From be79eb1d70378f051a9cbdd9bd7491c33e4ebf5b Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Wed, 11 Jan 2023 09:51:25 -0500 Subject: [PATCH 1/4] Disable updating action trigger --- internal/cli/actions.go | 89 ++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 49 deletions(-) diff --git a/internal/cli/actions.go b/internal/cli/actions.go index 278e827af..99b17a294 100644 --- a/internal/cli/actions.go +++ b/internal/cli/actions.go @@ -190,12 +190,18 @@ func createActionCmd(cli *cli) *cobra.Command { return err } - triggers, version, err := latestActionTriggers(cli) + triggers, err := getTriggers(cli) if err != nil { return err } + triggers = filterDeprecatedActionTriggers(triggers) - if err := actionTrigger.Select(cmd, &inputs.Trigger, triggers, nil); err != nil { + triggerIds := make([]string, 0) + for _, t := range triggers { + triggerIds = append(triggerIds, t.GetID()) + } + + if err := actionTrigger.Select(cmd, &inputs.Trigger, triggerIds, nil); err != nil { return err } @@ -212,6 +218,14 @@ func createActionCmd(cli *cli) *cobra.Command { return err } + var version string + for _, t := range triggers { + if t.GetID() == inputs.Trigger { + version = t.GetVersion() + break + } + } + action := &management.Action{ Name: &inputs.Name, SupportedTriggers: []management.ActionTrigger{ @@ -250,7 +264,6 @@ func updateActionCmd(cli *cli) *cobra.Command { var inputs struct { ID string Name string - Trigger string Code string Dependencies map[string]string Secrets map[string]string @@ -262,15 +275,15 @@ func updateActionCmd(cli *cli) *cobra.Command { Short: "Update an action", Long: "Update an action.\n\n" + "To update interactively, use `auth0 actions update` with no arguments.\n\n" + - "To update non-interactively, supply the action id, name, trigger, secrets and " + + "To update non-interactively, supply the action id, name, cod, secrets and " + "dependencies through the flags.", Example: ` auth0 actions update auth0 actions update --name myaction - auth0 actions update --name myaction --trigger post-login - auth0 actions update --name myaction --trigger post-login --code "$(cat path/to/code.js)" - auth0 actions update --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" - auth0 actions update --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --secret "SECRET=value" - auth0 actions update --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --dependency "uuid=9.0.0" --secret "API_KEY=value" --secret "SECRET=value" + auth0 actions update --name myaction + auth0 actions update --name myaction --code "$(cat path/to/code.js)" + auth0 actions update --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" + auth0 actions update --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --secret "SECRET=value" + auth0 actions update --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --dependency "uuid=9.0.0" --secret "API_KEY=value" --secret "SECRET=value" auth0 actions update -n myaction -t post-login -c "$(cat path/to/code.js)" -d "lodash=4.0.0" -d "uuid=9.0.0" -s "API_KEY=value" -s "SECRET=value" --json`, RunE: func(cmd *cobra.Command, args []string) error { if len(args) > 0 { @@ -296,20 +309,6 @@ func updateActionCmd(cli *cli) *cobra.Command { return err } - triggers, version, err := latestActionTriggers(cli) - if err != nil { - return err - } - - var currentTriggerId = "" - if len(current.SupportedTriggers) > 0 { - currentTriggerId = current.SupportedTriggers[0].GetID() - } - - if err := actionTrigger.SelectU(cmd, &inputs.Trigger, triggers, ¤tTriggerId); err != nil { - return err - } - // TODO(cyx): we can re-think this once we have // `--stdin` based commands. For now we don't have // those yet, so keeping this simple. @@ -330,10 +329,6 @@ func updateActionCmd(cli *cli) *cobra.Command { inputs.Name = current.GetName() } - if inputs.Trigger == "" && currentTriggerId != "" { - inputs.Trigger = currentTriggerId - } - if inputs.Code == "" { inputs.Code = current.GetCode() } @@ -342,14 +337,9 @@ func updateActionCmd(cli *cli) *cobra.Command { // re-hydrated by the SDK, which we'll use below during // display. action := &management.Action{ - Name: &inputs.Name, - SupportedTriggers: []management.ActionTrigger{ - { - ID: &inputs.Trigger, - Version: &version, - }, - }, - Code: &inputs.Code, + Name: &inputs.Name, + SupportedTriggers: current.SupportedTriggers, + Code: &inputs.Code, } if len(inputs.Dependencies) == 0 { @@ -377,7 +367,6 @@ func updateActionCmd(cli *cli) *cobra.Command { cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.") actionName.RegisterStringU(cmd, &inputs.Name, "") - actionTrigger.RegisterStringU(cmd, &inputs.Trigger, "") actionCode.RegisterStringU(cmd, &inputs.Code, "") actionDependency.RegisterStringMapU(cmd, &inputs.Dependencies, nil) actionSecret.RegisterStringMapU(cmd, &inputs.Secrets, nil) @@ -557,17 +546,27 @@ func latestActionTriggerVersion(list []*management.ActionTrigger) string { return latestVersion } -func filterActionTriggersByVersion(list []*management.ActionTrigger, version string) []*management.ActionTrigger { +func filterDeprecatedActionTriggers(list []*management.ActionTrigger) []*management.ActionTrigger { + res := []*management.ActionTrigger{} + for _, t := range list { + if t.GetStatus() == "CURRENT" { + res = append(res, t) + } + } + return res +} + +func filterForActionTriggerVersion(list []*management.ActionTrigger, version string) []*management.ActionTrigger { res := []*management.ActionTrigger{} for _, t := range list { - if t.GetVersion() == version && t.GetStatus() == "CURRENT" { + if t.GetVersion() == version { res = append(res, t) } } return res } -func latestActionTriggers(cli *cli) ([]string, string, error) { +func getTriggers(cli *cli) ([]*management.ActionTrigger, error) { var triggers []*management.ActionTrigger if err := ansi.Waiting(func() error { list, err := cli.api.Action.Triggers() @@ -577,17 +576,9 @@ func latestActionTriggers(cli *cli) ([]string, string, error) { triggers = list.Triggers return nil }); err != nil { - return nil, "", err - } - - latestTriggerVersion := latestActionTriggerVersion(triggers) - triggers = filterActionTriggersByVersion(triggers, latestTriggerVersion) - var triggerIds []string - - for _, t := range triggers { - triggerIds = append(triggerIds, t.GetID()) + return nil, err } - return triggerIds, latestTriggerVersion, nil + return triggers, nil } func actionTemplate(key string) string { From 486e2805df6b6b2216f52c9a53e71c7ac27c0b50 Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Wed, 11 Jan 2023 09:54:36 -0500 Subject: [PATCH 2/4] Correcting error message and consolidating logic --- internal/cli/actions.go | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/internal/cli/actions.go b/internal/cli/actions.go index 99b17a294..e3345db32 100644 --- a/internal/cli/actions.go +++ b/internal/cli/actions.go @@ -148,7 +148,7 @@ func showActionCmd(cli *cli) *cobra.Command { action, err = cli.api.Action.Read(inputs.ID) return err }); err != nil { - return fmt.Errorf("Unable to get an action with Id '%s': %w", inputs.ID, err) + return fmt.Errorf("Unable to get an action with ID '%s': %w", inputs.ID, err) } cli.renderer.ActionShow(action) @@ -190,11 +190,10 @@ func createActionCmd(cli *cli) *cobra.Command { return err } - triggers, err := getTriggers(cli) + triggers, err := getCurrentTriggers(cli) if err != nil { return err } - triggers = filterDeprecatedActionTriggers(triggers) triggerIds := make([]string, 0) for _, t := range triggers { @@ -536,16 +535,6 @@ func formatActionDetailsPath(id string) string { return fmt.Sprintf("actions/library/details/%s", id) } -func latestActionTriggerVersion(list []*management.ActionTrigger) string { - latestVersion := "v1" - for _, t := range list { - if t.GetVersion() > latestVersion { - latestVersion = t.GetVersion() - } - } - return latestVersion -} - func filterDeprecatedActionTriggers(list []*management.ActionTrigger) []*management.ActionTrigger { res := []*management.ActionTrigger{} for _, t := range list { @@ -556,17 +545,7 @@ func filterDeprecatedActionTriggers(list []*management.ActionTrigger) []*managem return res } -func filterForActionTriggerVersion(list []*management.ActionTrigger, version string) []*management.ActionTrigger { - res := []*management.ActionTrigger{} - for _, t := range list { - if t.GetVersion() == version { - res = append(res, t) - } - } - return res -} - -func getTriggers(cli *cli) ([]*management.ActionTrigger, error) { +func getCurrentTriggers(cli *cli) ([]*management.ActionTrigger, error) { var triggers []*management.ActionTrigger if err := ansi.Waiting(func() error { list, err := cli.api.Action.Triggers() @@ -578,7 +557,8 @@ func getTriggers(cli *cli) ([]*management.ActionTrigger, error) { }); err != nil { return nil, err } - return triggers, nil + + return filterDeprecatedActionTriggers(triggers), nil } func actionTemplate(key string) string { From f1396988921307f6d0eec20e7f2b26cf1ba0ab96 Mon Sep 17 00:00:00 2001 From: Will Vedder Date: Wed, 11 Jan 2023 10:55:08 -0500 Subject: [PATCH 3/4] Updating docs --- docs/auth0_actions_update.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/auth0_actions_update.md b/docs/auth0_actions_update.md index 08d92ea77..52d547650 100644 --- a/docs/auth0_actions_update.md +++ b/docs/auth0_actions_update.md @@ -7,7 +7,7 @@ Update an action. To update interactively, use `auth0 actions update` with no arguments. -To update non-interactively, supply the action id, name, trigger, secrets and dependencies through the flags. +To update non-interactively, supply the action id, name, cod, secrets and dependencies through the flags. ## Usage ``` @@ -19,11 +19,11 @@ auth0 actions update [flags] ``` auth0 actions update auth0 actions update --name myaction - auth0 actions update --name myaction --trigger post-login - auth0 actions update --name myaction --trigger post-login --code "$(cat path/to/code.js)" - auth0 actions update --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" - auth0 actions update --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --secret "SECRET=value" - auth0 actions update --name myaction --trigger post-login --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --dependency "uuid=9.0.0" --secret "API_KEY=value" --secret "SECRET=value" + auth0 actions update --name myaction + auth0 actions update --name myaction --code "$(cat path/to/code.js)" + auth0 actions update --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" + auth0 actions update --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --secret "SECRET=value" + auth0 actions update --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --dependency "uuid=9.0.0" --secret "API_KEY=value" --secret "SECRET=value" auth0 actions update -n myaction -t post-login -c "$(cat path/to/code.js)" -d "lodash=4.0.0" -d "uuid=9.0.0" -s "API_KEY=value" -s "SECRET=value" --json ``` @@ -36,7 +36,6 @@ auth0 actions update [flags] --json Output in json format. -n, --name string Name of the action. -s, --secret stringToString Secrets to be used in the action. (default []) - -t, --trigger string Trigger of the action. At this time, an action can only target a single trigger at a time. ``` From c3e12bd7a9c95d4dfc699c375ad5d9ddaa9a2fb4 Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea Date: Wed, 11 Jan 2023 19:21:40 +0100 Subject: [PATCH 4/4] Fix typos in docs --- docs/auth0_actions_update.md | 3 +-- internal/cli/actions.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/auth0_actions_update.md b/docs/auth0_actions_update.md index 52d547650..d1e2b63c1 100644 --- a/docs/auth0_actions_update.md +++ b/docs/auth0_actions_update.md @@ -7,7 +7,7 @@ Update an action. To update interactively, use `auth0 actions update` with no arguments. -To update non-interactively, supply the action id, name, cod, secrets and dependencies through the flags. +To update non-interactively, supply the action id, name, code, secrets and dependencies through the flags. ## Usage ``` @@ -19,7 +19,6 @@ auth0 actions update [flags] ``` auth0 actions update auth0 actions update --name myaction - auth0 actions update --name myaction auth0 actions update --name myaction --code "$(cat path/to/code.js)" auth0 actions update --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" auth0 actions update --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --secret "SECRET=value" diff --git a/internal/cli/actions.go b/internal/cli/actions.go index 3dad24303..47ca7e6cb 100644 --- a/internal/cli/actions.go +++ b/internal/cli/actions.go @@ -274,11 +274,10 @@ func updateActionCmd(cli *cli) *cobra.Command { Short: "Update an action", Long: "Update an action.\n\n" + "To update interactively, use `auth0 actions update` with no arguments.\n\n" + - "To update non-interactively, supply the action id, name, cod, secrets and " + + "To update non-interactively, supply the action id, name, code, secrets and " + "dependencies through the flags.", Example: ` auth0 actions update auth0 actions update --name myaction - auth0 actions update --name myaction auth0 actions update --name myaction --code "$(cat path/to/code.js)" auth0 actions update --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" auth0 actions update --name myaction --code "$(cat path/to/code.js)" --dependency "lodash=4.0.0" --secret "SECRET=value"