Skip to content

Commit

Permalink
feat: actions triggers show (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
turcottedanny authored Jan 26, 2021
1 parent 521a47a commit 2e2020e
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 5 deletions.
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
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 @@ -158,10 +157,8 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
Expand Down Expand Up @@ -486,7 +483,6 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
Expand Down
4 changes: 4 additions & 0 deletions internal/auth0/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ type ActionVersionAPI interface {
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)
}
2 changes: 2 additions & 0 deletions internal/auth0/auth0.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type API struct {
Action ActionAPI
ActionVersion ActionVersionAPI
ActionBinding ActionBindingAPI
Client ClientAPI
Connection ConnectionAPI
Log LogAPI
Expand All @@ -21,6 +22,7 @@ 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
50 changes: 49 additions & 1 deletion internal/cli/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ func actionsCmd(cli *cli) *cobra.Command {
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 action triggers.",
}

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

return cmd
}
Expand Down Expand Up @@ -75,7 +88,7 @@ func testActionCmd(cli *cli) *cobra.Command {
return err
}

if err := json.Unmarshal([]byte(byteValue), &payload); err != nil {
if err := json.Unmarshal(byteValue, &payload); err != nil {
return err
}

Expand Down Expand Up @@ -159,3 +172,38 @@ 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
}
28 changes: 28 additions & 0 deletions internal/display/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ func (v *actionView) AsTableRow() []string {
return []string{v.ID, v.Name, v.Type, v.CreatedAt}
}

type triggerView struct {
ActionID string
DisplayName string
}

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

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

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

Expand Down Expand Up @@ -68,3 +81,18 @@ 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{
ActionID: auth0.StringValue(b.Action.ID),
DisplayName: auth0.StringValue(b.DisplayName),
})

}

r.Results(res)
}

0 comments on commit 2e2020e

Please sign in to comment.