Skip to content

Commit

Permalink
Warnings about options.cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbespalov committed Jan 17, 2024
1 parent 50418f8 commit d770afa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 6 additions & 1 deletion cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error {
}

// Cloud config
cloudConfig, _, err := cloudapi.GetConsolidatedConfig(
cloudConfig, warn, err := cloudapi.GetConsolidatedConfig(
test.derivedConfig.Collectors["cloud"], c.gs.Env, "", arc.Options.Cloud, arc.Options.External)
if err != nil {
return err
Expand All @@ -120,6 +120,11 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error {
return errors.New("Not logged in, please use `k6 login cloud`.") //nolint:golint,revive,stylecheck
}

// Display config warning if needed
if warn != "" {
modifyAndPrintBar(c.gs, progressBar, pb.WithConstProgress(0, "Warning: "+warn))
}

if cloudConfig.Token.Valid {
tmpCloudConfig["token"] = cloudConfig.Token
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/login_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ This will set the default token used when just "k6 run -o cloud" is passed.`,

// We want to use this fully consolidated config for things like
// host addresses, so users can overwrite them with env vars.
consolidatedCurrentConfig, _, err := cloudapi.GetConsolidatedConfig(
consolidatedCurrentConfig, warn, err := cloudapi.GetConsolidatedConfig(
currentJSONConfigRaw, gs.Env, "", nil, nil)
if err != nil {
return err
}

if warn != "" {
gs.Logger.Warn(warn)
}

// But we don't want to save them back to the JSON file, we only
// want to save what already existed there and the login details.
newCloudConf := currentJSONConfig
Expand Down
8 changes: 6 additions & 2 deletions output/cloud/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func New(params output.Params) (output.Output, error) {

// New creates a new cloud output.
func newOutput(params output.Params) (*Output, error) {
conf, _, err := cloudapi.GetConsolidatedConfig(
conf, warn, err := cloudapi.GetConsolidatedConfig(
params.JSONConfig,
params.Environment,
params.ConfigArgument,
Expand All @@ -89,6 +89,10 @@ func newOutput(params output.Params) (*Output, error) {
return nil, err
}

if warn != "" {
params.Logger.Warn(warn)
}

if err := validateRequiredSystemTags(params.ScriptOptions.SystemTags); err != nil {
return nil, err
}
Expand All @@ -99,7 +103,7 @@ func newOutput(params output.Params) (*Output, error) {
scriptPath := params.ScriptPath.String()
if scriptPath == "" {
// Script from stdin without a name, likely from stdin
return nil, errors.New("script name not set, please specify K6_CLOUD_NAME or options.ext.loadimpact.name")
return nil, errors.New("script name not set, please specify K6_CLOUD_NAME or options.cloud.name")
}

conf.Name = null.StringFrom(filepath.Base(scriptPath))
Expand Down

0 comments on commit d770afa

Please sign in to comment.