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

[A0CLI-30] feat: actions triggers reorder #37

Merged
merged 27 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4f132b1
wip working
turcottedanny Jan 25, 2021
162ada0
working output as json
turcottedanny Jan 25, 2021
ea465b6
Improve logging
turcottedanny Jan 26, 2021
62f503f
update go-auth0
turcottedanny Jan 26, 2021
3c1e85d
typos
turcottedanny Jan 26, 2021
b596505
Merge branch 'main' into A0CLI-17-test-action
turcottedanny Jan 26, 2021
8186ffa
cleanup
turcottedanny Jan 26, 2021
1287704
wip list bindings
turcottedanny Jan 26, 2021
18264ed
update vendor
turcottedanny Jan 26, 2021
a41b4cc
working reorder bindings prototype
turcottedanny Jan 26, 2021
36ce917
vendor
turcottedanny Jan 26, 2021
983b0f7
fix
turcottedanny Jan 26, 2021
6d586c4
review fixes
turcottedanny Jan 26, 2021
c02865f
update vendor
turcottedanny Jan 26, 2021
befdcd6
Merge branch 'main' into A0CLI-17-test-action
turcottedanny Jan 26, 2021
b0ab9ff
implement new struct
turcottedanny Jan 26, 2021
4aec6ac
wip list bindings
turcottedanny Jan 26, 2021
9477879
update vendor
turcottedanny Jan 26, 2021
01ba881
implement new api
turcottedanny Jan 26, 2021
13c3fb9
Merge branch 'A0CLI-29-actions-triggers-show' of github.com:auth0/aut…
turcottedanny Jan 26, 2021
183b337
working reorder bindings prototype
turcottedanny Jan 26, 2021
57f8e54
vendor
turcottedanny Jan 26, 2021
5b4af1e
fix
turcottedanny Jan 26, 2021
8516d94
implement new api
turcottedanny Jan 26, 2021
321827c
Merge branch 'A0CLI-30-actions-triggers-reorder' of github.com:auth0/…
turcottedanny Jan 26, 2021
bdc2ec7
Merge branch 'main' into A0CLI-30-actions-triggers-reorder
turcottedanny Jan 26, 2021
03385dd
forgot some merge conflict
turcottedanny Jan 26, 2021
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 @@ -22,4 +22,5 @@ require (
)

// replace gopkg.in/auth0.v5 => ../auth0
replace gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210125203113-388ed60f4d87

replace gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210126044025-c2f94c36f593
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-auth0/auth0 v1.3.1-0.20210125203113-388ed60f4d87 h1:u6DcEF5H9NkexI/ebnZkXj6ZtBJcnQBiOPZG0y0Frao=
github.com/go-auth0/auth0 v1.3.1-0.20210125203113-388ed60f4d87/go.mod h1:pbIRmwBulkHNKKsUGGvhyIOI2itMhz2OfwtPaFXBSSQ=
github.com/go-auth0/auth0 v1.3.1-0.20210126044025-c2f94c36f593 h1:Ty0FV0S+59z1ioKa6uM0WW9i39HgZM46oAtFh++rUHQ=
github.com/go-auth0/auth0 v1.3.1-0.20210126044025-c2f94c36f593/go.mod h1:pbIRmwBulkHNKKsUGGvhyIOI2itMhz2OfwtPaFXBSSQ=
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 Expand Up @@ -124,7 +124,6 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down Expand Up @@ -199,9 +198,7 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand Down Expand Up @@ -358,7 +355,6 @@ golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fq
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
13 changes: 13 additions & 0 deletions internal/auth0/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ type ActionAPI interface {
Delete(id string, opts ...management.RequestOption) error
List(opts ...management.RequestOption) (c *management.ActionList, err error)
}

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
Delete(actionID string, id string, opts ...management.RequestOption) error
Test(actionID string, id string, payload management.Object) (management.Object, error)
}

