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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

### Breaking:
- 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))

### Enhancements:
- feat(rust): Allow testing with prerelease Rust versions ([#1604](https://github.com/fastly/cli/pull/1604))
Expand Down
1 change: 0 additions & 1 deletion pkg/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ dashboard
dictionary
dictionary-entry
domain
domain-v1
healthcheck
imageoptimizer
install
Expand Down
30 changes: 15 additions & 15 deletions pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/fastly/cli/pkg/commands/dictionary"
"github.com/fastly/cli/pkg/commands/dictionaryentry"
"github.com/fastly/cli/pkg/commands/domain"
"github.com/fastly/cli/pkg/commands/domainv1"
"github.com/fastly/cli/pkg/commands/healthcheck"
"github.com/fastly/cli/pkg/commands/imageoptimizerdefaults"
"github.com/fastly/cli/pkg/commands/install"
Expand Down Expand Up @@ -94,6 +93,7 @@ import (
"github.com/fastly/cli/pkg/commands/secretstore"
"github.com/fastly/cli/pkg/commands/secretstoreentry"
"github.com/fastly/cli/pkg/commands/service"
servicedomain "github.com/fastly/cli/pkg/commands/service/domain"
servicepurge "github.com/fastly/cli/pkg/commands/service/purge"
"github.com/fastly/cli/pkg/commands/serviceauth"
"github.com/fastly/cli/pkg/commands/serviceversion"
Expand Down Expand Up @@ -228,13 +228,6 @@ func Define( // nolint:revive // function-length
domainDescribe := domain.NewDescribeCommand(domainCmdRoot.CmdClause, data)
domainList := domain.NewListCommand(domainCmdRoot.CmdClause, data)
domainUpdate := domain.NewUpdateCommand(domainCmdRoot.CmdClause, data)
domainValidate := domain.NewValidateCommand(domainCmdRoot.CmdClause, data)
domainv1CmdRoot := domainv1.NewRootCommand(app, data)
domainv1Create := domainv1.NewCreateCommand(domainv1CmdRoot.CmdClause, data)
domainv1Delete := domainv1.NewDeleteCommand(domainv1CmdRoot.CmdClause, data)
domainv1Describe := domainv1.NewDescribeCommand(domainv1CmdRoot.CmdClause, data)
domainv1List := domainv1.NewListCommand(domainv1CmdRoot.CmdClause, data)
domainv1Update := domainv1.NewUpdateCommand(domainv1CmdRoot.CmdClause, data)
healthcheckCmdRoot := healthcheck.NewRootCommand(app, data)
healthcheckCreate := healthcheck.NewCreateCommand(healthcheckCmdRoot.CmdClause, data)
healthcheckDelete := healthcheck.NewDeleteCommand(healthcheckCmdRoot.CmdClause, data)
Expand Down Expand Up @@ -639,6 +632,13 @@ func Define( // nolint:revive // function-length
serviceVersionStage := serviceversion.NewStageCommand(serviceVersionCmdRoot.CmdClause, data)
serviceVersionUnstage := serviceversion.NewUnstageCommand(serviceVersionCmdRoot.CmdClause, data)
serviceVersionUpdate := serviceversion.NewUpdateCommand(serviceVersionCmdRoot.CmdClause, data)
servicedomainCmdRoot := servicedomain.NewRootCommand(serviceCmdRoot.CmdClause, data)
servicedomainCreate := servicedomain.NewCreateCommand(servicedomainCmdRoot.CmdClause, data)
servicedomainDelete := servicedomain.NewDeleteCommand(servicedomainCmdRoot.CmdClause, data)
servicedomainDescribe := servicedomain.NewDescribeCommand(servicedomainCmdRoot.CmdClause, data)
servicedomainList := servicedomain.NewListCommand(servicedomainCmdRoot.CmdClause, data)
servicedomainUpdate := servicedomain.NewUpdateCommand(servicedomainCmdRoot.CmdClause, data)
servicedomainValidate := servicedomain.NewValidateCommand(servicedomainCmdRoot.CmdClause, data)
statsCmdRoot := stats.NewRootCommand(app, data)
statsHistorical := stats.NewHistoricalCommand(statsCmdRoot.CmdClause, data)
statsRealtime := stats.NewRealtimeCommand(statsCmdRoot.CmdClause, data)
Expand Down Expand Up @@ -809,13 +809,6 @@ func Define( // nolint:revive // function-length
domainDescribe,
domainList,
domainUpdate,
domainValidate,
domainv1CmdRoot,
domainv1Create,
domainv1Delete,
domainv1Describe,
domainv1List,
domainv1Update,
healthcheckCmdRoot,
healthcheckCreate,
healthcheckDelete,
Expand Down Expand Up @@ -1205,6 +1198,13 @@ func Define( // nolint:revive // function-length
serviceauthDescribe,
serviceauthList,
serviceauthUpdate,
servicedomainCmdRoot,
servicedomainCreate,
servicedomainDelete,
servicedomainDescribe,
servicedomainList,
servicedomainUpdate,
servicedomainValidate,
serviceVersionActivate,
serviceVersionClone,
serviceVersionCmdRoot,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package domainv1
package domain

import (
"fmt"
Expand Down
91 changes: 32 additions & 59 deletions pkg/commands/domain/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package domain

import (
"context"
"errors"
"fmt"
"io"

"github.com/fastly/go-fastly/v12/fastly"

"4d63.com/optional"
"github.com/fastly/go-fastly/v12/fastly/domainmanagement/v1/domains"

"github.com/fastly/cli/pkg/argparser"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/text"
)
Expand All @@ -19,13 +19,11 @@ type CreateCommand struct {
argparser.Base

// Required.
serviceVersion argparser.OptionalServiceVersion
fqdn string
serviceID string

// Optional.
autoClone argparser.OptionalAutoClone
comment argparser.OptionalString
name argparser.OptionalString
serviceName argparser.OptionalServiceNameID
description argparser.OptionalString
}

// NewCreateCommand returns a usable command registered under the parent.
Expand All @@ -35,77 +33,52 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
Globals: g,
},
}
c.CmdClause = parent.Command("create", "Create a domain on a Fastly service version").Alias("add")

// Required.
c.RegisterFlag(argparser.StringFlagOpts{
Name: argparser.FlagVersionName,
Description: argparser.FlagVersionDesc,
Dst: &c.serviceVersion.Value,
Required: true,
})
c.CmdClause = parent.Command("create", "Create a domain").Alias("add")

// Optional.
c.RegisterAutoCloneFlag(argparser.AutoCloneFlagOpts{
Action: c.autoClone.Set,
Dst: &c.autoClone.Value,
})
c.CmdClause.Flag("comment", "A descriptive note").Action(c.comment.Set).StringVar(&c.comment.Value)
c.CmdClause.Flag("name", "Domain name").Short('n').Action(c.name.Set).StringVar(&c.name.Value)
c.CmdClause.Flag("description", "The description for the domain").Action(c.description.Set).StringVar(&c.description.Value)
c.CmdClause.Flag("fqdn", "The fully qualified domain name").Required().StringVar(&c.fqdn)
c.RegisterFlag(argparser.StringFlagOpts{
Name: argparser.FlagServiceIDName,
Description: argparser.FlagServiceIDDesc,
Dst: &g.Manifest.Flag.ServiceID,
Description: "The service_id associated with your domain",
Dst: &c.serviceID,
Short: 's',
})
c.RegisterFlag(argparser.StringFlagOpts{
Action: c.serviceName.Set,
Name: argparser.FlagServiceName,
Description: argparser.FlagServiceNameDesc,
Dst: &c.serviceName.Value,
})
return &c
}

// 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,
Out: out,
ServiceNameFlag: c.serviceName,
ServiceVersionFlag: c.serviceVersion,
VerboseMode: c.Globals.Flags.Verbose,
})
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": errors.ServiceVersion(serviceVersion),
})
return err
input := &domains.CreateInput{
FQDN: &c.fqdn,
}
input := fastly.CreateDomainInput{
ServiceID: serviceID,
ServiceVersion: fastly.ToValue(serviceVersion.Number),
if c.serviceID != "" {
input.ServiceID = &c.serviceID
}
if c.name.WasSet {
input.Name = &c.name.Value

if c.description.WasSet {
input.Description = &c.description.Value
}
if c.comment.WasSet {
input.Comment = &c.comment.Value

fc, ok := c.Globals.APIClient.(*fastly.Client)
if !ok {
return errors.New("failed to convert interface to a fastly client")
}
d, err := c.Globals.APIClient.CreateDomain(context.TODO(), &input)

d, err := domains.Create(context.TODO(), fc, input)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": fastly.ToValue(serviceVersion.Number),
"FQDN": c.fqdn,
"Service ID": c.serviceID,
})
return err
}

text.Success(out, "Created domain %s (service %s version %d)", fastly.ToValue(d.Name), fastly.ToValue(d.ServiceID), fastly.ToValue(d.ServiceVersion))
serviceOutput := ""
if d.ServiceID != nil {
serviceOutput = fmt.Sprintf(", service-id: %s", *d.ServiceID)
}

text.Success(out, "Created domain '%s' (domain-id: %s%s)", d.FQDN, d.DomainID, serviceOutput)
return nil
}
70 changes: 15 additions & 55 deletions pkg/commands/domain/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@ package domain

