Skip to content

Commit 0bf74d0

Browse files
ToreMerkelyclaude
andauthored
fix: deprecate --visibility flag instead of removing it (#923)
Removing --visibility in #918 made passing the flag illegal (unknown flag), breaking existing scripts. Restore it as a deprecated flag so it is accepted with a deprecation notice rather than erroring. Drop the hardcoded visibility "private" added in #922 as a backwards- compat shim for servers that still required the field; prod no longer requires it. The field is now sent only when the user explicitly passes the deprecated flag (json omitempty), preserving compatibility with older instances that still mandate it. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 168dbc9 commit 0bf74d0

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

cmd/kosli/createFlow.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ type createFlowOptions struct {
4747
type FlowPayload struct {
4848
Name string `json:"name"`
4949
Description string `json:"description"`
50-
// TODO: Visibility is deprecated and ignored by recent Kosli servers, but older
51-
// instances still reject the payload without it. Keep sending
52-
// "private" until the minimum supported server version no longer requires
53-
// this field, then remove the field and the assignment in run().
54-
Visibility string `json:"visibility"`
50+
// Visibility is deprecated. It is only sent when the user explicitly passes
51+
// the deprecated --visibility flag, so that older instances that still
52+
// require the field keep working.
53+
Visibility string `json:"visibility,omitempty"`
5554
Template []string `json:"template,omitempty"`
5655
}
5756

@@ -87,11 +86,17 @@ func newCreateFlowCmd(out io.Writer) *cobra.Command {
8786
}
8887

8988
cmd.Flags().StringVar(&o.payload.Description, "description", "", flowDescriptionFlag)
89+
cmd.Flags().StringVar(&o.payload.Visibility, "visibility", "", visibilityFlag)
9090
cmd.Flags().StringSliceVarP(&o.payload.Template, "template", "t", []string{}, templateFlag)
9191
cmd.Flags().StringVarP(&o.TemplateFile, "template-file", "f", "", templateFileFlag)
9292
cmd.Flags().BoolVar(&o.UseEmptyTemplate, "use-empty-template", false, useEmptyTemplateFlag)
9393
addDryRunFlag(cmd)
9494

95+
err := cmd.Flags().MarkDeprecated("visibility", "this flag is deprecated and will be removed in a future version.")
96+
if err != nil {
97+
logger.Error("failed to mark visibility as deprecated: %v", err)
98+
}
99+
95100
return cmd
96101
}
97102

@@ -100,7 +105,6 @@ func (o *createFlowOptions) run(args []string) error {
100105
var url string
101106
var err error
102107
o.payload.Name = args[0]
103-
o.payload.Visibility = "private"
104108

105109
if o.TemplateFile != "" || o.UseEmptyTemplate {
106110
url, err = neturl.JoinPath(global.Host, "api/v2/flows", global.Org, "template_file")

cmd/kosli/createFlow_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func (suite *CreateFlowCommandTestSuite) SetupTest() {
2626

2727
func (suite *CreateFlowCommandTestSuite) TestCreateFlowCmd() {
2828
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"
29+
visibilityDeprecationNotice := "Flag --visibility has been deprecated, this flag is deprecated and will be removed in a future version.\n"
2930
tests := []cmdTestCase{
3031
{
3132
wantError: true,
@@ -73,6 +74,11 @@ func (suite *CreateFlowCommandTestSuite) TestCreateFlowCmd() {
7374
cmd: "create flow newFlow --description \"my new flow\" --template foo --template-file testdata/valid_template.yml" + suite.defaultKosliArguments,
7475
golden: "Error: only one of --template, --template-file is allowed\n",
7576
},
77+
{
78+
name: "deprecated --visibility flag is accepted (no longer illegal) and warns",
79+
cmd: "create flow newFlowWithVisibility --visibility public --use-empty-template --description \"my new flow\" " + suite.defaultKosliArguments,
80+
golden: visibilityDeprecationNotice + "flow 'newFlowWithVisibility' was created\n",
81+
},
7682
// flows v2
7783
{
7884
name: "can create a flow with a valid template",

cmd/kosli/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ The ^.kosli_ignore^ will be treated as part of the artifact like any other file,
129129
envDescriptionFlag = "[optional] The environment description."
130130
flowDescriptionFlag = "[optional] The Kosli flow description."
131131
trailDescriptionFlag = "[optional] The Kosli trail description."
132+
visibilityFlag = "[deprecated] The visibility of the Kosli flow. This flag is deprecated and will be removed in a future version."
132133
templateFlag = "[defaulted] The comma-separated list of required compliance controls names."
133134
templateFileFlag = "[optional] The path to a yaml template file. Cannot be used together with --use-empty-template"
134135
templateFileSimpleFlag = "[optional] The path to a yaml template file."

0 commit comments

Comments
 (0)