From 8b01134ba3a32e16aba9e091364f98f9c2d76db0 Mon Sep 17 00:00:00 2001 From: Danny Turcotte Date: Tue, 26 Jan 2021 16:46:23 -0500 Subject: [PATCH 1/5] add deploy and list for versions --- internal/auth0/actions.go | 2 ++ internal/cli/actions.go | 70 +++++++++++++++++++++++++++++++++++-- internal/display/actions.go | 48 +++++++++++++++++++++++-- 3 files changed, 116 insertions(+), 4 deletions(-) diff --git a/internal/auth0/actions.go b/internal/auth0/actions.go index b7fdf155a..9285655d6 100644 --- a/internal/auth0/actions.go +++ b/internal/auth0/actions.go @@ -16,7 +16,9 @@ type ActionVersionAPI interface { Read(actionID string, id string) (*management.ActionVersion, error) Update(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) + Promote(actionID string, id string) (*management.ActionVersion, error) } type ActionBindingAPI interface { diff --git a/internal/cli/actions.go b/internal/cli/actions.go index 9fd2a3d29..b4ddedd86 100644 --- a/internal/cli/actions.go +++ b/internal/cli/actions.go @@ -23,6 +23,8 @@ func actionsCmd(cli *cli) *cobra.Command { cmd.AddCommand(listActionsCmd(cli)) cmd.AddCommand(testActionCmd(cli)) cmd.AddCommand(createActionCmd(cli)) + cmd.AddCommand(promoteActionCmd(cli)) + cmd.AddCommand(listActionVersionsCmd(cli)) cmd.AddCommand(triggersCmd(cli)) return cmd @@ -127,6 +129,70 @@ func testActionCmd(cli *cli) *cobra.Command { return cmd } +func promoteActionCmd(cli *cli) *cobra.Command { + var actionId string + var versionId string + + cmd := &cobra.Command{ + Use: "promote", + Short: "Deploys the action version", + Long: `$ auth0 actions promote --name --version `, + RunE: func(cmd *cobra.Command, args []string) error { + var version *management.ActionVersion + err := ansi.Spinner(fmt.Sprintf("Promoting action: %s, version: %s", actionId, versionId), func() (err error) { + version, err = cli.api.ActionVersion.Promote(actionId, versionId) + return err + }) + + if err != nil { + return err + } + + cli.renderer.ActionVersion(version) + + return nil + }, + } + + cmd.Flags().StringVar(&actionId, "name", "", "Action ID to to test") + cmd.Flags().StringVarP(&versionId, "version", "v", "draft", "Version ID of the action to test") + + 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 `, + 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", @@ -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 } diff --git a/internal/display/actions.go b/internal/display/actions.go index 95dab9588..fc7661e76 100644 --- a/internal/display/actions.go +++ b/internal/display/actions.go @@ -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") @@ -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 { @@ -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) +} From 9c869a041e40d47ff22167e24c3e7e2230b9c41f Mon Sep 17 00:00:00 2001 From: Danny Turcotte Date: Tue, 26 Jan 2021 16:46:43 -0500 Subject: [PATCH 2/5] vendora --- go.mod | 2 +- go.sum | 2 ++ vendor/gopkg.in/auth0.v5/management/actions.go | 5 ++--- vendor/modules.txt | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index a319133a2..2af69fa19 100644 --- a/go.mod +++ b/go.mod @@ -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.20210126214458-2807092480f8 diff --git a/go.sum b/go.sum index a6df28f61..2a889f89a 100644 --- a/go.sum +++ b/go.sum @@ -86,6 +86,8 @@ 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-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= diff --git a/vendor/gopkg.in/auth0.v5/management/actions.go b/vendor/gopkg.in/auth0.v5/management/actions.go index 0a15e9c48..8102a0eb0 100644 --- a/vendor/gopkg.in/auth0.v5/management/actions.go +++ b/vendor/gopkg.in/auth0.v5/management/actions.go @@ -152,8 +152,7 @@ func (m *ActionVersionManager) Create(actionID string, v *ActionVersion) error { return m.Request("POST", m.URI("actions", "actions", actionID, "versions"), v) } -// TODO(cyx): This isn't implemented yet. -func (m *ActionVersionManager) Update(actionID string, v *ActionVersion) error { +func (m *ActionVersionManager) UpsertDraft(actionID string, v *ActionVersion) error { return m.Request("PATCH", m.URI("actions", "actions", actionID, "versions", "draft"), v) } @@ -176,7 +175,7 @@ func (m *ActionVersionManager) List(actionID string, opts ...RequestOption) (c * // name. func (m *ActionVersionManager) Promote(actionID, id string) (*ActionVersion, error) { var v ActionVersion - err := m.Request("POST", m.URI("actions", "actions", actionID, "versions", id, "promote"), &v) + err := m.Request("POST", m.URI("actions", "actions", actionID, "versions", id, "deploy"), &v) return &v, err } diff --git a/vendor/modules.txt b/vendor/modules.txt index c8b024940..7fe02f1f9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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.20210126214458-2807092480f8 ## explicit gopkg.in/auth0.v5 gopkg.in/auth0.v5/internal/client @@ -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.20210126214458-2807092480f8 From b1559f78ab017ba4eca2600d5ed8bd162502a6b7 Mon Sep 17 00:00:00 2001 From: Danny Turcotte Date: Tue, 26 Jan 2021 17:01:14 -0500 Subject: [PATCH 3/5] fix after vendor updates --- internal/auth0/actions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/auth0/actions.go b/internal/auth0/actions.go index 9285655d6..eb8cd1d5f 100644 --- a/internal/auth0/actions.go +++ b/internal/auth0/actions.go @@ -14,7 +14,7 @@ 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) From d4566e5d7eefa50871da8501825ffffd82749bb9 Mon Sep 17 00:00:00 2001 From: Danny Turcotte Date: Tue, 26 Jan 2021 21:03:30 -0500 Subject: [PATCH 4/5] replace promote by deploy --- internal/auth0/actions.go | 2 +- internal/cli/actions.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/auth0/actions.go b/internal/auth0/actions.go index eb8cd1d5f..53cf3b3f1 100644 --- a/internal/auth0/actions.go +++ b/internal/auth0/actions.go @@ -18,7 +18,7 @@ type ActionVersionAPI interface { 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) - Promote(actionID string, id string) (*management.ActionVersion, error) + Deploy(actionID string, id string) (*management.ActionVersion, error) } type ActionBindingAPI interface { diff --git a/internal/cli/actions.go b/internal/cli/actions.go index b4ddedd86..86570915f 100644 --- a/internal/cli/actions.go +++ b/internal/cli/actions.go @@ -23,7 +23,7 @@ func actionsCmd(cli *cli) *cobra.Command { cmd.AddCommand(listActionsCmd(cli)) cmd.AddCommand(testActionCmd(cli)) cmd.AddCommand(createActionCmd(cli)) - cmd.AddCommand(promoteActionCmd(cli)) + cmd.AddCommand(deployActionCmd(cli)) cmd.AddCommand(listActionVersionsCmd(cli)) cmd.AddCommand(triggersCmd(cli)) @@ -129,18 +129,18 @@ func testActionCmd(cli *cli) *cobra.Command { return cmd } -func promoteActionCmd(cli *cli) *cobra.Command { +func deployActionCmd(cli *cli) *cobra.Command { var actionId string var versionId string cmd := &cobra.Command{ - Use: "promote", + Use: "deploy", Short: "Deploys the action version", - Long: `$ auth0 actions promote --name --version `, + Long: `$ auth0 actions deploy --name --version `, RunE: func(cmd *cobra.Command, args []string) error { var version *management.ActionVersion - err := ansi.Spinner(fmt.Sprintf("Promoting action: %s, version: %s", actionId, versionId), func() (err error) { - version, err = cli.api.ActionVersion.Promote(actionId, versionId) + 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 }) @@ -154,8 +154,8 @@ func promoteActionCmd(cli *cli) *cobra.Command { }, } - cmd.Flags().StringVar(&actionId, "name", "", "Action ID to to test") - cmd.Flags().StringVarP(&versionId, "version", "v", "draft", "Version ID of the action to test") + 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") From a06ad49df77c853575f23d744060ddbabd0a387f Mon Sep 17 00:00:00 2001 From: Danny Turcotte Date: Tue, 26 Jan 2021 21:03:56 -0500 Subject: [PATCH 5/5] vendors --- go.mod | 2 +- go.sum | 2 ++ vendor/gopkg.in/auth0.v5/management/actions.go | 2 +- vendor/modules.txt | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 2af69fa19..a2227f9bf 100644 --- a/go.mod +++ b/go.mod @@ -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.20210126214458-2807092480f8 +replace gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210127020221-38fd79682c4a diff --git a/go.sum b/go.sum index 2a889f89a..8976485cb 100644 --- a/go.sum +++ b/go.sum @@ -88,6 +88,8 @@ github.com/go-auth0/auth0 v1.3.1-0.20210126164439-7451a183abbd h1:O1ZCQlPODGWJND 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= diff --git a/vendor/gopkg.in/auth0.v5/management/actions.go b/vendor/gopkg.in/auth0.v5/management/actions.go index 8102a0eb0..20daa8d33 100644 --- a/vendor/gopkg.in/auth0.v5/management/actions.go +++ b/vendor/gopkg.in/auth0.v5/management/actions.go @@ -173,7 +173,7 @@ func (m *ActionVersionManager) List(actionID string, opts ...RequestOption) (c * // TODO(cyx): might call this `activate` instead later. Still fleshing out the // name. -func (m *ActionVersionManager) Promote(actionID, id string) (*ActionVersion, error) { +func (m *ActionVersionManager) Deploy(actionID, id string) (*ActionVersion, error) { var v ActionVersion err := m.Request("POST", m.URI("actions", "actions", actionID, "versions", id, "deploy"), &v) return &v, err diff --git a/vendor/modules.txt b/vendor/modules.txt index 7fe02f1f9..ac38caa2f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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.20210126214458-2807092480f8 +# 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 @@ -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.20210126214458-2807092480f8 +# gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210127020221-38fd79682c4a