diff --git a/.tmpl/create.go b/.tmpl/create.go index 163a553dd..485ee7fcf 100644 --- a/.tmpl/create.go +++ b/.tmpl/create.go @@ -62,6 +62,8 @@ type CreateCommand struct { // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(in io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, Client: c.Globals.Client, Manifest: c.manifest, diff --git a/.tmpl/delete.go b/.tmpl/delete.go index 6e13c7d79..e9d08e85a 100644 --- a/.tmpl/delete.go +++ b/.tmpl/delete.go @@ -62,6 +62,8 @@ type DeleteCommand struct { // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(in io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, Client: c.Globals.Client, Manifest: c.manifest, diff --git a/.tmpl/describe.go b/.tmpl/describe.go index 54cdcefa9..b01d0493b 100644 --- a/.tmpl/describe.go +++ b/.tmpl/describe.go @@ -57,7 +57,6 @@ type DescribeCommand struct { // Exec invokes the application logic for the command. func (c *DescribeCommand) Exec(in io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, Client: c.Globals.Client, Manifest: c.manifest, Out: out, diff --git a/.tmpl/list.go b/.tmpl/list.go index 2505e48e9..7a2c518ad 100644 --- a/.tmpl/list.go +++ b/.tmpl/list.go @@ -58,7 +58,6 @@ type ListCommand struct { // Exec invokes the application logic for the command. func (c *ListCommand) Exec(in io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, Client: c.Globals.Client, Manifest: c.manifest, Out: out, diff --git a/.tmpl/test.go b/.tmpl/test.go index 59f986d86..b1c57f06f 100644 --- a/.tmpl/test.go +++ b/.tmpl/test.go @@ -25,12 +25,20 @@ func TestCreate(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: "--service-id 123 --version 1", - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: "--service-id 123 --version 2", + WantError: "service version 2 is locked", }, { Name: "validate Create${CLI_API} API error", @@ -88,12 +96,20 @@ func TestDelete(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: "--service-id 123 --version 1", - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: "--service-id 123 --version 2", + WantError: "service version 2 is locked", }, { Name: "validate Delete${CLI_API} API error", @@ -233,12 +249,20 @@ func TestUpdate(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, - Args: "--service-id 123 --version 1", - WantError: "service version 1 is not editable", + Args: "--name foobar --service-id 123 --version 1", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: "--name foobar --service-id 123 --version 2", + WantError: "service version 2 is locked", }, { Name: "validate Update${CLI_API} API error", diff --git a/.tmpl/update.go b/.tmpl/update.go index bd601ebff..294f7a530 100644 --- a/.tmpl/update.go +++ b/.tmpl/update.go @@ -66,6 +66,8 @@ type UpdateCommand struct { // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(in io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, Client: c.Globals.Client, Manifest: c.manifest, diff --git a/pkg/argparser/cmd.go b/pkg/argparser/cmd.go index cf7c873d7..31245e583 100644 --- a/pkg/argparser/cmd.go +++ b/pkg/argparser/cmd.go @@ -13,6 +13,7 @@ import ( "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // Command is an interface that abstracts over all of the concrete command @@ -108,7 +109,12 @@ type OptionalFloat64 struct { // ServiceDetailsOpts provides data and behaviours required by the // ServiceDetails function. type ServiceDetailsOpts struct { - AllowActiveLocked bool + // if this is not set, then the 'active' state of the service is ignored; + // otherwise, the 'active' state must match the value of this field + Active optional.Optional[bool] + // if this is not set, then the 'locked' state of the service is ignored; + // otherwise, the 'locked' state must match the value of this field + Locked optional.Optional[bool] AutoCloneFlag OptionalAutoClone APIClient api.Interface Manifest manifest.Data @@ -140,14 +146,41 @@ func ServiceDetails(opts ServiceDetailsOpts) (serviceID string, serviceVersion * if err != nil { return serviceID, currentVersion, err } - } else if !opts.AllowActiveLocked && (fastly.ToValue(v.Active) || fastly.ToValue(v.Locked)) { + return serviceID, v, nil + } + + failure := false + var failureState string + + if active, present := opts.Active.Get(); present { + if active && !fastly.ToValue(v.Active) { + failure = true + failureState = "not active" + } + if !active && fastly.ToValue(v.Active) { + failure = true + failureState = "active" + } + } + + if locked, present := opts.Locked.Get(); present { + if locked && !fastly.ToValue(v.Locked) { + failure = true + failureState = "not locked" + } + if !locked && fastly.ToValue(v.Locked) { + failure = true + failureState = "locked" + } + } + + if failure { err = fsterr.RemediationError{ - Inner: fmt.Errorf("service version %d is not editable", fastly.ToValue(v.Number)), + Inner: fmt.Errorf("service version %d is %s", fastly.ToValue(v.Number), failureState), Remediation: fsterr.AutoCloneRemediation, } return serviceID, v, err } - return serviceID, v, nil } diff --git a/pkg/commands/acl/acl_test.go b/pkg/commands/acl/acl_test.go index bdc99e98d..192b9f610 100644 --- a/pkg/commands/acl/acl_test.go +++ b/pkg/commands/acl/acl_test.go @@ -31,12 +31,20 @@ func TestACLCreate(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Arg: "--name foo --service-id 123 --version 1", - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Arg: "--name foo --service-id 123 --version 2", + WantError: "service version 2 is locked", }, { Name: "validate CreateACL API error", @@ -105,12 +113,20 @@ func TestACLDelete(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Arg: "--name foobar --service-id 123 --version 1", - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Arg: "--name foo --service-id 123 --version 2", + WantError: "service version 2 is locked", }, { Name: "validate DeleteACL API error", @@ -279,12 +295,20 @@ func TestACLUpdate(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Arg: "--name foo --new-name beepboop --service-id 123 --version 1", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, - Arg: "--name foobar --new-name beepboop --service-id 123 --version 1", - WantError: "service version 1 is not editable", + Arg: "--name foo --new-name beepboop --service-id 123 --version 2", + WantError: "service version 2 is locked", }, { Name: "validate UpdateACL API error", diff --git a/pkg/commands/acl/create.go b/pkg/commands/acl/create.go index 747b2c850..45e420fd9 100644 --- a/pkg/commands/acl/create.go +++ b/pkg/commands/acl/create.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // NewCreateCommand returns a usable command registered under the parent. @@ -64,6 +65,8 @@ type CreateCommand struct { // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, ErrLog: c.Globals.ErrLog, diff --git a/pkg/commands/acl/delete.go b/pkg/commands/acl/delete.go index 368fbc6d9..a2e4726c9 100644 --- a/pkg/commands/acl/delete.go +++ b/pkg/commands/acl/delete.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // NewDeleteCommand returns a usable command registered under the parent. @@ -63,6 +64,8 @@ type DeleteCommand struct { // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/acl/describe.go b/pkg/commands/acl/describe.go index 3171774a7..d5ef60093 100644 --- a/pkg/commands/acl/describe.go +++ b/pkg/commands/acl/describe.go @@ -64,7 +64,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/acl/list.go b/pkg/commands/acl/list.go index 800e53ece..8d0c69421 100644 --- a/pkg/commands/acl/list.go +++ b/pkg/commands/acl/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/acl/update.go b/pkg/commands/acl/update.go index 464201085..e4c45ed0d 100644 --- a/pkg/commands/acl/update.go +++ b/pkg/commands/acl/update.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // NewUpdateCommand returns a usable command registered under the parent. @@ -65,6 +66,8 @@ type UpdateCommand struct { // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/backend/backend_test.go b/pkg/commands/backend/backend_test.go index f2977ce65..ddca895a3 100644 --- a/pkg/commands/backend/backend_test.go +++ b/pkg/commands/backend/backend_test.go @@ -33,9 +33,31 @@ func TestBackendCreate(t *testing.T) { API: mock.API{ ListVersionsFn: testutil.ListVersions, }, - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", }, - // The following test is the same as the above but it appends --autoclone + // The following test specifies a service version that's 'locked', and + // subsequently we expect it to not be cloned as we don't provide the + // --autoclone flag and trying to add a backend to an activated service + // should cause an error. + { + Args: args("backend create --service-id 123 --version 2 --address example.com --name www.test.com"), + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + WantError: "service version 2 is locked", + }, + // The following test is the same as the 'active' test above but it appends --autoclone + // so we can be sure the backend creation error still occurs. + { + Args: args("backend create --service-id 123 --version 1 --address example.com --name www.test.com --autoclone"), + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + CloneVersionFn: testutil.CloneVersionResult(4), + CreateBackendFn: createBackendError, + }, + WantError: errTest.Error(), + }, + // The following test is the same as the 'locked' test above but it appends --autoclone // so we can be sure the backend creation error still occurs. { Args: args("backend create --service-id 123 --version 1 --address example.com --name www.test.com --autoclone"), @@ -125,8 +147,8 @@ func TestBackendCreate(t *testing.T) { }, WantOutput: "Created backend www.test.com (service 123 version 4)", }, - // The following test specifies a service version that's 'inactive', and - // subsequently we expect it to be the same editable version. + // The following test specifies a service version that's 'inactive' and not 'locked', + // and subsequently we expect it to be the same editable version. { Args: args("backend create --service-id 123 --version 3 --address 127.0.0.1 --name www.test.com"), API: mock.API{ diff --git a/pkg/commands/backend/create.go b/pkg/commands/backend/create.go index b8f9d7e73..f80041cbf 100644 --- a/pkg/commands/backend/create.go +++ b/pkg/commands/backend/create.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // CreateCommand calls the Fastly API to create backends. @@ -116,6 +117,8 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/backend/delete.go b/pkg/commands/backend/delete.go index c64f1e0ae..b381e5013 100644 --- a/pkg/commands/backend/delete.go +++ b/pkg/commands/backend/delete.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // DeleteCommand calls the Fastly API to delete backends. @@ -62,6 +63,8 @@ func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteComman // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/backend/describe.go b/pkg/commands/backend/describe.go index df948bcb7..973ec2203 100644 --- a/pkg/commands/backend/describe.go +++ b/pkg/commands/backend/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/backend/list.go b/pkg/commands/backend/list.go index 72c7af676..ba61986af 100644 --- a/pkg/commands/backend/list.go +++ b/pkg/commands/backend/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/backend/update.go b/pkg/commands/backend/update.go index 58a67123a..d6ce656a1 100644 --- a/pkg/commands/backend/update.go +++ b/pkg/commands/backend/update.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // UpdateCommand calls the Fastly API to update backends. @@ -113,6 +114,8 @@ func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateComman // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/compute/deploy_test.go b/pkg/commands/compute/deploy_test.go index e1bb21fa2..1b07b9674 100644 --- a/pkg/commands/compute/deploy_test.go +++ b/pkg/commands/compute/deploy_test.go @@ -198,6 +198,17 @@ func TestDeploy(t *testing.T) { }, wantError: fmt.Sprintf("error cloning service version: %s", testutil.Err.Error()), }, + { + name: "service version is locked, clone version error", + args: args("compute deploy --service-id 123 --token 123 --version 2"), + api: mock.API{ + CloneVersionFn: testutil.CloneVersionError, + GetPackageFn: getPackageOk, + GetServiceDetailsFn: getServiceDetailsWasm, + ListVersionsFn: testutil.ListVersions, + }, + wantError: fmt.Sprintf("error cloning service version: %s", testutil.Err.Error()), + }, { name: "list domains error", args: args("compute deploy --service-id 123 --token 123"), diff --git a/pkg/commands/dictionary/create.go b/pkg/commands/dictionary/create.go index 5080095be..0a415f0ce 100644 --- a/pkg/commands/dictionary/create.go +++ b/pkg/commands/dictionary/create.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // CreateCommand calls the Fastly API to create a service. @@ -67,6 +68,8 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/dictionary/delete.go b/pkg/commands/dictionary/delete.go index e75369ea1..0edc60a96 100644 --- a/pkg/commands/dictionary/delete.go +++ b/pkg/commands/dictionary/delete.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // DeleteCommand calls the Fastly API to delete a service. @@ -61,6 +62,8 @@ func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteComman // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/dictionary/describe.go b/pkg/commands/dictionary/describe.go index 9ecfc7cdf..03ba86f67 100644 --- a/pkg/commands/dictionary/describe.go +++ b/pkg/commands/dictionary/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/dictionary/list.go b/pkg/commands/dictionary/list.go index a9f0b6ccc..70042d7a3 100644 --- a/pkg/commands/dictionary/list.go +++ b/pkg/commands/dictionary/list.go @@ -62,7 +62,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { return fsterr.ErrInvalidVerboseJSONCombo } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/dictionary/update.go b/pkg/commands/dictionary/update.go index 1b13d8db4..62238e755 100644 --- a/pkg/commands/dictionary/update.go +++ b/pkg/commands/dictionary/update.go @@ -11,6 +11,7 @@ import ( fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // UpdateCommand calls the Fastly API to update a dictionary. @@ -70,6 +71,8 @@ func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateComman // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/domain/create.go b/pkg/commands/domain/create.go index ceb6994d5..79c1c8b80 100644 --- a/pkg/commands/domain/create.go +++ b/pkg/commands/domain/create.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // CreateCommand calls the Fastly API to create domains. @@ -67,6 +68,8 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/domain/delete.go b/pkg/commands/domain/delete.go index 739fc8e28..edf939459 100644 --- a/pkg/commands/domain/delete.go +++ b/pkg/commands/domain/delete.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // DeleteCommand calls the Fastly API to delete domains. @@ -61,6 +62,8 @@ func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteComman // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/domain/describe.go b/pkg/commands/domain/describe.go index 4ecf3cb2c..b99b1e221 100644 --- a/pkg/commands/domain/describe.go +++ b/pkg/commands/domain/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/domain/list.go b/pkg/commands/domain/list.go index ae360a120..69c81fa1b 100644 --- a/pkg/commands/domain/list.go +++ b/pkg/commands/domain/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/domain/update.go b/pkg/commands/domain/update.go index 6127581b4..e2a26c3b1 100644 --- a/pkg/commands/domain/update.go +++ b/pkg/commands/domain/update.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // UpdateCommand calls the Fastly API to update domains. @@ -67,6 +68,8 @@ func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateComman // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/domain/validate.go b/pkg/commands/domain/validate.go index 0e9a6c3bd..44f4b3fcd 100644 --- a/pkg/commands/domain/validate.go +++ b/pkg/commands/domain/validate.go @@ -57,7 +57,6 @@ type ValidateCommand struct { // Exec invokes the application logic for the command. func (c *ValidateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/healthcheck/create.go b/pkg/commands/healthcheck/create.go index bcdb9b527..f9da8ba3b 100644 --- a/pkg/commands/healthcheck/create.go +++ b/pkg/commands/healthcheck/create.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // CreateCommand calls the Fastly API to create healthchecks. @@ -87,6 +88,8 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/healthcheck/delete.go b/pkg/commands/healthcheck/delete.go index a1af30d8b..281a0b729 100644 --- a/pkg/commands/healthcheck/delete.go +++ b/pkg/commands/healthcheck/delete.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // DeleteCommand calls the Fastly API to delete healthchecks. @@ -61,6 +62,8 @@ func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteComman // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/healthcheck/describe.go b/pkg/commands/healthcheck/describe.go index 5b93eca56..5f357a39f 100644 --- a/pkg/commands/healthcheck/describe.go +++ b/pkg/commands/healthcheck/describe.go @@ -64,7 +64,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/healthcheck/list.go b/pkg/commands/healthcheck/list.go index a33bb3875..95dd7c600 100644 --- a/pkg/commands/healthcheck/list.go +++ b/pkg/commands/healthcheck/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/healthcheck/update.go b/pkg/commands/healthcheck/update.go index d1ad48027..363d51cdd 100644 --- a/pkg/commands/healthcheck/update.go +++ b/pkg/commands/healthcheck/update.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // UpdateCommand calls the Fastly API to update healthchecks. @@ -86,6 +87,8 @@ func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateComman // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/logging/azureblob/describe.go b/pkg/commands/logging/azureblob/describe.go index 3247e3038..0b7c69353 100644 --- a/pkg/commands/logging/azureblob/describe.go +++ b/pkg/commands/logging/azureblob/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/azureblob/list.go b/pkg/commands/logging/azureblob/list.go index cebe670dc..53d8a95ec 100644 --- a/pkg/commands/logging/azureblob/list.go +++ b/pkg/commands/logging/azureblob/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/bigquery/describe.go b/pkg/commands/logging/bigquery/describe.go index da8343f4b..cc5da8e62 100644 --- a/pkg/commands/logging/bigquery/describe.go +++ b/pkg/commands/logging/bigquery/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/bigquery/list.go b/pkg/commands/logging/bigquery/list.go index bb49da19a..e08f30b39 100644 --- a/pkg/commands/logging/bigquery/list.go +++ b/pkg/commands/logging/bigquery/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/cloudfiles/describe.go b/pkg/commands/logging/cloudfiles/describe.go index 8a515e6be..9ad73b53f 100644 --- a/pkg/commands/logging/cloudfiles/describe.go +++ b/pkg/commands/logging/cloudfiles/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/cloudfiles/list.go b/pkg/commands/logging/cloudfiles/list.go index 8ea716bbc..20b3c5343 100644 --- a/pkg/commands/logging/cloudfiles/list.go +++ b/pkg/commands/logging/cloudfiles/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/datadog/describe.go b/pkg/commands/logging/datadog/describe.go index 1ba797910..515506f3e 100644 --- a/pkg/commands/logging/datadog/describe.go +++ b/pkg/commands/logging/datadog/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/datadog/list.go b/pkg/commands/logging/datadog/list.go index 1473d2bd0..91538dac8 100644 --- a/pkg/commands/logging/datadog/list.go +++ b/pkg/commands/logging/datadog/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/digitalocean/describe.go b/pkg/commands/logging/digitalocean/describe.go index 71d0353c4..cc6cd11b0 100644 --- a/pkg/commands/logging/digitalocean/describe.go +++ b/pkg/commands/logging/digitalocean/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/digitalocean/list.go b/pkg/commands/logging/digitalocean/list.go index a1e740788..62ff3aacb 100644 --- a/pkg/commands/logging/digitalocean/list.go +++ b/pkg/commands/logging/digitalocean/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/elasticsearch/describe.go b/pkg/commands/logging/elasticsearch/describe.go index c7c8b7ba4..e1907195b 100644 --- a/pkg/commands/logging/elasticsearch/describe.go +++ b/pkg/commands/logging/elasticsearch/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/elasticsearch/list.go b/pkg/commands/logging/elasticsearch/list.go index 6dd53b084..ecdb7e762 100644 --- a/pkg/commands/logging/elasticsearch/list.go +++ b/pkg/commands/logging/elasticsearch/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/ftp/describe.go b/pkg/commands/logging/ftp/describe.go index ecc4292a5..ee7eb805e 100644 --- a/pkg/commands/logging/ftp/describe.go +++ b/pkg/commands/logging/ftp/describe.go @@ -59,7 +59,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/ftp/list.go b/pkg/commands/logging/ftp/list.go index a6b8f0e1c..68827fa75 100644 --- a/pkg/commands/logging/ftp/list.go +++ b/pkg/commands/logging/ftp/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/gcs/describe.go b/pkg/commands/logging/gcs/describe.go index 0ecae611e..c5629d981 100644 --- a/pkg/commands/logging/gcs/describe.go +++ b/pkg/commands/logging/gcs/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/gcs/list.go b/pkg/commands/logging/gcs/list.go index f6841a1e0..20ec6b805 100644 --- a/pkg/commands/logging/gcs/list.go +++ b/pkg/commands/logging/gcs/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/googlepubsub/describe.go b/pkg/commands/logging/googlepubsub/describe.go index 479b25b64..252c0b8cf 100644 --- a/pkg/commands/logging/googlepubsub/describe.go +++ b/pkg/commands/logging/googlepubsub/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/googlepubsub/list.go b/pkg/commands/logging/googlepubsub/list.go index cc65e9c36..c533e81e7 100644 --- a/pkg/commands/logging/googlepubsub/list.go +++ b/pkg/commands/logging/googlepubsub/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/heroku/describe.go b/pkg/commands/logging/heroku/describe.go index 1de4697a3..15f494046 100644 --- a/pkg/commands/logging/heroku/describe.go +++ b/pkg/commands/logging/heroku/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/heroku/list.go b/pkg/commands/logging/heroku/list.go index cac714dec..9de12f3da 100644 --- a/pkg/commands/logging/heroku/list.go +++ b/pkg/commands/logging/heroku/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/honeycomb/describe.go b/pkg/commands/logging/honeycomb/describe.go index 6b75dc351..6e8f06556 100644 --- a/pkg/commands/logging/honeycomb/describe.go +++ b/pkg/commands/logging/honeycomb/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/honeycomb/list.go b/pkg/commands/logging/honeycomb/list.go index a51283a36..102b3ff1b 100644 --- a/pkg/commands/logging/honeycomb/list.go +++ b/pkg/commands/logging/honeycomb/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/https/describe.go b/pkg/commands/logging/https/describe.go index c996a8c10..1bceb2235 100644 --- a/pkg/commands/logging/https/describe.go +++ b/pkg/commands/logging/https/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/https/list.go b/pkg/commands/logging/https/list.go index 9a9591d4a..e20aab7bd 100644 --- a/pkg/commands/logging/https/list.go +++ b/pkg/commands/logging/https/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/kafka/describe.go b/pkg/commands/logging/kafka/describe.go index a5eb34347..ff948a573 100644 --- a/pkg/commands/logging/kafka/describe.go +++ b/pkg/commands/logging/kafka/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/kafka/list.go b/pkg/commands/logging/kafka/list.go index 22fc4e645..0b5dc8db4 100644 --- a/pkg/commands/logging/kafka/list.go +++ b/pkg/commands/logging/kafka/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/kinesis/describe.go b/pkg/commands/logging/kinesis/describe.go index 6237aefc4..89986c583 100644 --- a/pkg/commands/logging/kinesis/describe.go +++ b/pkg/commands/logging/kinesis/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/kinesis/list.go b/pkg/commands/logging/kinesis/list.go index 2babf1a66..d17006e7a 100644 --- a/pkg/commands/logging/kinesis/list.go +++ b/pkg/commands/logging/kinesis/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/loggly/describe.go b/pkg/commands/logging/loggly/describe.go index 5ff0ecf0e..a999c38a3 100644 --- a/pkg/commands/logging/loggly/describe.go +++ b/pkg/commands/logging/loggly/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/loggly/list.go b/pkg/commands/logging/loggly/list.go index 1f1246061..cf43267c2 100644 --- a/pkg/commands/logging/loggly/list.go +++ b/pkg/commands/logging/loggly/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/logshuttle/describe.go b/pkg/commands/logging/logshuttle/describe.go index 6ff34bb7d..22a1e35d3 100644 --- a/pkg/commands/logging/logshuttle/describe.go +++ b/pkg/commands/logging/logshuttle/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/logshuttle/list.go b/pkg/commands/logging/logshuttle/list.go index 268894b34..59f629900 100644 --- a/pkg/commands/logging/logshuttle/list.go +++ b/pkg/commands/logging/logshuttle/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/newrelic/create.go b/pkg/commands/logging/newrelic/create.go index 7a11ae590..cdafe219b 100644 --- a/pkg/commands/logging/newrelic/create.go +++ b/pkg/commands/logging/newrelic/create.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // CreateCommand calls the Fastly API to create an appropriate resource. @@ -79,6 +80,8 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/logging/newrelic/delete.go b/pkg/commands/logging/newrelic/delete.go index 34c456f1d..b76f5e00e 100644 --- a/pkg/commands/logging/newrelic/delete.go +++ b/pkg/commands/logging/newrelic/delete.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // NewDeleteCommand returns a usable command registered under the parent. @@ -63,6 +64,8 @@ type DeleteCommand struct { // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/logging/newrelic/describe.go b/pkg/commands/logging/newrelic/describe.go index df0d919e9..ffca83fec 100644 --- a/pkg/commands/logging/newrelic/describe.go +++ b/pkg/commands/logging/newrelic/describe.go @@ -64,7 +64,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/newrelic/list.go b/pkg/commands/logging/newrelic/list.go index ce6a18d6a..0c7d7330e 100644 --- a/pkg/commands/logging/newrelic/list.go +++ b/pkg/commands/logging/newrelic/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/newrelic/newrelic_test.go b/pkg/commands/logging/newrelic/newrelic_test.go index b30dd2178..df1050a2a 100644 --- a/pkg/commands/logging/newrelic/newrelic_test.go +++ b/pkg/commands/logging/newrelic/newrelic_test.go @@ -22,12 +22,20 @@ func TestNewRelicCreate(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: args("logging newrelic create --key abc --name foo --service-id 123 --version 1"), - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: args("logging newrelic create --key abc --name foo --service-id 123 --version 2"), + WantError: "service version 2 is locked", }, { Name: "validate CreateNewRelic API error", @@ -108,12 +116,20 @@ func TestNewRelicDelete(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: args("logging newrelic delete --name foobar --service-id 123 --version 1"), - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: args("logging newrelic delete --name foobar --service-id 123 --version 2"), + WantError: "service version 2 is locked", }, { Name: "validate DeleteNewRelic API error", @@ -320,12 +336,20 @@ func TestNewRelicUpdate(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: args("logging newrelic update --name foobar --service-id 123 --version 1"), - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: args("logging newrelic update --name foobar --service-id 123 --version 2"), + WantError: "service version 2 is locked", }, { Name: "validate UpdateNewRelic API error", diff --git a/pkg/commands/logging/newrelic/update.go b/pkg/commands/logging/newrelic/update.go index 5d53ca30a..106d85572 100644 --- a/pkg/commands/logging/newrelic/update.go +++ b/pkg/commands/logging/newrelic/update.go @@ -11,6 +11,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // UpdateCommand calls the Fastly API to update an appropriate resource. @@ -80,6 +81,8 @@ func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateComman // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/logging/newrelicotlp/create.go b/pkg/commands/logging/newrelicotlp/create.go index ab52e8c6e..d8318eaae 100644 --- a/pkg/commands/logging/newrelicotlp/create.go +++ b/pkg/commands/logging/newrelicotlp/create.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // CreateCommand calls the Fastly API to create an appropriate resource. @@ -81,6 +82,8 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/logging/newrelicotlp/delete.go b/pkg/commands/logging/newrelicotlp/delete.go index c748b874b..d7c738671 100644 --- a/pkg/commands/logging/newrelicotlp/delete.go +++ b/pkg/commands/logging/newrelicotlp/delete.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // NewDeleteCommand returns a usable command registered under the parent. @@ -63,6 +64,8 @@ type DeleteCommand struct { // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/logging/newrelicotlp/describe.go b/pkg/commands/logging/newrelicotlp/describe.go index 2022e2ddc..ee3e7853d 100644 --- a/pkg/commands/logging/newrelicotlp/describe.go +++ b/pkg/commands/logging/newrelicotlp/describe.go @@ -64,7 +64,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/newrelicotlp/list.go b/pkg/commands/logging/newrelicotlp/list.go index f024c3d63..0ef13719c 100644 --- a/pkg/commands/logging/newrelicotlp/list.go +++ b/pkg/commands/logging/newrelicotlp/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/newrelicotlp/newrelicotlp_test.go b/pkg/commands/logging/newrelicotlp/newrelicotlp_test.go index 83b9588b6..c520929f9 100644 --- a/pkg/commands/logging/newrelicotlp/newrelicotlp_test.go +++ b/pkg/commands/logging/newrelicotlp/newrelicotlp_test.go @@ -22,12 +22,20 @@ func TestNewRelicOTLPCreate(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: args("logging newrelicotlp create --key abc --name foo --service-id 123 --version 1"), - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: args("logging newrelicotlp create --key abc --name foo --service-id 123 --version 2"), + WantError: "service version 2 is locked", }, { Name: "validate CreateNewRelicOTLP API error", @@ -108,12 +116,20 @@ func TestNewRelicOTLPDelete(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: args("logging newrelicotlp delete --name foobar --service-id 123 --version 1"), - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: args("logging newrelicotlp delete --name foobar --service-id 123 --version 2"), + WantError: "service version 2 is locked", }, { Name: "validate DeleteNewRelic API error", @@ -320,12 +336,20 @@ func TestNewRelicUpdate(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: args("logging newrelicotlp update --name foobar --service-id 123 --version 1"), - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: args("logging newrelicotlp update --name foobar --service-id 123 --version 2"), + WantError: "service version 2 is locked", }, { Name: "validate UpdateNewRelic API error", diff --git a/pkg/commands/logging/newrelicotlp/update.go b/pkg/commands/logging/newrelicotlp/update.go index 509cc14d6..dc257c240 100644 --- a/pkg/commands/logging/newrelicotlp/update.go +++ b/pkg/commands/logging/newrelicotlp/update.go @@ -11,6 +11,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // UpdateCommand calls the Fastly API to update an appropriate resource. @@ -82,6 +83,8 @@ func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateComman // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/logging/openstack/describe.go b/pkg/commands/logging/openstack/describe.go index 0718bf194..3f4512414 100644 --- a/pkg/commands/logging/openstack/describe.go +++ b/pkg/commands/logging/openstack/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/openstack/list.go b/pkg/commands/logging/openstack/list.go index 3b9a9fff7..dc898cde4 100644 --- a/pkg/commands/logging/openstack/list.go +++ b/pkg/commands/logging/openstack/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/papertrail/describe.go b/pkg/commands/logging/papertrail/describe.go index 9a7c68650..4eeff8f5d 100644 --- a/pkg/commands/logging/papertrail/describe.go +++ b/pkg/commands/logging/papertrail/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/papertrail/list.go b/pkg/commands/logging/papertrail/list.go index 96c7bfd41..382cb0a70 100644 --- a/pkg/commands/logging/papertrail/list.go +++ b/pkg/commands/logging/papertrail/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/s3/describe.go b/pkg/commands/logging/s3/describe.go index ae39d09d0..d15f4b56a 100644 --- a/pkg/commands/logging/s3/describe.go +++ b/pkg/commands/logging/s3/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/s3/list.go b/pkg/commands/logging/s3/list.go index 379bb0701..353245038 100644 --- a/pkg/commands/logging/s3/list.go +++ b/pkg/commands/logging/s3/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/scalyr/describe.go b/pkg/commands/logging/scalyr/describe.go index 0b5ce43a4..c6178da29 100644 --- a/pkg/commands/logging/scalyr/describe.go +++ b/pkg/commands/logging/scalyr/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/scalyr/list.go b/pkg/commands/logging/scalyr/list.go index 8dabd2ab8..cb14fd7a3 100644 --- a/pkg/commands/logging/scalyr/list.go +++ b/pkg/commands/logging/scalyr/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/sftp/describe.go b/pkg/commands/logging/sftp/describe.go index 802c30891..afd56c278 100644 --- a/pkg/commands/logging/sftp/describe.go +++ b/pkg/commands/logging/sftp/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/sftp/list.go b/pkg/commands/logging/sftp/list.go index 716775b3b..625de2bcd 100644 --- a/pkg/commands/logging/sftp/list.go +++ b/pkg/commands/logging/sftp/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/splunk/describe.go b/pkg/commands/logging/splunk/describe.go index d94f3801c..e38400810 100644 --- a/pkg/commands/logging/splunk/describe.go +++ b/pkg/commands/logging/splunk/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/splunk/list.go b/pkg/commands/logging/splunk/list.go index 9d3d5896e..f95e75e09 100644 --- a/pkg/commands/logging/splunk/list.go +++ b/pkg/commands/logging/splunk/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/sumologic/describe.go b/pkg/commands/logging/sumologic/describe.go index cbd8ed290..fde4bd250 100644 --- a/pkg/commands/logging/sumologic/describe.go +++ b/pkg/commands/logging/sumologic/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/sumologic/list.go b/pkg/commands/logging/sumologic/list.go index 4daedaf49..2c0d42466 100644 --- a/pkg/commands/logging/sumologic/list.go +++ b/pkg/commands/logging/sumologic/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/syslog/describe.go b/pkg/commands/logging/syslog/describe.go index b13718dfd..41cdb7e98 100644 --- a/pkg/commands/logging/syslog/describe.go +++ b/pkg/commands/logging/syslog/describe.go @@ -63,7 +63,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/logging/syslog/list.go b/pkg/commands/logging/syslog/list.go index caab65a78..032ef989a 100644 --- a/pkg/commands/logging/syslog/list.go +++ b/pkg/commands/logging/syslog/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/ratelimit/create.go b/pkg/commands/ratelimit/create.go index 91963d1d5..f84000cd3 100644 --- a/pkg/commands/ratelimit/create.go +++ b/pkg/commands/ratelimit/create.go @@ -12,6 +12,7 @@ import ( fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // rateLimitActionFlagOpts is a string representation of rateLimitActions @@ -133,6 +134,8 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/ratelimit/list.go b/pkg/commands/ratelimit/list.go index 89956917c..d0aa60fd8 100644 --- a/pkg/commands/ratelimit/list.go +++ b/pkg/commands/ratelimit/list.go @@ -59,7 +59,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/resourcelink/create.go b/pkg/commands/resourcelink/create.go index ded301870..a53c32085 100644 --- a/pkg/commands/resourcelink/create.go +++ b/pkg/commands/resourcelink/create.go @@ -9,6 +9,7 @@ import ( fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // CreateCommand calls the Fastly API to create a resource link. @@ -88,6 +89,8 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/resourcelink/delete.go b/pkg/commands/resourcelink/delete.go index 16428a84a..ff5c7c23a 100644 --- a/pkg/commands/resourcelink/delete.go +++ b/pkg/commands/resourcelink/delete.go @@ -9,6 +9,7 @@ import ( fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // DeleteCommand calls the Fastly API to delete service resource links. @@ -76,6 +77,8 @@ func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/resourcelink/update.go b/pkg/commands/resourcelink/update.go index a143f3f4c..c92c2a09b 100644 --- a/pkg/commands/resourcelink/update.go +++ b/pkg/commands/resourcelink/update.go @@ -9,6 +9,7 @@ import ( fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // UpdateCommand calls the Fastly API to update a dictionary. @@ -87,6 +88,8 @@ func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/serviceversion/activate.go b/pkg/commands/serviceversion/activate.go index d25214701..6731554d4 100644 --- a/pkg/commands/serviceversion/activate.go +++ b/pkg/commands/serviceversion/activate.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // ActivateCommand calls the Fastly API to activate a service version. @@ -53,6 +54,7 @@ func NewActivateCommand(parent argparser.Registerer, g *global.Data) *ActivateCo // Exec invokes the application logic for the command. func (c *ActivateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/serviceversion/clone.go b/pkg/commands/serviceversion/clone.go index 9711303f1..49f719e56 100644 --- a/pkg/commands/serviceversion/clone.go +++ b/pkg/commands/serviceversion/clone.go @@ -48,7 +48,6 @@ func NewCloneCommand(parent argparser.Registerer, g *global.Data) *CloneCommand // Exec invokes the application logic for the command. func (c *CloneCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/serviceversion/deactivate.go b/pkg/commands/serviceversion/deactivate.go index 5c7d64cbf..be5ad807c 100644 --- a/pkg/commands/serviceversion/deactivate.go +++ b/pkg/commands/serviceversion/deactivate.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // DeactivateCommand calls the Fastly API to deactivate a service version. @@ -48,7 +49,7 @@ func NewDeactivateCommand(parent argparser.Registerer, g *global.Data) *Deactiva // Exec invokes the application logic for the command. func (c *DeactivateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, + Active: optional.Of(true), APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/serviceversion/lock.go b/pkg/commands/serviceversion/lock.go index 0087d8dc7..5745e2907 100644 --- a/pkg/commands/serviceversion/lock.go +++ b/pkg/commands/serviceversion/lock.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // LockCommand calls the Fastly API to lock a service version. @@ -48,7 +49,7 @@ func NewLockCommand(parent argparser.Registerer, g *global.Data) *LockCommand { // Exec invokes the application logic for the command. func (c *LockCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, + Locked: optional.Of(false), APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/serviceversion/serviceversion_test.go b/pkg/commands/serviceversion/serviceversion_test.go index 64a9f4956..b83650f62 100644 --- a/pkg/commands/serviceversion/serviceversion_test.go +++ b/pkg/commands/serviceversion/serviceversion_test.go @@ -125,6 +125,13 @@ func TestVersionActivate(t *testing.T) { Arg: "--service-id 123", WantError: "error parsing arguments: required flag --version not provided", }, + { + Arg: "--service-id 123 --version 1", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + WantError: "service version 1 is active", + }, { Arg: "--service-id 123 --version 1 --autoclone", API: mock.API{ @@ -143,6 +150,15 @@ func TestVersionActivate(t *testing.T) { }, WantOutput: "Activated service 123 version 4", }, + { + Arg: "--service-id 123 --version 2 --autoclone", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + CloneVersionFn: testutil.CloneVersionResult(4), + ActivateVersionFn: activateVersionOK, + }, + WantOutput: "Activated service 123 version 4", + }, { Arg: "--service-id 123 --version 3 --autoclone", API: mock.API{ @@ -176,10 +192,10 @@ func TestVersionDeactivate(t *testing.T) { ListVersionsFn: testutil.ListVersions, DeactivateVersionFn: deactivateVersionOK, }, - WantOutput: "Deactivated service 123 version 3", + WantError: "service version 3 is not active", }, { - Arg: "--service-id 123 --version 3", + Arg: "--service-id 123 --version 1", API: mock.API{ ListVersionsFn: testutil.ListVersions, DeactivateVersionFn: deactivateVersionError, diff --git a/pkg/commands/vcl/condition/create.go b/pkg/commands/vcl/condition/create.go index 74876bb38..0598b49eb 100644 --- a/pkg/commands/vcl/condition/create.go +++ b/pkg/commands/vcl/condition/create.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // ConditionTypes are the allowed input values for the --type flag. @@ -76,6 +77,8 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/vcl/condition/delete.go b/pkg/commands/vcl/condition/delete.go index e9f564c65..946e642f0 100644 --- a/pkg/commands/vcl/condition/delete.go +++ b/pkg/commands/vcl/condition/delete.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // DeleteCommand calls the Fastly API to delete an appropriate resource. @@ -62,6 +63,8 @@ func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteComman // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/vcl/condition/describe.go b/pkg/commands/vcl/condition/describe.go index 789260af7..3177b3b7a 100644 --- a/pkg/commands/vcl/condition/describe.go +++ b/pkg/commands/vcl/condition/describe.go @@ -61,7 +61,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/vcl/condition/list.go b/pkg/commands/vcl/condition/list.go index f5dc56f0e..8e961a825 100644 --- a/pkg/commands/vcl/condition/list.go +++ b/pkg/commands/vcl/condition/list.go @@ -59,7 +59,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/vcl/condition/update.go b/pkg/commands/vcl/condition/update.go index 802dcc994..ca75c420d 100644 --- a/pkg/commands/vcl/condition/update.go +++ b/pkg/commands/vcl/condition/update.go @@ -10,6 +10,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // UpdateCommand calls the Fastly API to update an appropriate resource. @@ -72,6 +73,8 @@ func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateComman // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/vcl/custom/create.go b/pkg/commands/vcl/custom/create.go index f6b2644c2..993d809af 100644 --- a/pkg/commands/vcl/custom/create.go +++ b/pkg/commands/vcl/custom/create.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // NewCreateCommand returns a usable command registered under the parent. @@ -67,6 +68,8 @@ type CreateCommand struct { // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/vcl/custom/custom_test.go b/pkg/commands/vcl/custom/custom_test.go index 5d976ff09..ad1658b24 100644 --- a/pkg/commands/vcl/custom/custom_test.go +++ b/pkg/commands/vcl/custom/custom_test.go @@ -18,12 +18,20 @@ func TestVCLCustomCreate(t *testing.T) { args := testutil.Args scenarios := []testutil.TestScenario{ { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: args("vcl custom create --content ./testdata/example.vcl --name foo --service-id 123 --version 1"), - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: args("vcl custom create --content ./testdata/example.vcl --name foo --service-id 123 --version 2"), + WantError: "service version 2 is locked", }, { Name: "validate CreateVCL API error", @@ -192,12 +200,20 @@ func TestVCLCustomDelete(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: args("vcl custom delete --name foobar --service-id 123 --version 1"), - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: args("vcl custom delete --name foobar --service-id 123 --version 2"), + WantError: "service version 2 is locked", }, { Name: "validate DeleteVCL API error", @@ -405,12 +421,20 @@ func TestVCLCustomUpdate(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: args("vcl custom update --name foobar --service-id 123 --version 1"), - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: args("vcl custom update --name foobar --service-id 123 --version 2"), + WantError: "service version 2 is locked", }, { Name: "validate UpdateVCL API error", diff --git a/pkg/commands/vcl/custom/delete.go b/pkg/commands/vcl/custom/delete.go index fdaac9ab3..a846dda7d 100644 --- a/pkg/commands/vcl/custom/delete.go +++ b/pkg/commands/vcl/custom/delete.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // NewDeleteCommand returns a usable command registered under the parent. @@ -63,6 +64,8 @@ type DeleteCommand struct { // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/vcl/custom/describe.go b/pkg/commands/vcl/custom/describe.go index cd22cdcfb..05205affa 100644 --- a/pkg/commands/vcl/custom/describe.go +++ b/pkg/commands/vcl/custom/describe.go @@ -64,7 +64,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/vcl/custom/list.go b/pkg/commands/vcl/custom/list.go index 7c879608f..0ce5f7dfe 100644 --- a/pkg/commands/vcl/custom/list.go +++ b/pkg/commands/vcl/custom/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/vcl/custom/update.go b/pkg/commands/vcl/custom/update.go index b8e9127ae..5b9d953ec 100644 --- a/pkg/commands/vcl/custom/update.go +++ b/pkg/commands/vcl/custom/update.go @@ -10,6 +10,7 @@ import ( fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // NewUpdateCommand returns a usable command registered under the parent. @@ -68,6 +69,8 @@ type UpdateCommand struct { // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/vcl/snippet/create.go b/pkg/commands/vcl/snippet/create.go index 286f1dfc4..29f67efee 100644 --- a/pkg/commands/vcl/snippet/create.go +++ b/pkg/commands/vcl/snippet/create.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // Locations is a list of VCL subroutines. @@ -75,6 +76,8 @@ type CreateCommand struct { // Exec invokes the application logic for the command. func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/vcl/snippet/delete.go b/pkg/commands/vcl/snippet/delete.go index 0ab1c2275..bd6af06d8 100644 --- a/pkg/commands/vcl/snippet/delete.go +++ b/pkg/commands/vcl/snippet/delete.go @@ -9,6 +9,7 @@ import ( "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // NewDeleteCommand returns a usable command registered under the parent. @@ -63,6 +64,8 @@ type DeleteCommand struct { // Exec invokes the application logic for the command. func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error { serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ + Active: optional.Of(false), + Locked: optional.Of(false), AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, diff --git a/pkg/commands/vcl/snippet/describe.go b/pkg/commands/vcl/snippet/describe.go index 831ee0825..503e56d10 100644 --- a/pkg/commands/vcl/snippet/describe.go +++ b/pkg/commands/vcl/snippet/describe.go @@ -68,7 +68,6 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/vcl/snippet/list.go b/pkg/commands/vcl/snippet/list.go index 0fbf4c74b..ef7067643 100644 --- a/pkg/commands/vcl/snippet/list.go +++ b/pkg/commands/vcl/snippet/list.go @@ -63,7 +63,6 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: true, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest, Out: out, diff --git a/pkg/commands/vcl/snippet/snippet_test.go b/pkg/commands/vcl/snippet/snippet_test.go index e1f5404e7..fd0eea0f6 100644 --- a/pkg/commands/vcl/snippet/snippet_test.go +++ b/pkg/commands/vcl/snippet/snippet_test.go @@ -23,12 +23,20 @@ func TestVCLSnippetCreate(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: args("vcl snippet create --content ./testdata/snippet.vcl --name foo --type recv --service-id 123 --version 1"), - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: args("vcl snippet create --content ./testdata/snippet.vcl --name foo --type recv --service-id 123 --version 2"), + WantError: "service version 2 is locked", }, { Name: "validate CreateSnippet API error", @@ -227,12 +235,20 @@ func TestVCLSnippetDelete(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: args("vcl snippet delete --name foobar --service-id 123 --version 1"), - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: args("vcl snippet delete --name foobar --service-id 123 --version 2"), + WantError: "service version 2 is locked", }, { Name: "validate DeleteSnippet API error", @@ -455,12 +471,20 @@ func TestVCLSnippetUpdate(t *testing.T) { WantError: "error reading service: no service ID found", }, { - Name: "validate missing --autoclone flag", + Name: "validate missing --autoclone flag with 'active' service", API: mock.API{ ListVersionsFn: testutil.ListVersions, }, Args: args("vcl snippet update --service-id 123 --version 1"), - WantError: "service version 1 is not editable", + WantError: "service version 1 is active", + }, + { + Name: "validate missing --autoclone flag with 'locked' service", + API: mock.API{ + ListVersionsFn: testutil.ListVersions, + }, + Args: args("vcl snippet update --service-id 123 --version 2"), + WantError: "service version 2 is locked", }, { Name: "validate versioned snippet missing --name", diff --git a/pkg/commands/vcl/snippet/update.go b/pkg/commands/vcl/snippet/update.go index c34e4b297..047bd1baa 100644 --- a/pkg/commands/vcl/snippet/update.go +++ b/pkg/commands/vcl/snippet/update.go @@ -10,6 +10,7 @@ import ( fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/text" + "github.com/fastly/cli/thirdparty/optional" ) // NewUpdateCommand returns a usable command registered under the parent. @@ -77,8 +78,19 @@ type UpdateCommand struct { // Exec invokes the application logic for the command. func (c *UpdateCommand) Exec(_ io.Reader, out io.Writer) error { + // in the normal case, we do not want to allow 'active' or 'locked' services to be updated, + // so we require those states to be 'false' + var allowActive = optional.Of(false) + var allowLocked = optional.Of(false) + if c.dynamic.WasSet && c.dynamic.Value { + // in this case, we will accept all states ('active' and 'inactive', 'locked' and 'unlocked'), + // so we mark the OptionalBools as 'unset' and they will not be applied as filters + allowActive = optional.Empty[bool]() + allowLocked = optional.Empty[bool]() + } serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ - AllowActiveLocked: c.dynamic.WasSet && c.dynamic.Value, + Active: allowActive, + Locked: allowLocked, AutoCloneFlag: c.autoClone, APIClient: c.Globals.APIClient, Manifest: *c.Globals.Manifest,