Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions cmd/kosli/createFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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)
}
Comment thread
ToreMerkely marked this conversation as resolved.

return cmd
}

Expand All @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions cmd/kosli/createFlow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions cmd/kosli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
Loading