-
Notifications
You must be signed in to change notification settings - Fork 2
use k6 cloud credentials #98
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// structure of the config file with the fields that are used by k6exec | ||
type k6configFile struct { | ||
Collectors struct { | ||
Cloud struct { | ||
Token string `json:"token"` | ||
} `json:"cloud"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More FYI and not sure that we actually need workaround that, but until the k6 v0.50 the structure was different and had more layers, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll open an issue and we can discuss if this is required. |
||
} `json:"collectors"` | ||
} | ||
|
||
// loadConfig loads the k6 config file from the given path or the default location. | ||
// if using the default location and the file does not exist, it returns an empty config. | ||
func loadConfig(configPath string) (k6configFile, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will be it difficult to add the debug logs here for success path, which we can enable by increasing verbosity ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That will require some changes in the code as we are not logging anything at the moment. I will open an issue an address this in a follow-up PR. |
||
var ( | ||
config k6configFile | ||
usingDefault bool | ||
homeDir string | ||
err error | ||
) | ||
|
||
if configPath == "" { | ||
usingDefault = true | ||
homeDir, err = os.UserConfigDir() //nolint:forbidigo | ||
if err != nil { | ||
return config, fmt.Errorf("failed to get user home directory: %w", err) | ||
} | ||
configPath = filepath.Join(homeDir, "loadimpact", "k6", "config.json") | ||
pablochacin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
buffer, err := os.ReadFile(configPath) //nolint:forbidigo,gosec | ||
if err != nil { | ||
if errors.Is(err, os.ErrNotExist) && usingDefault { //nolint:forbidigo | ||
return config, nil | ||
} | ||
return config, fmt.Errorf("failed to read config file %q: %w", configPath, err) | ||
} | ||
|
||
err = json.Unmarshal(buffer, &config) | ||
if err != nil { | ||
return config, fmt.Errorf("failed to parse config file %q: %w", configPath, err) | ||
} | ||
|
||
return config, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"collectors": { | ||
"cloud": { | ||
"token": "token" | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.