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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
)

require (
github.com/fastly/go-fastly/v9 v9.12.0
github.com/fastly/go-fastly/v9 v9.13.0
github.com/hashicorp/cap v0.8.0
github.com/kennygrant/sanitize v1.2.4
github.com/otiai10/copy v1.14.1
Expand All @@ -38,6 +38,7 @@ require (
)

require (
github.com/dnaeon/go-vcr v1.2.0 // indirect
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/otiai10/mint v1.6.3 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj6
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/dustinkirkland/golang-petname v0.0.0-20240428194347-eebcea082ee0 h1:aYo8nnk3ojoQkP5iErif5Xxv0Mo0Ga/FR5+ffl/7+Nk=
github.com/dustinkirkland/golang-petname v0.0.0-20240428194347-eebcea082ee0/go.mod h1:8AuBTZBRSFqEYBPYULd+NN474/zZBLP+6WeT5S9xlAc=
github.com/fastly/go-fastly/v9 v9.12.0 h1:NUR4l+3LrSCux91sgKduFV8d/eejoGpQNlHa0ftKrFo=
github.com/fastly/go-fastly/v9 v9.12.0/go.mod h1:5w2jgJBZqQEebOwM/rRg7wutAcpDTziiMYWb/6qdM7U=
github.com/fastly/go-fastly/v9 v9.13.0 h1:/YpMLLquAruW2FZq01kY/VX5kouFCRMexwYfJbN/IWQ=
github.com/fastly/go-fastly/v9 v9.13.0/go.mod h1:oHzPMQCh93xygivG2qnri3XUdH7KDSUbAMv0+khzz3M=
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible h1:FhrXlfhgGCS+uc6YwyiFUt04alnjpoX7vgDKJxS6Qbk=
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible/go.mod h1:U8UynVoU1SQaqD2I4ZqgYd5lx3A1ipQYn4aSt2Y5h6c=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
Expand Down Expand Up @@ -90,6 +90,7 @@ github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQ
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
github.com/nicksnyder/go-i18n v1.10.3 h1:0U60fnLBNrLBVt8vb8Q67yKNs+gykbQuLsIkiesJL+w=
github.com/nicksnyder/go-i18n v1.10.3/go.mod h1:hvLG5HTlZ4UfSuVLSRuX7JRUomIaoKQM19hm6f+no7o=
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
Expand Down Expand Up @@ -214,6 +215,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
1 change: 1 addition & 0 deletions pkg/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ dashboard
dictionary
dictionary-entry
domain
domain-v1
healthcheck
install
ip-list
Expand Down
15 changes: 14 additions & 1 deletion pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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/install"
"github.com/fastly/cli/pkg/commands/ip"
Expand Down Expand Up @@ -86,7 +87,7 @@ import (
)

// Define constructs all the commands exposed by the CLI.
func Define(
func Define( // nolint:revive // function-length
app *kingpin.Application,
data *global.Data,
) []argparser.Command {
Expand Down Expand Up @@ -186,6 +187,12 @@ func Define(
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 @@ -578,6 +585,12 @@ func Define(
domainList,
domainUpdate,
domainValidate,
domainv1CmdRoot,
domainv1Create,
domainv1Delete,
domainv1Describe,
domainv1List,
domainv1Update,
healthcheckCmdRoot,
healthcheckCreate,
healthcheckDelete,
Expand Down
40 changes: 40 additions & 0 deletions pkg/commands/domainv1/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package domainv1

import (
"fmt"
"io"

v1 "github.com/fastly/go-fastly/v9/fastly/domains/v1"

"github.com/fastly/cli/pkg/text"
)

// printSummary displays the information returned from the API in a summarised
// format.
func printSummary(out io.Writer, data []v1.Data) {
t := text.NewTable(out)
t.AddHeader("FQDN", "DOMAIN ID", "SERVICE ID", "CREATED AT", "UPDATED AT")
for _, d := range data {
var sid string
if d.ServiceID != nil {
sid = *d.ServiceID
}
t.AddLine(d.FQDN, d.DomainID, sid, d.CreatedAt, d.UpdatedAt)
}
t.Print()
}

// printSummary displays the information returned from the API in a verbose
// format.
func printVerbose(out io.Writer, data []v1.Data) {
for _, d := range data {
fmt.Fprintf(out, "FQDN: %s\n", d.FQDN)
fmt.Fprintf(out, "Domain ID: %s\n", d.DomainID)
if d.ServiceID != nil {
fmt.Fprintf(out, "Service ID: %s\n", *d.ServiceID)
}
fmt.Fprintf(out, "Created at: %s\n", d.CreatedAt)
fmt.Fprintf(out, "Updated at: %s\n", d.UpdatedAt)
fmt.Fprintf(out, "\n")
}
}
75 changes: 75 additions & 0 deletions pkg/commands/domainv1/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package domainv1

import (
"errors"
"fmt"
"io"

"github.com/fastly/go-fastly/v9/fastly"
v1 "github.com/fastly/go-fastly/v9/fastly/domains/v1"

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

// CreateCommand calls the Fastly API to create domains.
type CreateCommand struct {
argparser.Base

// Required.
fqdn string
serviceID string
}

// NewCreateCommand returns a usable command registered under the parent.
func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateCommand {
c := CreateCommand{
Base: argparser.Base{
Globals: g,
},
}
c.CmdClause = parent.Command("create", "Create a domain").Alias("add")

// Optional.
c.CmdClause.Flag("fqdn", "The fully qualified domain name").Required().StringVar(&c.fqdn)
c.RegisterFlag(argparser.StringFlagOpts{
Name: argparser.FlagServiceIDName,
Description: "The service_id associated with your domain",
Dst: &c.serviceID,
Short: 's',
})
return &c
}

// Exec invokes the application logic for the command.
func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error {
input := &v1.CreateInput{
FQDN: &c.fqdn,
}
if c.serviceID != "" {
input.ServiceID = &c.serviceID
}

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

d, err := v1.Create(fc, input)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"FQDN": c.fqdn,
"Service ID": c.serviceID,
})
return err
}

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
}
57 changes: 57 additions & 0 deletions pkg/commands/domainv1/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package domainv1

import (
"errors"
"io"

"github.com/fastly/go-fastly/v9/fastly"
v1 "github.com/fastly/go-fastly/v9/fastly/domains/v1"

"github.com/fastly/cli/pkg/argparser"
"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
domainID string
}

// NewDeleteCommand returns a usable command registered under the parent.
func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteCommand {
c := DeleteCommand{
Base: argparser.Base{
Globals: g,
},
}
c.CmdClause = parent.Command("delete", "Delete a domain").Alias("remove")

// Required.
c.CmdClause.Flag("domain-id", "The Domain Identifier (UUID)").Required().StringVar(&c.domainID)

return &c
}

// Exec invokes the application logic for the command.
func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error {
fc, ok := c.Globals.APIClient.(*fastly.Client)
if !ok {
return errors.New("failed to convert interface to a fastly client")
}

input := &v1.DeleteInput{
DomainID: &c.domainID,
}

err := v1.Delete(fc, input)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Domain ID": c.domainID,
})
return err
}

text.Success(out, "Deleted domain (domain-id: %s)", c.domainID)
return nil
}
75 changes: 75 additions & 0 deletions pkg/commands/domainv1/describe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package domainv1

import (
"errors"
"io"

"github.com/fastly/go-fastly/v9/fastly"
v1 "github.com/fastly/go-fastly/v9/fastly/domains/v1"

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

// DescribeCommand calls the Fastly API to describe a domain.
type DescribeCommand struct {
argparser.Base
argparser.JSONOutput
domainID string
}

// NewDescribeCommand returns a usable command registered under the parent.
func NewDescribeCommand(parent argparser.Registerer, g *global.Data) *DescribeCommand {
c := DescribeCommand{
Base: argparser.Base{
Globals: g,
},
}
c.CmdClause = parent.Command("describe", "Show detailed information about a domain").Alias("get")

// Required.
c.CmdClause.Flag("domain-id", "The Domain Identifier (UUID)").Required().StringVar(&c.domainID)

// Optional.
c.RegisterFlagBool(c.JSONFlag()) // --json
return &c
}

// Exec invokes the application logic for the command.
func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
if c.Globals.Verbose() && c.JSONOutput.Enabled {
return fsterr.ErrInvalidVerboseJSONCombo
}

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

input := &v1.GetInput{
DomainID: &c.domainID,
}

d, err := v1.Get(fc, input)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Domain ID": c.domainID,
})
return err
}

if ok, err := c.WriteJSON(out, d); ok {
return err
}

if d != nil {
cl := []v1.Data{*d}
if c.Globals.Verbose() {
printVerbose(out, cl)
} else {
printSummary(out, cl)
}
}
return nil
}
2 changes: 2 additions & 0 deletions pkg/commands/domainv1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package domain contains commands to inspect and manipulate Fastly domains.

Check failure on line 1 in pkg/commands/domainv1/doc.go

View workflow job for this annotation

GitHub Actions / lint

package comment should be of the form "Package domainv1 ..."
package domainv1
Loading