Skip to content

Commit e3bd798

Browse files
authored
[Breaking][CDTOOL-1256] Move domainv1 commands to domain and move prior domain command to service/domain (#1615)
### Change summary <!-- Briefly describe the changes introduced in this pull request. Include context or reasoning behind the changes, even if they seem minor. If relevant, link to any related discussions (e.g. Slack threads, tickets, documents). --> All Submissions: * [x] Have you followed the guidelines in our Contributing document? * [x] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/fastly/cli/pulls) for the same update/change? <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### New Feature Submissions: * [x] Does your submission pass tests? ``` make test TEST_ARGS="-run TestDomainCreate ./pkg/commands/domain" ok github.com/fastly/cli/pkg/commands/domain 1.063s make test TEST_ARGS="-run TestDomainList ./pkg/commands/doma in" ok github.com/fastly/cli/pkg/commands/domain 1.044s make test TEST_ARGS="-run TestDomainDescribe ./pkg/commands/ domain" ok github.com/fastly/cli/pkg/commands/domain 1.045s make test TEST_ARGS="-run TestDomainUpdate ./pkg/commands/do main" ok github.com/fastly/cli/pkg/commands/domain 1.052s make test TEST_ARGS="-run TestDomainDelete ./pkg/commands/do main" ok github.com/fastly/cli/pkg/commands/domain 1.044s --- make test TEST_ARGS="-run TestDomainDelete ./pkg/commands/service/domain" ok github.com/fastly/cli/pkg/commands/service/domain 1.047s make test TEST_ARGS="-run TestDomainValidate ./pkg/commands/ service/domain" ok github.com/fastly/cli/pkg/commands/service/domain 1.072s make test TEST_ARGS="-run TestDomainUpdate ./pkg/commands/se rvice/domain" ok github.com/fastly/cli/pkg/commands/service/domain 1.051s make test TEST_ARGS="-run TestDomainDescribe ./pkg/commands/ service/domain" ok github.com/fastly/cli/pkg/commands/service/domain 1.059s make test TEST_ARGS="-run TestDomainList ./pkg/commands/serv ice/domain" ok github.com/fastly/cli/pkg/commands/service/domain 1.062s make test TEST_ARGS="-run TestDomainCreate ./pkg/commands/se rvice/domain" ok github.com/fastly/cli/pkg/commands/service/domain 1.049s ``` ### Changes to Core Features: * [ ] Have you written new tests for your core changes, as applicable? * [x] Have you successfully run tests with your changes locally? ### User Impact Service version oriented `domain` commands have been moved under the `service domain` command. Versionless `domainv1` commands have been moved to the `domain` command. ### Are there any considerations that need to be addressed for release? End users that are using the CLI in any workflows for domains will need to update accordingly for these command changes.
1 parent c22a60b commit e3bd798

28 files changed

Lines changed: 1369 additions & 1368 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
### Breaking:
6+
- breaking(domain) - service version oriented `domain` commands have been moved under the `service domain` command. Versionless `domainv1` commands have been moved to the `domain` command ([#1615](https://github.com/fastly/cli/pull/1615))
67

78
### Enhancements:
89
- feat(rust): Allow testing with prerelease Rust versions ([#1604](https://github.com/fastly/cli/pull/1604))

pkg/app/run_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ dashboard
7373
dictionary
7474
dictionary-entry
7575
domain
76-
domain-v1
7776
healthcheck
7877
imageoptimizer
7978
install

pkg/commands/commands.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/fastly/cli/pkg/commands/dictionary"
2121
"github.com/fastly/cli/pkg/commands/dictionaryentry"
2222
"github.com/fastly/cli/pkg/commands/domain"
23-
"github.com/fastly/cli/pkg/commands/domainv1"
2423
"github.com/fastly/cli/pkg/commands/healthcheck"
2524
"github.com/fastly/cli/pkg/commands/imageoptimizerdefaults"
2625
"github.com/fastly/cli/pkg/commands/install"
@@ -94,6 +93,7 @@ import (
9493
"github.com/fastly/cli/pkg/commands/secretstore"
9594
"github.com/fastly/cli/pkg/commands/secretstoreentry"
9695
"github.com/fastly/cli/pkg/commands/service"
96+
servicedomain "github.com/fastly/cli/pkg/commands/service/domain"
9797
servicepurge "github.com/fastly/cli/pkg/commands/service/purge"
9898
"github.com/fastly/cli/pkg/commands/serviceauth"
9999
"github.com/fastly/cli/pkg/commands/serviceversion"
@@ -228,13 +228,6 @@ func Define( // nolint:revive // function-length
228228
domainDescribe := domain.NewDescribeCommand(domainCmdRoot.CmdClause, data)
229229
domainList := domain.NewListCommand(domainCmdRoot.CmdClause, data)
230230
domainUpdate := domain.NewUpdateCommand(domainCmdRoot.CmdClause, data)
231-
domainValidate := domain.NewValidateCommand(domainCmdRoot.CmdClause, data)
232-
domainv1CmdRoot := domainv1.NewRootCommand(app, data)
233-
domainv1Create := domainv1.NewCreateCommand(domainv1CmdRoot.CmdClause, data)
234-
domainv1Delete := domainv1.NewDeleteCommand(domainv1CmdRoot.CmdClause, data)
235-
domainv1Describe := domainv1.NewDescribeCommand(domainv1CmdRoot.CmdClause, data)
236-
domainv1List := domainv1.NewListCommand(domainv1CmdRoot.CmdClause, data)
237-
domainv1Update := domainv1.NewUpdateCommand(domainv1CmdRoot.CmdClause, data)
238231
healthcheckCmdRoot := healthcheck.NewRootCommand(app, data)
239232
healthcheckCreate := healthcheck.NewCreateCommand(healthcheckCmdRoot.CmdClause, data)
240233
healthcheckDelete := healthcheck.NewDeleteCommand(healthcheckCmdRoot.CmdClause, data)
@@ -639,6 +632,13 @@ func Define( // nolint:revive // function-length
639632
serviceVersionStage := serviceversion.NewStageCommand(serviceVersionCmdRoot.CmdClause, data)
640633
serviceVersionUnstage := serviceversion.NewUnstageCommand(serviceVersionCmdRoot.CmdClause, data)
641634
serviceVersionUpdate := serviceversion.NewUpdateCommand(serviceVersionCmdRoot.CmdClause, data)
635+
servicedomainCmdRoot := servicedomain.NewRootCommand(serviceCmdRoot.CmdClause, data)
636+
servicedomainCreate := servicedomain.NewCreateCommand(servicedomainCmdRoot.CmdClause, data)
637+
servicedomainDelete := servicedomain.NewDeleteCommand(servicedomainCmdRoot.CmdClause, data)
638+
servicedomainDescribe := servicedomain.NewDescribeCommand(servicedomainCmdRoot.CmdClause, data)
639+
servicedomainList := servicedomain.NewListCommand(servicedomainCmdRoot.CmdClause, data)
640+
servicedomainUpdate := servicedomain.NewUpdateCommand(servicedomainCmdRoot.CmdClause, data)
641+
servicedomainValidate := servicedomain.NewValidateCommand(servicedomainCmdRoot.CmdClause, data)
642642
statsCmdRoot := stats.NewRootCommand(app, data)
643643
statsHistorical := stats.NewHistoricalCommand(statsCmdRoot.CmdClause, data)
644644
statsRealtime := stats.NewRealtimeCommand(statsCmdRoot.CmdClause, data)
@@ -809,13 +809,6 @@ func Define( // nolint:revive // function-length
809809
domainDescribe,
810810
domainList,
811811
domainUpdate,
812-
domainValidate,
813-
domainv1CmdRoot,
814-
domainv1Create,
815-
domainv1Delete,
816-
domainv1Describe,
817-
domainv1List,
818-
domainv1Update,
819812
healthcheckCmdRoot,
820813
healthcheckCreate,
821814
healthcheckDelete,
@@ -1205,6 +1198,13 @@ func Define( // nolint:revive // function-length
12051198
serviceauthDescribe,
12061199
serviceauthList,
12071200
serviceauthUpdate,
1201+
servicedomainCmdRoot,
1202+
servicedomainCreate,
1203+
servicedomainDelete,
1204+
servicedomainDescribe,
1205+
servicedomainList,
1206+
servicedomainUpdate,
1207+
servicedomainValidate,
12081208
serviceVersionActivate,
12091209
serviceVersionClone,
12101210
serviceVersionCmdRoot,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package domainv1
1+
package domain
22

33
import (
44
"fmt"

pkg/commands/domain/create.go

Lines changed: 32 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package domain
22

33
import (
44
"context"
5+
"errors"
6+
"fmt"
57
"io"
68

79
"github.com/fastly/go-fastly/v12/fastly"
8-
9-
"4d63.com/optional"
10+
"github.com/fastly/go-fastly/v12/fastly/domainmanagement/v1/domains"
1011

1112
"github.com/fastly/cli/pkg/argparser"
12-
"github.com/fastly/cli/pkg/errors"
1313
"github.com/fastly/cli/pkg/global"
1414
"github.com/fastly/cli/pkg/text"
1515
)
@@ -19,13 +19,11 @@ type CreateCommand struct {
1919
argparser.Base
2020

2121
// Required.
22-
serviceVersion argparser.OptionalServiceVersion
22+
fqdn string
23+
serviceID string
2324

2425
// Optional.
25-
autoClone argparser.OptionalAutoClone
26-
comment argparser.OptionalString
27-
name argparser.OptionalString
28-
serviceName argparser.OptionalServiceNameID
26+
description argparser.OptionalString
2927
}
3028

3129
// NewCreateCommand returns a usable command registered under the parent.
@@ -35,77 +33,52 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
3533
Globals: g,
3634
},
3735
}
38-
c.CmdClause = parent.Command("create", "Create a domain on a Fastly service version").Alias("add")
39-
40-
// Required.
41-
c.RegisterFlag(argparser.StringFlagOpts{
42-
Name: argparser.FlagVersionName,
43-
Description: argparser.FlagVersionDesc,
44-
Dst: &c.serviceVersion.Value,
45-
Required: true,
46-
})
36+
c.CmdClause = parent.Command("create", "Create a domain").Alias("add")
4737

4838
// Optional.
49-
c.RegisterAutoCloneFlag(argparser.AutoCloneFlagOpts{
50-
Action: c.autoClone.Set,
51-
Dst: &c.autoClone.Value,
52-
})
53-
c.CmdClause.Flag("comment", "A descriptive note").Action(c.comment.Set).StringVar(&c.comment.Value)
54-
c.CmdClause.Flag("name", "Domain name").Short('n').Action(c.name.Set).StringVar(&c.name.Value)
39+
c.CmdClause.Flag("description", "The description for the domain").Action(c.description.Set).StringVar(&c.description.Value)
40+
c.CmdClause.Flag("fqdn", "The fully qualified domain name").Required().StringVar(&c.fqdn)
5541
c.RegisterFlag(argparser.StringFlagOpts{
5642
Name: argparser.FlagServiceIDName,
57-
Description: argparser.FlagServiceIDDesc,
58-
Dst: &g.Manifest.Flag.ServiceID,
43+
Description: "The service_id associated with your domain",
44+
Dst: &c.serviceID,
5945
Short: 's',
6046
})
61-
c.RegisterFlag(argparser.StringFlagOpts{
62-
Action: c.serviceName.Set,
63-
Name: argparser.FlagServiceName,
64-
Description: argparser.FlagServiceNameDesc,
65-
Dst: &c.serviceName.Value,
66-
})
6747
return &c
6848
}
6949

7050
// Exec invokes the application logic for the command.
7151
func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error {
72-
serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{
73-
Active: optional.Of(false),
74-
Locked: optional.Of(false),
75-
AutoCloneFlag: c.autoClone,
76-
APIClient: c.Globals.APIClient,
77-
Manifest: *c.Globals.Manifest,
78-
Out: out,
79-
ServiceNameFlag: c.serviceName,
80-
ServiceVersionFlag: c.serviceVersion,
81-
VerboseMode: c.Globals.Flags.Verbose,
82-
})
83-
if err != nil {
84-
c.Globals.ErrLog.AddWithContext(err, map[string]any{
85-
"Service ID": serviceID,
86-
"Service Version": errors.ServiceVersion(serviceVersion),
87-
})
88-
return err
52+
input := &domains.CreateInput{
53+
FQDN: &c.fqdn,
8954
}
90-
input := fastly.CreateDomainInput{
91-
ServiceID: serviceID,
92-
ServiceVersion: fastly.ToValue(serviceVersion.Number),
55+
if c.serviceID != "" {
56+
input.ServiceID = &c.serviceID
9357
}
94-
if c.name.WasSet {
95-
input.Name = &c.name.Value
58+
59+
if c.description.WasSet {
60+
input.Description = &c.description.Value
9661
}
97-
if c.comment.WasSet {
98-
input.Comment = &c.comment.Value
62+
63+
fc, ok := c.Globals.APIClient.(*fastly.Client)
64+
if !ok {
65+
return errors.New("failed to convert interface to a fastly client")
9966
}
100-
d, err := c.Globals.APIClient.CreateDomain(context.TODO(), &input)
67+
68+
d, err := domains.Create(context.TODO(), fc, input)
10169
if err != nil {
10270
c.Globals.ErrLog.AddWithContext(err, map[string]any{
103-
"Service ID": serviceID,
104-
"Service Version": fastly.ToValue(serviceVersion.Number),
71+
"FQDN": c.fqdn,
72+
"Service ID": c.serviceID,
10573
})
10674
return err
10775
}
10876

109-
text.Success(out, "Created domain %s (service %s version %d)", fastly.ToValue(d.Name), fastly.ToValue(d.ServiceID), fastly.ToValue(d.ServiceVersion))
77+
serviceOutput := ""
78+
if d.ServiceID != nil {
79+
serviceOutput = fmt.Sprintf(", service-id: %s", *d.ServiceID)
80+
}
81+
82+
text.Success(out, "Created domain '%s' (domain-id: %s%s)", d.FQDN, d.DomainID, serviceOutput)
11083
return nil
11184
}

pkg/commands/domain/delete.go

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@ package domain
22

33
import (
44
"context"
5+
"errors"
56
"io"
67

78
"github.com/fastly/go-fastly/v12/fastly"
8-
9-
"4d63.com/optional"
9+
"github.com/fastly/go-fastly/v12/fastly/domainmanagement/v1/domains"
1010

1111
"github.com/fastly/cli/pkg/argparser"
12-
"github.com/fastly/cli/pkg/errors"
1312
"github.com/fastly/cli/pkg/global"
1413
"github.com/fastly/cli/pkg/text"
1514
)
1615

1716
// DeleteCommand calls the Fastly API to delete domains.
1817
type DeleteCommand struct {
1918
argparser.Base
20-
Input fastly.DeleteDomainInput
21-
serviceName argparser.OptionalServiceNameID
22-
serviceVersion argparser.OptionalServiceVersion
23-
autoClone argparser.OptionalAutoClone
19+
domainID string
2420
}
2521

2622
// NewDeleteCommand returns a usable command registered under the parent.
@@ -30,69 +26,33 @@ func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteComman
3026
Globals: g,
3127
},
3228
}
33-
c.CmdClause = parent.Command("delete", "Delete a domain on a Fastly service version").Alias("remove")
29+
c.CmdClause = parent.Command("delete", "Delete a domain").Alias("remove")
3430

3531
// Required.
36-
c.CmdClause.Flag("name", "Domain name").Short('n').Required().StringVar(&c.Input.Name)
37-
c.RegisterFlag(argparser.StringFlagOpts{
38-
Name: argparser.FlagVersionName,
39-
Description: argparser.FlagVersionDesc,
40-
Dst: &c.serviceVersion.Value,
41-
Required: true,
42-
})
32+
c.CmdClause.Flag("domain-id", "The Domain Identifier (UUID)").Required().StringVar(&c.domainID)
4333

44-
// Optional.
45-
c.RegisterAutoCloneFlag(argparser.AutoCloneFlagOpts{
46-
Action: c.autoClone.Set,
47-
Dst: &c.autoClone.Value,
48-
})
49-
c.RegisterFlag(argparser.StringFlagOpts{
50-
Name: argparser.FlagServiceIDName,
51-
Description: argparser.FlagServiceIDDesc,
52-
Dst: &g.Manifest.Flag.ServiceID,
53-
Short: 's',
54-
})
55-
c.RegisterFlag(argparser.StringFlagOpts{
56-
Action: c.serviceName.Set,
57-
Name: argparser.FlagServiceName,
58-
Description: argparser.FlagServiceNameDesc,
59-
Dst: &c.serviceName.Value,
60-
})
6134
return &c
6235
}
6336

6437
// Exec invokes the application logic for the command.
6538
func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error {
66-
serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{
67-
Active: optional.Of(false),
68-
Locked: optional.Of(false),
69-
AutoCloneFlag: c.autoClone,
70-
APIClient: c.Globals.APIClient,
71-
Manifest: *c.Globals.Manifest,
72-
Out: out,
73-
ServiceNameFlag: c.serviceName,
74-
ServiceVersionFlag: c.serviceVersion,
75-
VerboseMode: c.Globals.Flags.Verbose,
76-
})
77-
if err != nil {
78-
c.Globals.ErrLog.AddWithContext(err, map[string]any{
79-
"Service ID": serviceID,
80-
"Service Version": errors.ServiceVersion(serviceVersion),
81-
})
82-
return err
39+
fc, ok := c.Globals.APIClient.(*fastly.Client)
40+
if !ok {
41+
return errors.New("failed to convert interface to a fastly client")
8342
}
8443

85-
c.Input.ServiceID = serviceID
86-
c.Input.ServiceVersion = fastly.ToValue(serviceVersion.Number)
44+
input := &domains.DeleteInput{
45+
DomainID: &c.domainID,
46+
}
8747

88-
if err := c.Globals.APIClient.DeleteDomain(context.TODO(), &c.Input); err != nil {
48+
err := domains.Delete(context.TODO(), fc, input)
49+
if err != nil {
8950
c.Globals.ErrLog.AddWithContext(err, map[string]any{
90-
"Service ID": serviceID,
91-
"Service Version": fastly.ToValue(serviceVersion.Number),
51+
"Domain ID": c.domainID,
9252
})
9353
return err
9454
}
9555

96-
text.Success(out, "Deleted domain %s (service %s version %d)", c.Input.Name, c.Input.ServiceID, c.Input.ServiceVersion)
56+
text.Success(out, "Deleted domain (domain-id: %s)", c.domainID)
9757
return nil
9858
}

0 commit comments

Comments
 (0)