-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-kinesis-logging-endpoint
- Loading branch information
Showing
28 changed files
with
1,985 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package edgedictionary | ||
|
||
import ( | ||
"io" | ||
"strconv" | ||
|
||
"github.com/fastly/cli/pkg/common" | ||
"github.com/fastly/cli/pkg/compute/manifest" | ||
"github.com/fastly/cli/pkg/config" | ||
"github.com/fastly/cli/pkg/errors" | ||
"github.com/fastly/cli/pkg/text" | ||
"github.com/fastly/go-fastly/v2/fastly" | ||
) | ||
|
||
// CreateCommand calls the Fastly API to create a service. | ||
type CreateCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.CreateDictionaryInput | ||
|
||
writeOnly common.OptionalString | ||
} | ||
|
||
// NewCreateCommand returns a usable command registered under the parent. | ||
func NewCreateCommand(parent common.Registerer, globals *config.Data) *CreateCommand { | ||
var c CreateCommand | ||
c.Globals = globals | ||
c.manifest.File.Read(manifest.Filename) | ||
c.CmdClause = parent.Command("create", "Create a Fastly edge dictionary on a Fastly service version") | ||
c.CmdClause.Flag("service-id", "Service ID").Short('s').StringVar(&c.manifest.Flag.ServiceID) | ||
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.ServiceVersion) | ||
c.CmdClause.Flag("name", "Name of Dictionary").Short('n').Required().StringVar(&c.Input.Name) | ||
c.CmdClause.Flag("write-only", "Whether to mark this dictionary as write-only. Can be true or false (defaults to false)").Action(c.writeOnly.Set).StringVar(&c.writeOnly.Value) | ||
return &c | ||
} | ||
|
||
// Exec invokes the application logic for the command. | ||
func (c *CreateCommand) Exec(in io.Reader, out io.Writer) error { | ||
serviceID, source := c.manifest.ServiceID() | ||
if source == manifest.SourceUndefined { | ||
return errors.ErrNoServiceID | ||
} | ||
c.Input.ServiceID = serviceID | ||
|
||
if c.writeOnly.WasSet { | ||
writeOnly, err := strconv.ParseBool(c.writeOnly.Value) | ||
if err != nil { | ||
return err | ||
} | ||
c.Input.WriteOnly = fastly.Compatibool(writeOnly) | ||
} | ||
|
||
d, err := c.Globals.Client.CreateDictionary(&c.Input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var writeOnlyOutput string | ||
if d.WriteOnly { | ||
writeOnlyOutput = "as write-only " | ||
} | ||
|
||
text.Success(out, "Created dictionary %s %s(service %s version %d)", d.Name, writeOnlyOutput, d.ServiceID, d.ServiceVersion) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package edgedictionary | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/fastly/cli/pkg/common" | ||
"github.com/fastly/cli/pkg/compute/manifest" | ||
"github.com/fastly/cli/pkg/config" | ||
"github.com/fastly/cli/pkg/errors" | ||
"github.com/fastly/cli/pkg/text" | ||
"github.com/fastly/go-fastly/v2/fastly" | ||
) | ||
|
||
// DeleteCommand calls the Fastly API to delete a service. | ||
type DeleteCommand struct { | ||
common.Base | ||
manifest manifest.Data | ||
Input fastly.DeleteDictionaryInput | ||
} | ||
|
||
// NewDeleteCommand returns a usable command registered under the parent. | ||
func NewDeleteCommand(parent common.Registerer, globals *config.Data) *DeleteCommand { | ||
var c DeleteCommand | ||
c.Globals = globals | ||
c.manifest.File.Read(manifest.Filename) | ||
c.CmdClause = parent.Command("delete", "Delete a Fastly edge dictionary from a Fastly service version") | ||
c.CmdClause.Flag("service-id", "Service ID").Short('s').StringVar(&c.manifest.Flag.ServiceID) | ||
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.ServiceVersion) | ||
c.CmdClause.Flag("name", "Name of Dictionary").Short('n').Required().StringVar(&c.Input.Name) | ||
return &c | ||
} | ||
|
||
// Exec invokes the application logic for the command. | ||
func (c *DeleteCommand) Exec(in io.Reader, out io.Writer) error { | ||
serviceID, source := c.manifest.ServiceID() | ||
if source == manifest.SourceUndefined { | ||
return errors.ErrNoServiceID | ||
} | ||
c.Input.ServiceID = serviceID | ||
|
||
err := c.Globals.Client.DeleteDictionary(&c.Input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
text.Success(out, "Deleted dictionary %s (service %s version %d)", c.Input.Name, c.Input.ServiceID, c.Input.ServiceVersion) | ||
return nil | ||
} |
Oops, something went wrong.