type ActionBindingAPI interface {
List(triggerID management.TriggerID, opts ...management.RequestOption) (c *management.ActionBindingList, err error)
Update(triggerID management.TriggerID, v *management.ActionBindingList) error
}
4 changes: 4 additions & 0 deletions internal/auth0/auth0.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
// the interfaces instead of the concrete structs.
type API struct {
Action ActionAPI
ActionVersion ActionVersionAPI
ActionBinding ActionBindingAPI
Client ClientAPI
Connection ConnectionAPI
Log LogAPI
Expand All @@ -19,6 +21,8 @@ type API struct {
func NewAPI(m *management.Management) *API {
return &API{
Action: m.Action,
ActionVersion: m.ActionVersion,
ActionBinding: m.ActionBinding,
Client: m.Client,
Connection: m.Connection,
Log: m.Log,
Expand Down
157 changes: 157 additions & 0 deletions internal/cli/actions.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package cli

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/auth0"
"github.com/auth0/auth0-cli/internal/validators"
Expand All @@ -16,7 +21,22 @@ func actionsCmd(cli *cli) *cobra.Command {

cmd.SetUsageTemplate(resourceUsageTemplate())
cmd.AddCommand(listActionsCmd(cli))
cmd.AddCommand(testActionCmd(cli))
cmd.AddCommand(createActionCmd(cli))
cmd.AddCommand(triggersCmd(cli))

return cmd
}

func triggersCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "triggers",
Short: "manage resources for actions triggers.",
}

cmd.SetUsageTemplate(resourceUsageTemplate())
cmd.AddCommand(showTriggerCmd(cli))
cmd.AddCommand(reorderTriggerCmd(cli))

return cmd
}
Expand Down Expand Up @@ -44,6 +64,68 @@ Lists your existing actions. To create one try:
return cmd
}

func readJsonFile(filePath string, out interface{}) error {
// Open our jsonFile
jsonFile, err := os.Open(filePath)
// if we os.Open returns an error then handle it
if err != nil {
return err
}
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()

byteValue, err := ioutil.ReadAll(jsonFile)
if err != nil {
return err
}

if err := json.Unmarshal([]byte(byteValue), &out); err != nil {
turcottedanny marked this conversation as resolved.
Show resolved Hide resolved
return err
}

return nil
}

func testActionCmd(cli *cli) *cobra.Command {
var actionId string
var versionId string
var payloadFile string
var payload = make(management.Object)

cmd := &cobra.Command{
Use: "test",
Short: "Test an action draft against a payload",
Long: `$ auth0 actions test --name <actionid> --file <payload.json>`,
RunE: func(cmd *cobra.Command, args []string) error {
err := readJsonFile(payloadFile, &payload)
if err != nil {
return err
}

var result management.Object
err = ansi.Spinner(fmt.Sprintf("Testing action: %s, version: %s", actionId, versionId), func() error {
result, err = cli.api.ActionVersion.Test(actionId, versionId, payload)
return err
})

if err != nil {
return err
}

cli.renderer.ActionTest(result)
return nil
},
}

cmd.Flags().StringVar(&actionId, "name", "", "Action ID to to test")
cmd.Flags().StringVarP(&payloadFile, "file", "f", "", "File containing the payload for the test")
cmd.Flags().StringVarP(&versionId, "version", "v", "draft", "Version ID of the action to test")

mustRequireFlags(cmd, "name", "file")

return cmd
}

func createActionCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Expand Down Expand Up @@ -99,3 +181,78 @@ Creates a new action:

return cmd
}

func showTriggerCmd(cli *cli) *cobra.Command {
var trigger string

cmd := &cobra.Command{
Use: "show",
Short: "Show actions by trigger",
Long: `$ auth0 actions triggers show --trigger post-login`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := validators.TriggerID(trigger); err != nil {
return err
}

triggerID := management.TriggerID(trigger)

var list *management.ActionBindingList
err := ansi.Spinner("Loading actions", func() error {
var err error
list, err = cli.api.ActionBinding.List(triggerID)
return err
})

if err != nil {
return err
}

cli.renderer.ActionTriggersList(list.Bindings)
return nil
},
}

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

return cmd
}

func reorderTriggerCmd(cli *cli) *cobra.Command {
var trigger string
var bindingsFile string

cmd := &cobra.Command{
Use: "reorder",
Short: "Reorders actions by trigger",
Long: `$ auth0 actions triggers reorder --trigger <post-login> --file <bindings.json>`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := validators.TriggerID(trigger); err != nil {
return err
}

triggerID := management.TriggerID(trigger)

var list *management.ActionBindingList
err := readJsonFile(bindingsFile, &list)
if err != nil {
return err
}

err = ansi.Spinner("Loading actions", func() error {
return cli.api.ActionBinding.Update(triggerID, list)
})

if err != nil {
return err
}

cli.renderer.ActionTriggersList(list.Bindings)
return nil
},
}

cmd.Flags().StringVarP(&trigger, "trigger", "t", string(management.PostLogin), "Trigger type for action.")
cmd.Flags().StringVarP(&bindingsFile, "file", "f", "", "File containing the bindings")

return cmd
}
35 changes: 35 additions & 0 deletions internal/display/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ func (v *actionView) AsTableRow() []string {
return []string{v.ID, v.Name, v.Type, v.CreatedAt}
}

type triggerView struct {
ID string
ActionID string
DisplayName string
}

func (v *triggerView) AsTableHeader() []string {
return []string{"ID", "Action ID", "Action Name"}
}

func (v *triggerView) AsTableRow() []string {
return []string{v.ID, v.ActionID, v.DisplayName}
}

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

Expand All @@ -46,6 +60,11 @@ func (r *Renderer) ActionList(actions []*management.Action) {
r.Results(res)
}

func (r *Renderer) ActionTest(payload management.Object) {
r.Heading(ansi.Bold(r.Tenant), "Actions test result\n")
r.JSONResult(payload)
}

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

Expand All @@ -63,3 +82,19 @@ func (r *Renderer) ActionCreate(action *management.Action) {

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

func (r *Renderer) ActionTriggersList(bindings []*management.ActionBinding) {
r.Heading(ansi.Bold(r.Tenant), "triggers\n")

var res []View
for _, b := range bindings {
res = append(res, &triggerView{
ID: auth0.StringValue(b.ID),
ActionID: auth0.StringValue(b.Action.ID),
DisplayName: auth0.StringValue(b.DisplayName),
})

}

r.Results(res)
}
16 changes: 10 additions & 6 deletions internal/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,20 @@ type View interface {
AsTableRow() []string
}

func (r *Renderer) JSONResult(data interface{}) {
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
r.Errorf("couldn't marshal results as JSON: %v", err)
return
}
fmt.Fprint(r.ResultWriter, string(b))
}

func (r *Renderer) Results(data []View) {
if len(data) > 0 {
switch r.Format {
case OutputFormatJSON:
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
r.Errorf("couldn't marshal results as JSON: %v", err)
return
}
fmt.Fprint(r.ResultWriter, string(b))
r.JSONResult(data)

default:
rows := make([][]string, len(data))
Expand Down
34 changes: 34 additions & 0 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.

Loading