diff --git a/cmd/kosli/createFlow.go b/cmd/kosli/createFlow.go index 174647b0d..6581a8c4a 100644 --- a/cmd/kosli/createFlow.go +++ b/cmd/kosli/createFlow.go @@ -47,11 +47,10 @@ type createFlowOptions struct { type FlowPayload struct { Name string `json:"name"` Description string `json:"description"` - // TODO: Visibility is deprecated and ignored by recent Kosli servers, but older - // instances still reject the payload without it. Keep sending - // "private" until the minimum supported server version no longer requires - // this field, then remove the field and the assignment in run(). - Visibility string `json:"visibility"` + // Visibility is deprecated. It is only sent when the user explicitly passes + // the deprecated --visibility flag, so that older instances that still + // require the field keep working. + Visibility string `json:"visibility,omitempty"` Template []string `json:"template,omitempty"` } @@ -87,11 +86,17 @@ func newCreateFlowCmd(out io.Writer) *cobra.Command { } cmd.Flags().StringVar(&o.payload.Description, "description", "", flowDescriptionFlag) + cmd.Flags().StringVar(&o.payload.Visibility, "visibility", "", visibilityFlag) cmd.Flags().StringSliceVarP(&o.payload.Template, "template", "t", []string{}, templateFlag) cmd.Flags().StringVarP(&o.TemplateFile, "template-file", "f", "", templateFileFlag) cmd.Flags().BoolVar(&o.UseEmptyTemplate, "use-empty-template", false, useEmptyTemplateFlag) addDryRunFlag(cmd) + err := cmd.Flags().MarkDeprecated("visibility", "this flag is deprecated and will be removed in a future version.") + if err != nil { + logger.Error("failed to mark visibility as deprecated: %v", err) + } + return cmd } @@ -100,7 +105,6 @@ func (o *createFlowOptions) run(args []string) error { var url string var err error o.payload.Name = args[0] - o.payload.Visibility = "private" if o.TemplateFile != "" || o.UseEmptyTemplate { url, err = neturl.JoinPath(global.Host, "api/v2/flows", global.Org, "template_file") diff --git a/cmd/kosli/createFlow_test.go b/cmd/kosli/createFlow_test.go index 73c964e2b..cab0ef81c 100644 --- a/cmd/kosli/createFlow_test.go +++ b/cmd/kosli/createFlow_test.go @@ -26,6 +26,7 @@ func (suite *CreateFlowCommandTestSuite) SetupTest() { func (suite *CreateFlowCommandTestSuite) TestCreateFlowCmd() { deprecationWarning := "[warning] creating a flow without --template-file or --use-empty-template uses a deprecated API endpoint and will stop working in a future release; please provide a template\n" + visibilityDeprecationNotice := "Flag --visibility has been deprecated, this flag is deprecated and will be removed in a future version.\n" tests := []cmdTestCase{ { wantError: true, @@ -73,6 +74,11 @@ func (suite *CreateFlowCommandTestSuite) TestCreateFlowCmd() { cmd: "create flow newFlow --description \"my new flow\" --template foo --template-file testdata/valid_template.yml" + suite.defaultKosliArguments, golden: "Error: only one of --template, --template-file is allowed\n", }, + { + name: "deprecated --visibility flag is accepted (no longer illegal) and warns", + cmd: "create flow newFlowWithVisibility --visibility public --use-empty-template --description \"my new flow\" " + suite.defaultKosliArguments, + golden: visibilityDeprecationNotice + "flow 'newFlowWithVisibility' was created\n", + }, // flows v2 { name: "can create a flow with a valid template", diff --git a/cmd/kosli/root.go b/cmd/kosli/root.go index 1ff9cef0d..7c3dd2602 100644 --- a/cmd/kosli/root.go +++ b/cmd/kosli/root.go @@ -129,6 +129,7 @@ The ^.kosli_ignore^ will be treated as part of the artifact like any other file, envDescriptionFlag = "[optional] The environment description." flowDescriptionFlag = "[optional] The Kosli flow description." trailDescriptionFlag = "[optional] The Kosli trail description." + visibilityFlag = "[deprecated] The visibility of the Kosli flow. This flag is deprecated and will be removed in a future version." templateFlag = "[defaulted] The comma-separated list of required compliance controls names." templateFileFlag = "[optional] The path to a yaml template file. Cannot be used together with --use-empty-template" templateFileSimpleFlag = "[optional] The path to a yaml template file."