Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: actions promote and actions versions #53

Merged
merged 5 commits into from
Jan 27, 2021
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ require (

// replace gopkg.in/auth0.v5 => ../auth0

replace gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210126164439-7451a183abbd
replace gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210127020221-38fd79682c4a
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ github.com/go-auth0/auth0 v1.3.1-0.20210126044025-c2f94c36f593 h1:Ty0FV0S+59z1io
github.com/go-auth0/auth0 v1.3.1-0.20210126044025-c2f94c36f593/go.mod h1:pbIRmwBulkHNKKsUGGvhyIOI2itMhz2OfwtPaFXBSSQ=
github.com/go-auth0/auth0 v1.3.1-0.20210126164439-7451a183abbd h1:O1ZCQlPODGWJNDT0qH6SpGdFEcEBWz7dd/mHFw6Kh10=
github.com/go-auth0/auth0 v1.3.1-0.20210126164439-7451a183abbd/go.mod h1:QQ9fgGj2Wpza15+Ho3mM6amMeKfhzHo2cixcOqdkoKk=
github.com/go-auth0/auth0 v1.3.1-0.20210126214458-2807092480f8 h1:x5rbuD/ay7ieXnEynRnTA92qHbe6uMTxumOWfsCPiws=
github.com/go-auth0/auth0 v1.3.1-0.20210126214458-2807092480f8/go.mod h1:QQ9fgGj2Wpza15+Ho3mM6amMeKfhzHo2cixcOqdkoKk=
github.com/go-auth0/auth0 v1.3.1-0.20210127020221-38fd79682c4a h1:TAnbIrM2gdxfqT4pdPso61aO74mS+mNuIbRDYhfSNKI=
github.com/go-auth0/auth0 v1.3.1-0.20210127020221-38fd79682c4a/go.mod h1:QQ9fgGj2Wpza15+Ho3mM6amMeKfhzHo2cixcOqdkoKk=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down
4 changes: 3 additions & 1 deletion internal/auth0/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ type ActionAPI interface {
type ActionVersionAPI interface {
Create(actionID string, v *management.ActionVersion) error
Read(actionID string, id string) (*management.ActionVersion, error)
Update(id string, a *management.ActionVersion) error
UpsertDraft(id string, a *management.ActionVersion) error
Delete(actionID string, id string, opts ...management.RequestOption) error
List(actionID string, opts ...management.RequestOption) (c *management.ActionVersionList, err error)
Test(actionID string, id string, payload management.Object) (management.Object, error)
Deploy(actionID string, id string) (*management.ActionVersion, error)
}

type ActionBindingAPI interface {
Expand Down
70 changes: 68 additions & 2 deletions internal/cli/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func actionsCmd(cli *cli) *cobra.Command {
cmd.AddCommand(listActionsCmd(cli))
cmd.AddCommand(testActionCmd(cli))
cmd.AddCommand(createActionCmd(cli))
cmd.AddCommand(deployActionCmd(cli))
cmd.AddCommand(listActionVersionsCmd(cli))
cmd.AddCommand(triggersCmd(cli))

return cmd
Expand Down Expand Up @@ -127,6 +129,70 @@ func testActionCmd(cli *cli) *cobra.Command {
return cmd
}

func deployActionCmd(cli *cli) *cobra.Command {
var actionId string
var versionId string

cmd := &cobra.Command{
Use: "deploy",
Short: "Deploys the action version",
Long: `$ auth0 actions deploy --name <actionid> --version <versionid>`,
RunE: func(cmd *cobra.Command, args []string) error {
var version *management.ActionVersion
err := ansi.Spinner(fmt.Sprintf("Deploying action: %s, version: %s", actionId, versionId), func() (err error) {
version, err = cli.api.ActionVersion.Deploy(actionId, versionId)
return err
})

if err != nil {
return err
}

cli.renderer.ActionVersion(version)

return nil
},
}

cmd.Flags().StringVar(&actionId, "name", "", "Action ID to deploy")
cmd.Flags().StringVarP(&versionId, "version", "v", "draft", "Version ID of the action to deploy")

mustRequireFlags(cmd, "name")

return cmd
}

func listActionVersionsCmd(cli *cli) *cobra.Command {
var actionId string

cmd := &cobra.Command{
Use: "versions",
Short: "Lists the action versions",
Long: `$ auth0 actions versions --name <actionid>`,
RunE: func(cmd *cobra.Command, args []string) error {
var list *management.ActionVersionList
err := ansi.Spinner(fmt.Sprintf("Loading versions for action: %s", actionId), func() (err error) {
list, err = cli.api.ActionVersion.List(actionId)
return err
})

if err != nil {
return err
}

cli.renderer.ActionVersionList(list.Versions)

return nil
},
}

cmd.Flags().StringVar(&actionId, "name", "", "Action ID to show versions")

mustRequireFlags(cmd, "name")

return cmd
}

func createActionCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Expand Down Expand Up @@ -173,12 +239,12 @@ Creates a new action:
return err
}

cli.renderer.ActionCreate(action)
cli.renderer.Action(action)
return nil
},
}

cmd.LocalFlags().StringP("trigger", "t", string(management.PostLogin), "Trigger type for action.")
cmd.Flags().StringP("trigger", "t", string(management.PostLogin), "Trigger type for action.")

return cmd
}
Expand Down
48 changes: 46 additions & 2 deletions internal/display/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ func (v *triggerView) AsTableRow() []string {
return []string{v.ID, v.ActionID, v.DisplayName}
}