import (
"context"
"errors"
"io"

"github.com/fastly/go-fastly/v12/fastly"

"4d63.com/optional"
"github.com/fastly/go-fastly/v12/fastly/domainmanagement/v1/domains"

"github.com/fastly/cli/pkg/argparser"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/text"
)

// DeleteCommand calls the Fastly API to delete domains.
type DeleteCommand struct {
argparser.Base
Input fastly.DeleteDomainInput
serviceName argparser.OptionalServiceNameID
serviceVersion argparser.OptionalServiceVersion
autoClone argparser.OptionalAutoClone
domainID string
}

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

// Required.
c.CmdClause.Flag("name", "Domain name").Short('n').Required().StringVar(&c.Input.Name)
c.RegisterFlag(argparser.StringFlagOpts{
Name: argparser.FlagVersionName,
Description: argparser.FlagVersionDesc,
Dst: &c.serviceVersion.Value,
Required: true,
})
c.CmdClause.Flag("domain-id", "The Domain Identifier (UUID)").Required().StringVar(&c.domainID)

// Optional.
c.RegisterAutoCloneFlag(argparser.AutoCloneFlagOpts{
Action: c.autoClone.Set,
Dst: &c.autoClone.Value,
})
c.RegisterFlag(argparser.StringFlagOpts{
Name: argparser.FlagServiceIDName,
Description: argparser.FlagServiceIDDesc,
Dst: &g.Manifest.Flag.ServiceID,
Short: 's',
})
c.RegisterFlag(argparser.StringFlagOpts{
Action: c.serviceName.Set,
Name: argparser.FlagServiceName,
Description: argparser.FlagServiceNameDesc,
Dst: &c.serviceName.Value,
})
return &c
}

// 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,
Out: out,
ServiceNameFlag: c.serviceName,
ServiceVersionFlag: c.serviceVersion,
VerboseMode: c.Globals.Flags.Verbose,
})
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": errors.ServiceVersion(serviceVersion),
})
return err
fc, ok := c.Globals.APIClient.(*fastly.Client)
if !ok {
return errors.New("failed to convert interface to a fastly client")
}

c.Input.ServiceID = serviceID
c.Input.ServiceVersion = fastly.ToValue(serviceVersion.Number)
input := &domains.DeleteInput{
DomainID: &c.domainID,
}

if err := c.Globals.APIClient.DeleteDomain(context.TODO(), &c.Input); err != nil {
err := domains.Delete(context.TODO(), fc, input)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Service Version": fastly.ToValue(serviceVersion.Number),
"Domain ID": c.domainID,
})
return err
}

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