Skip to content

Commit

Permalink
add actions create, bump go-auth/auth0, mod tidy && mod vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
iamjem committed Jan 25, 2021
1 parent 0d36b7d commit 3fe0b13
Show file tree
Hide file tree
Showing 50 changed files with 111 additions and 37,685 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/olekukonko/tablewriter v0.0.4
github.com/spf13/afero v1.2.2
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.5.1
Expand All @@ -21,4 +20,4 @@ require (
)

// replace gopkg.in/auth0.v5 => ../auth0
replace gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210125191543-690e086040a7
replace gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210125203113-388ed60f4d87
6 changes: 2 additions & 4 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.20210125191543-690e086040a7 h1:6kaJtttAsJDTFy0RD2RVPw1DadgzDBiSbrsfTOSBjfI=
github.com/go-auth0/auth0 v1.3.1-0.20210125191543-690e086040a7/go.mod h1:pbIRmwBulkHNKKsUGGvhyIOI2itMhz2OfwtPaFXBSSQ=
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-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 @@ -204,8 +204,6 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
Expand Down
61 changes: 61 additions & 0 deletions internal/cli/actions.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package cli

import (
"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/validators"
"github.com/spf13/cobra"
"gopkg.in/auth0.v5"
"gopkg.in/auth0.v5/management"
)

func actionsCmd(cli *cli) *cobra.Command {
Expand All @@ -12,6 +16,7 @@ func actionsCmd(cli *cli) *cobra.Command {

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

return cmd
}
Expand All @@ -38,3 +43,59 @@ Lists your existing actions. To create one try:

return cmd
}

func createActionCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: "Creates a new action",
Long: `$ auth0 actions list
Lists your existing actions. To create one try:
$ auth0 actions create my-action --trigger post-login
`,
Args: func(cmd *cobra.Command, args []string) error {
if err := validators.ExactArgs("name")(cmd, args); err != nil {
return err
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
trigger, err := cmd.LocalFlags().GetString("trigger")
if err != nil {
return err
}

if err := validators.TriggerID(trigger); err != nil {
return err
}

triggerID := management.TriggerID(trigger)
triggers := []management.Trigger{
{
ID: &triggerID,
Version: auth0.String("v1"),
},
}

action := &management.Action{
Name: auth0.String(args[0]),
SupportedTriggers: &triggers,
}

err = ansi.Spinner("Creating action", func() error {
return cli.api.Action.Create(action)
})

if err != nil {
return err
}

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

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

return cmd
}
18 changes: 18 additions & 0 deletions internal/display/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,21 @@ func (r *Renderer) ActionList(actions []*management.Action) {

r.Results(res)
}

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

var triggers = make([]string, 0, len(*action.SupportedTriggers))
for _, t := range *action.SupportedTriggers {
triggers = append(triggers, string(*t.ID))
}

v := &actionView{
ID: auth0.StringValue(action.ID),
Name: auth0.StringValue(action.Name),
CreatedAt: timeAgo(auth0.TimeValue(action.CreatedAt)),
Type: strings.Join(triggers, ", "),
}

r.Results([]View{v})
}
26 changes: 26 additions & 0 deletions internal/validators/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package validators

import (
"fmt"
"strings"

"gopkg.in/auth0.v5/management"
)

// TriggerID checks that the provided trigger is valid.
func TriggerID(trigger string) error {
allTriggerIDs := []string{
string(management.PostLogin),
string(management.ClientCredentials),
string(management.PreUserRegistration),
string(management.PostUserRegistration),
}

for _, id := range allTriggerIDs {
if trigger == id {
return nil
}
}

return fmt.Errorf("%s is not a valid trigger type (%s)", trigger, strings.Join(allTriggerIDs, ", "))
}
21 changes: 0 additions & 21 deletions vendor/github.com/spf13/afero/.travis.yml

This file was deleted.

174 changes: 0 additions & 174 deletions vendor/github.com/spf13/afero/LICENSE.txt

This file was deleted.

Loading

0 comments on commit 3fe0b13

Please sign in to comment.