type actionVersionView struct {
ID string
Status string
Runtime string
CreatedAt string
}

func (v *actionVersionView) AsTableHeader() []string {
return []string{"ID", "Status", "Runtime", "Created At"}
}

func (v *actionVersionView) AsTableRow() []string {
return []string{v.ID, v.Status, v.Runtime, v.CreatedAt}
}

func (r *Renderer) ActionList(actions []*management.Action) {
r.Heading(ansi.Bold(r.Tenant), "actions\n")

Expand Down Expand Up @@ -65,8 +80,8 @@ func (r *Renderer) ActionTest(payload management.Object) {
r.JSONResult(payload)
}

func (r *Renderer) ActionCreate(action *management.Action) {
r.Heading(ansi.Bold(r.Tenant), "action created\n")
func (r *Renderer) Action(action *management.Action) {
r.Heading(ansi.Bold(r.Tenant), "action\n")

var triggers = make([]string, 0, len(*action.SupportedTriggers))
for _, t := range *action.SupportedTriggers {
Expand Down Expand Up @@ -98,3 +113,32 @@ func (r *Renderer) ActionTriggersList(bindings []*management.ActionBinding) {

r.Results(res)
}

func (r *Renderer) ActionVersion(version *management.ActionVersion) {
r.Heading(ansi.Bold(r.Tenant), "action version\n")

v := &actionVersionView{
ID: auth0.StringValue(&version.ID),
Status: string(version.Status),
Runtime: auth0.StringValue(&version.Runtime),
CreatedAt: timeAgo(auth0.TimeValue(version.CreatedAt)),
}

r.Results([]View{v})
}

func (r *Renderer) ActionVersionList(list []*management.ActionVersion) {
r.Heading(ansi.Bold(r.Tenant), "action versions\n")

var res []View
for _, version := range list {
res = append(res, &actionVersionView{
ID: auth0.StringValue(&version.ID),
Status: string(version.Status),
Runtime: auth0.StringValue(&version.Runtime),
CreatedAt: timeAgo(auth0.TimeValue(version.CreatedAt)),
})
}

r.Results(res)
}
7 changes: 3 additions & 4 deletions vendor/gopkg.in/auth0.v5/management/actions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ google.golang.org/protobuf/reflect/protoreflect
google.golang.org/protobuf/reflect/protoregistry
google.golang.org/protobuf/runtime/protoiface
google.golang.org/protobuf/runtime/protoimpl
# gopkg.in/auth0.v5 v5.8.0 => github.com/go-auth0/auth0 v1.3.1-0.20210126164439-7451a183abbd
# gopkg.in/auth0.v5 v5.8.0 => github.com/go-auth0/auth0 v1.3.1-0.20210127020221-38fd79682c4a
## explicit
gopkg.in/auth0.v5
gopkg.in/auth0.v5/internal/client
Expand All @@ -145,4 +145,4 @@ gopkg.in/auth0.v5/management
# gopkg.in/yaml.v2 v2.2.8
## explicit
gopkg.in/yaml.v2
# gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210126164439-7451a183abbd
# gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210127020221-38fd79682c4a