From b08f89042810796d5225717fd5e038e3f2d2518c Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 19 Mar 2021 14:55:58 -0300 Subject: [PATCH 1/4] Remove actions commands --- internal/cli/actions.go | 985 ------------------------------------ internal/cli/root.go | 1 - internal/display/actions.go | 200 -------- 3 files changed, 1186 deletions(-) delete mode 100644 internal/cli/actions.go delete mode 100644 internal/display/actions.go diff --git a/internal/cli/actions.go b/internal/cli/actions.go deleted file mode 100644 index bde344eed..000000000 --- a/internal/cli/actions.go +++ /dev/null @@ -1,985 +0,0 @@ -package cli - -import ( - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "os" - - "github.com/auth0/auth0-cli/internal/ansi" - "github.com/auth0/auth0-cli/internal/auth0" - "github.com/auth0/auth0-cli/internal/prompt" - "github.com/auth0/auth0-cli/internal/validators" - "github.com/spf13/cobra" - "gopkg.in/auth0.v5/management" -) - -const ( - actionID = "id" - actionName = "name" - actionVersion = "version" - actionFile = "file" - actionScript = "script" - actionDependency = "dependencies" - actionPath = "path" - actionTrigger = "trigger" -) - -func actionsCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "actions", - Short: "Manage resources for actions", - } - - cmd.SetUsageTemplate(resourceUsageTemplate()) - cmd.AddCommand(listActionsCmd(cli)) - cmd.AddCommand(testActionCmd(cli)) - cmd.AddCommand(createActionCmd(cli)) - cmd.AddCommand(updateActionCmd(cli)) - cmd.AddCommand(deleteActionCmd(cli)) - cmd.AddCommand(deployActionCmd(cli)) - cmd.AddCommand(downloadActionCmd(cli)) - cmd.AddCommand(listActionVersionsCmd(cli)) - cmd.AddCommand(bindActionCmd(cli)) - - cmd.AddCommand(flowsCmd(cli)) - - return cmd -} - -func flowsCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "flows", - Short: "Manages resources for action flows", - } - - cmd.SetUsageTemplate(resourceUsageTemplate()) - cmd.AddCommand(showFlowCmd(cli)) - cmd.AddCommand(updateFlowCmd(cli)) - - return cmd -} - -func listActionsCmd(cli *cli) *cobra.Command { - cmd := &cobra.Command{ - Use: "list", - Short: "List existing actions", - Long: `auth0 actions list -List existing actions. To create one try: - - auth0 actions create -`, - RunE: func(cmd *cobra.Command, args []string) error { - list, err := cli.api.Action.List() - if err != nil { - return err - } - - cli.renderer.ActionList(list.Actions) - return nil - }, - } - - 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(byteValue, out); err != nil { - return err - } - - return nil -} - -func testActionCmd(cli *cli) *cobra.Command { - var inputs struct { - ID string - File string - Version string - } - - var payload = make(management.Object) - - cmd := &cobra.Command{ - Use: "test", - Args: cobra.MaximumNArgs(1), - Short: "Test an action draft against a payload", - Long: `Test an action draft against a payload: - -auth0 actions test --file payload.json`, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - if canPrompt(cmd) { - input := prompt.TextInput(actionID, "Id:", "Action Id to test.", true) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } else { - return errors.New("Please provide an action Id") - } - } else { - inputs.ID = args[0] - } - - if shouldPrompt(cmd, actionFile) { - input := prompt.TextInput(actionFile, "File:", "File containing the payload for the test.", true) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } - - if shouldPrompt(cmd, actionVersion) { - input := prompt.TextInputDefault(actionVersion, "Version Id:", "Version ID of the action to test. Default: draft", "draft", false) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } - - err := readJsonFile(inputs.File, &payload) - if err != nil { - return err - } - - var result management.Object - err = ansi.Spinner(fmt.Sprintf("Testing action: %s, version: %s", inputs.ID, inputs.Version), func() error { - result, err = cli.api.ActionVersion.Test(inputs.ID, inputs.Version, payload) - return err - }) - - if err != nil { - return err - } - - cli.renderer.ActionTest(result) - return nil - }, - } - - cmd.Flags().StringVarP(&inputs.File, actionFile, "f", "", "File containing the payload for the test.") - cmd.Flags().StringVarP(&inputs.Version, actionVersion, "v", "draft", "Version Id of the action to test. Default: draft") - mustRequireFlags(cmd, actionFile) - - return cmd -} - -func deployActionCmd(cli *cli) *cobra.Command { - var inputs struct { - ID string - Version string - } - - cmd := &cobra.Command{ - Use: "deploy", - Args: cobra.MaximumNArgs(1), - Short: "Deploy the action version", - Long: `Deploy the action version: - -auth0 actions deploy --version version-id`, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - if canPrompt(cmd) { - input := prompt.TextInput(actionID, "Id:", "Action Id to deploy.", true) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } else { - return errors.New("Please provide an action Id") - } - } else { - inputs.ID = args[0] - } - - if shouldPrompt(cmd, actionVersion) { - version, err := askVersion(cli, inputs.ID) - if err != nil { - return err - } - inputs.Version = version - } - - var version *management.ActionVersion - err := ansi.Spinner(fmt.Sprintf("Deploying action: %s, version: %s", inputs.ID, inputs.Version), func() (err error) { - version, err = cli.api.ActionVersion.Deploy(inputs.ID, inputs.Version) - return err - }) - - if err != nil { - return err - } - - cli.renderer.ActionVersion(version) - - return nil - }, - } - - cmd.Flags().StringVarP(&inputs.Version, actionVersion, "v", "draft", "Version Id of the action to deploy. Default: draft") - - return cmd -} - -func renderVersionOptionText(v *management.ActionVersion) string { - deployed := "" - - if v.Deployed { - deployed = "[DEPLOYED]" - } - - return fmt.Sprintf("#%d %s %s", v.Number, v.ID, deployed) -} - -func askVersion(cli *cli, actionId string) (string, error) { - // var versionId string - versions, err := cli.api.ActionVersion.List(actionId) - if err != nil { - return "", err - } - - optChoices := make(map[string]string) - options := make([]string, 0) - options = append(options, "Draft") - optChoices["Draft"] = "draft" - - for _, v := range versions.Versions { - optText := renderVersionOptionText(v) - optChoices[optText] = v.ID - options = append(options, optText) - } - - var versionLabel string - if err = prompt.AskOne(prompt.SelectInput("Actions version", "Choose a version", "Select the version number you want to choose for this action", options, true), &versionLabel); err != nil { - return "", err - } - - return optChoices[versionLabel], nil -} - -func downloadActionCmd(cli *cli) *cobra.Command { - var inputs struct { - ID string - Version string - Path string - } - - cmd := &cobra.Command{ - Use: "download", - Args: cobra.MaximumNArgs(1), - Short: "Download an action", - Long: `Download an action: - -auth0 actions download --version `, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - if canPrompt(cmd) { - input := prompt.TextInput(actionID, "Id:", "Action Id to download.", true) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } else { - return errors.New("Please provide an action Id") - } - } else { - inputs.ID = args[0] - } - - if shouldPrompt(cmd, actionVersion) { - version, err := askVersion(cli, inputs.ID) - if err != nil { - return err - } - inputs.Version = version - } - - if shouldPrompt(cmd, actionPath) { - input := prompt.TextInputDefault(actionPath, "Path:", "Path to save the action content.", "./", false) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } - - cli.renderer.Infof("It will overwrite files in %s", inputs.Path) - if confirmed := prompt.Confirm("Do you wish to proceed?"); !confirmed { - return nil - } - - var version *management.ActionVersion - err := ansi.Spinner(fmt.Sprintf("Downloading action: %s, version: %s", inputs.ID, inputs.Version), func() (err error) { - if version, err = cli.api.ActionVersion.Read(inputs.ID, inputs.Version); err != nil { - return err - } - - if version.ID == "" { - version.ID = "draft" - } - return nil - }) - - if err != nil { - return err - } - - cli.renderer.Infof("Code downloaded to %s/code.js", inputs.Path) - - if err := ioutil.WriteFile(inputs.Path+"/code.js", []byte(version.Code), 0644); err != nil { - return err - } - - version.Code = "" - metadata, err := json.MarshalIndent(version, "", " ") - if err != nil { - return err - } - - if err := ioutil.WriteFile(inputs.Path+"/metadata.json", metadata, 0644); err != nil { - return err - } - - return nil - }, - } - - cmd.Flags().StringVarP(&inputs.Version, actionVersion, "v", "draft", "Version ID of the action to download. Default: draft") - cmd.Flags().StringVarP(&inputs.Path, actionPath, "p", "./", "Path to save the action content.") - - return cmd -} - -func listActionVersionsCmd(cli *cli) *cobra.Command { - var inputs struct { - ID string - } - - cmd := &cobra.Command{ - Use: "versions", - Args: cobra.MaximumNArgs(1), - Short: "List the action versions", - Long: `List the action versions: - -auth0 actions versions `, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - if canPrompt(cmd) { - input := prompt.TextInput(actionID, "Id:", "Action Id to show versions.", true) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } else { - return errors.New("Please provide an action Id") - } - } else { - inputs.ID = args[0] - } - - var list *management.ActionVersionList - err := ansi.Spinner(fmt.Sprintf("Loading versions for action: %s", inputs.ID), func() (err error) { - list, err = cli.api.ActionVersion.List(inputs.ID) - return err - }) - - if err != nil { - return err - } - - cli.renderer.ActionVersionList(list.Versions) - - return nil - }, - } - - return cmd -} - -func createActionCmd(cli *cli) *cobra.Command { - var flags struct { - Name string - Trigger string - File string - Script string - Dependency []string - CreateVersion bool - } - - cmd := &cobra.Command{ - Use: "create", - Short: "Create a new action", - Long: `auth0 actions create -Create a new action: - - auth0 actions create --name my-action --trigger post-login --file action.js --dependency lodash@4.17.19 -`, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if shouldPrompt(cmd, actionName) { - input := prompt.TextInput(actionName, "Name:", "Action name to create.", true) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if shouldPrompt(cmd, actionTrigger) { - input := prompt.SelectInput( - actionTrigger, - "Trigger:", - "Trigger type for action.", - validators.ValidTriggerIDs, - false) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - if shouldPrompt(cmd, actionFile) && shouldPrompt(cmd, actionScript) { - input := prompt.TextInput(actionFile, "Action File:", "File containing the action source code.", false) - - if err := prompt.AskOne(input, &flags); err != nil { - return err - } - } - - // TODO: Add prompt for script, dependency and version - - if err := validators.TriggerID(flags.Trigger); err != nil { - return err - } - - source, err := sourceFromFileOrScript(flags.File, flags.Script) - if err != nil { - return err - } - - dependencies, err := validators.Dependencies(flags.Dependency) - if err != nil { - return err - } - - triggerID := management.TriggerID(flags.Trigger) - triggers := []management.Trigger{ - { - ID: &triggerID, - Version: auth0.String("v1"), - }, - } - - action := &management.Action{ - Name: auth0.String(flags.Name), - SupportedTriggers: &triggers, - } - - version := &management.ActionVersion{ - Code: source, - Dependencies: dependencies, - Runtime: "node12", - } - - err = ansi.Spinner("Creating action", func() error { - if err := cli.api.Action.Create(action); err != nil { - return err - } - - created, err := createActionVersion(cli.api, auth0.StringValue(action.ID), !flags.CreateVersion, version) - if err != nil { - return err - } - - version = created - - return nil - }) - - if err != nil { - return err - } - - cli.renderer.ActionVersion(version) - - return nil - }, - } - - cmd.Flags().StringVarP(&flags.Name, actionName, "n", "", "Action name to create.") - cmd.Flags().StringVarP(&flags.Trigger, actionTrigger, "t", string(management.PostLogin), "Trigger type for action.") - cmd.Flags().StringVarP(&flags.File, actionFile, "f", "", "File containing the action source code.") - cmd.Flags().StringVarP(&flags.Script, actionScript, "s", "", "Raw source code for the action.") - cmd.Flags().StringSliceVarP(&flags.Dependency, actionDependency, "d", nil, "Dependency for the source code (@).") - // TODO: This name is kind of overloaded since it could also refer to the version of the trigger (though there's only v1's at this time) - cmd.Flags().BoolVarP(&flags.CreateVersion, actionVersion, "v", false, "Create an explicit action version from the source code instead of a draft.") - - mustRequireFlags(cmd, actionName) - if err := cmd.MarkFlagFilename(actionFile); err != nil { - panic(err) - } - - return cmd -} - -func updateActionCmd(cli *cli) *cobra.Command { - var inputs struct { - ID string - File string - Script string - Dependency []string - CreateVersion bool - } - - cmd := &cobra.Command{ - Use: "update", - Args: cobra.MaximumNArgs(1), - Short: "Updates an existing action", - Long: `Updates an existing action: - -$ auth0 actions update --file action.js --dependency lodash@4.17.19 -`, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - if canPrompt(cmd) { - input := prompt.TextInput(actionID, "Id:", "Id of the action.", true) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } else { - return errors.New("Please provide an action Id") - } - } else { - inputs.ID = args[0] - } - - if shouldPromptWhenFlagless(cmd, actionFile) && shouldPrompt(cmd, actionScript) { - input := prompt.TextInput(actionFile, "Action File:", "File containing the action source code.", false) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } - - source, err := sourceFromFileOrScript(inputs.File, inputs.Script) - if err != nil { - return err - } - - dependencies, err := validators.Dependencies(inputs.Dependency) - if err != nil { - return err - } - - version := &management.ActionVersion{ - Code: source, - Dependencies: dependencies, - Runtime: "node12", - } - - err = ansi.Spinner("Updating action", func() error { - created, err := createActionVersion(cli.api, inputs.ID, !inputs.CreateVersion, version) - if err != nil { - return err - } - - version = created - return nil - }) - - if err != nil { - return err - } - - cli.renderer.ActionVersion(version) - - return nil - }, - } - - cmd.Flags().StringVarP(&inputs.File, actionFile, "f", "", "File containing the action source code.") - cmd.Flags().StringVarP(&inputs.Script, actionScript, "s", "", "Raw source code for the action.") - cmd.Flags().StringSliceVarP(&inputs.Dependency, actionDependency, "d", nil, "Dependency for the source code (@).") - // TODO: This name is kind of overloaded since it could also refer to the version of the trigger (though there's only v1's at this time) - cmd.Flags().BoolVarP(&inputs.CreateVersion, actionVersion, "v", false, "Create an explicit action version from the source code instead of a draft.") - - if err := cmd.MarkFlagFilename(actionFile); err != nil { - fmt.Println(fmt.Errorf("An unexpected error occurred: %w", err)) - } - - return cmd -} - -func deleteActionCmd(cli *cli) *cobra.Command { - var inputs struct { - ID string - } - - cmd := &cobra.Command{ - Use: "delete", - Args: cobra.MaximumNArgs(1), - Short: "Delete an action", - Long: `Delete an action: - -$ auth0 actions delete `, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - if canPrompt(cmd) { - input := prompt.TextInput(actionID, "Id:", "Id of the action.", true) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } else { - return errors.New("Please provide an action Id") - } - } else { - inputs.ID = args[0] - } - - if !cli.force && canPrompt(cmd) { - if confirmed := prompt.Confirm("Are you sure you want to proceed?"); !confirmed { - return nil - } - } - - err := ansi.Spinner("Deleting action", func() error { - return cli.api.Action.Delete(inputs.ID) - }) - - if err != nil { - return err - } - - return nil - }, - } - - return cmd -} - -func showFlowCmd(cli *cli) *cobra.Command { - var inputs struct { - Trigger string - } - - cmd := &cobra.Command{ - Use: "show", - Args: cobra.MaximumNArgs(1), - Short: "Show actions by flow", - Long: `Show a list of actions by flow: - -auth0 actions flows show `, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - if canPrompt(cmd) { - input := prompt.SelectInput( - actionTrigger, - "Trigger:", - "Trigger type for action.", - validators.ValidTriggerIDs, - false) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } else { - return errors.New("Please provide an action trigger") - } - } else { - inputs.Trigger = args[0] - } - - if err := validators.TriggerID(inputs.Trigger); err != nil { - return err - } - - triggerID := management.TriggerID(inputs.Trigger) - - var list *management.ActionBindingList - err := ansi.Spinner("Loading actions", func() (err error) { - list, err = cli.api.ActionBinding.List(triggerID) - return err - }) - - if err != nil { - return err - } - - cli.renderer.ActionTriggersList(list.Bindings) - return nil - }, - } - - return cmd -} - -func updateFlowCmd(cli *cli) *cobra.Command { - var inputs struct { - Trigger string - File string - } - - cmd := &cobra.Command{ - Use: "update", - Args: cobra.MaximumNArgs(1), - Short: "Update actions by flow", - Long: `Update actions by flow: - -auth0 actions flows update --file bindings.json`, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - if canPrompt(cmd) { - input := prompt.SelectInput( - actionTrigger, - "Trigger:", - "Trigger type for action.", - validators.ValidTriggerIDs, - false) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } else { - return errors.New("Please provide an action trigger") - } - } else { - inputs.Trigger = args[0] - } - - if shouldPromptWhenFlagless(cmd, actionFile) { - input := prompt.TextInput(actionFile, "File:", "File containing the bindings.", true) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } - - if err := validators.TriggerID(inputs.Trigger); err != nil { - return err - } - - triggerID := management.TriggerID(inputs.Trigger) - - var list *management.ActionBindingList - err := readJsonFile(inputs.File, &list) - if err != nil { - return err - } - - err = ansi.Spinner("Updating actions", func() (err error) { - if _, err = cli.api.ActionBinding.Update(triggerID, list.Bindings); err != nil { - return err - } - - list, err = cli.api.ActionBinding.List(triggerID) - - return err - }) - - if err != nil { - return err - } - - cli.renderer.ActionTriggersList(list.Bindings) - return nil - }, - } - - cmd.Flags().StringVarP(&inputs.File, actionFile, "f", "", "File containing the bindings.") - mustRequireFlags(cmd, actionFile) - - return cmd -} - -func bindActionCmd(cli *cli) *cobra.Command { - var inputs struct { - ID string - Trigger string - } - - cmd := &cobra.Command{ - Use: "bind", - Args: cobra.MaximumNArgs(1), - Short: "Bind an action to a flow", - Long: `Bind an action to a flow: - -auth0 actions bind --trigger post-login`, - PreRun: func(cmd *cobra.Command, args []string) { - prepareInteractivity(cmd) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - if canPrompt(cmd) { - input := prompt.TextInput(actionID, "Action Id:", "Action Id to bind.", false) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } else { - return errors.New("Please provide an action Id") - } - } else { - inputs.ID = args[0] - } - - if shouldPrompt(cmd, actionTrigger) { - input := prompt.SelectInput( - actionTrigger, - "Trigger:", - "Trigger type for action.", - validators.ValidTriggerIDs, - false) - - if err := prompt.AskOne(input, &inputs); err != nil { - return err - } - } - - if err := validators.TriggerID(inputs.Trigger); err != nil { - return err - } - - triggerID := management.TriggerID(inputs.Trigger) - - var binding *management.ActionBinding - var list *management.ActionBindingList - - err := ansi.Spinner("Adding action", func() (err error) { - var action *management.Action - if action, err = cli.api.Action.Read(inputs.ID); err != nil { - return err - } - - if binding, err = cli.api.ActionBinding.Create(triggerID, action); err != nil { - return err - } - - if list, err = cli.api.ActionBinding.List(triggerID); err != nil { - return err - } - - bindings := append(list.Bindings, binding) - - if _, err = cli.api.ActionBinding.Update(triggerID, bindings); err != nil { - return err - } - - list, err = cli.api.ActionBinding.List(triggerID) - - return err - }) - - if err != nil { - return err - } - - cli.renderer.ActionTriggersList(list.Bindings) - return nil - }, - } - - cmd.Flags().StringVarP(&inputs.Trigger, actionTrigger, "t", string(management.PostLogin), "Trigger type for action.") - - return cmd -} - -var errNoSource = errors.New("please provide source code via --file or --script") - -func sourceFromFileOrScript(file, script string) (string, error) { - if script != "" { - return script, nil - } - - if file != "" { - f, err := os.Open(file) - if err != nil { - return "", err - } - defer f.Close() - - contents, err := ioutil.ReadAll(f) - if err != nil { - return "", err - } - - if len(contents) > 0 { - return string(contents), nil - } - } - - return "", errNoSource -} - -func createActionVersion(api *auth0.API, actionID string, draft bool, version *management.ActionVersion) (*management.ActionVersion, error) { - var v *management.ActionVersion - if draft { - if err := api.ActionVersion.UpsertDraft(actionID, version); err != nil { - return nil, err - } - - // TODO(iamjem): this is a hack since the SDK won't decode 202 responses - draft, err := api.ActionVersion.ReadDraft(actionID) - if err != nil { - return nil, err - } - v = draft - } else { - if err := api.ActionVersion.Create(actionID, version); err != nil { - return nil, err - } - - // TODO(iamjem): this is a hack since the SDK won't decode 202 responses - list, err := api.ActionVersion.List(actionID) - if err != nil { - return nil, err - } - - if len(list.Versions) > 0 { - v = list.Versions[0] - } - } - - return v, nil -} diff --git a/internal/cli/root.go b/internal/cli/root.go index 95819c2d5..30910be74 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -84,7 +84,6 @@ func Execute() { rootCmd.AddCommand(apisCmd(cli)) rootCmd.AddCommand(testCmd(cli)) rootCmd.AddCommand(logsCmd(cli)) - rootCmd.AddCommand(actionsCmd(cli)) rootCmd.AddCommand(logoutCmd(cli)) // keep completion at the bottom: diff --git a/internal/display/actions.go b/internal/display/actions.go deleted file mode 100644 index 8d79eaa2f..000000000 --- a/internal/display/actions.go +++ /dev/null @@ -1,200 +0,0 @@ -package display - -import ( - "fmt" - "strings" - - "github.com/auth0/auth0-cli/internal/ansi" - "github.com/auth0/auth0-cli/internal/auth0" - "gopkg.in/auth0.v5/management" -) - -type actionView struct { - ID string - Name string - CreatedAt string - Type string - raw interface{} -} - -func (v *actionView) AsTableHeader() []string { - return []string{"ID", "Name", "Type", "Created At"} -} - -func (v *actionView) AsTableRow() []string { - return []string{ansi.Faint(v.ID), v.Name, v.Type, v.CreatedAt} -} - -func (v *actionView) KeyValues() [][]string { - return [][]string{ - []string{"ID", ansi.Faint(v.ID)}, - []string{"NAME", v.Name}, - []string{"TYPE", v.Type}, - []string{"CREATED AT", v.CreatedAt}, - } -} - -func (v *actionView) Object() interface{} { - return v.raw -} - -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{ansi.Faint(v.ID), v.ActionID, v.DisplayName} -} - -type actionVersionView struct { - Number string - ID string - ActionID string - ActionName string - Runtime string - Status string - Deployed string - CreatedAt string - - raw interface{} -} - -func (v *actionVersionView) AsTableHeader() []string { - return []string{"Number", "ID", "Action ID", "Action Name", "Runtime", "Status", "Created At", "Deployed"} -} - -func (v *actionVersionView) AsTableRow() []string { - return []string{v.Number, ansi.Faint(v.getID()), v.ActionID, v.ActionName, v.Runtime, v.Status, v.CreatedAt, v.Deployed} -} - -func (v *actionVersionView) KeyValues() [][]string { - return [][]string{ - []string{"Number", v.Number}, - []string{"ID", ansi.Faint(v.getID())}, - []string{"ActionID", v.ActionID}, - []string{"ActionName", v.ActionName}, - []string{"RUNTIME", v.ActionName}, - []string{"STATUS", v.Status}, - []string{"CREATED AT", v.CreatedAt}, - []string{"DEPLOYED", v.Deployed}, - } -} - -func (v *actionVersionView) Object() interface{} { - return v.raw -} - -func (v *actionVersionView) getID() string { - // draft versions don't have a unique id - if v.ID == "" { - return "draft" - } - return v.ID -} - -func (r *Renderer) ActionList(actions []*management.Action) { - r.Heading(ansi.Bold(r.Tenant), "actions\n") - - var res []View - for _, a := range actions { - var triggers = make([]string, 0, len(*a.SupportedTriggers)) - for _, t := range *a.SupportedTriggers { - triggers = append(triggers, string(*t.ID)) - } - - res = append(res, &actionView{ - ID: auth0.StringValue(a.ID), - Name: auth0.StringValue(a.Name), - Type: strings.Join(triggers, ", "), - CreatedAt: timeAgo(auth0.TimeValue(a.CreatedAt)), - raw: a, - }) - - } - - 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) 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 { - 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, ", "), - raw: action, - } - - r.Result(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) -} - -func ActionVersionView(version *management.ActionVersion) *actionVersionView { - deployed := "" - if version.Deployed { - deployed = "✓" - } - - return &actionVersionView{ - Number: fmt.Sprint(version.Number), - ID: version.ID, - ActionID: auth0.StringValue(version.Action.ID), - ActionName: auth0.StringValue(version.Action.Name), - Runtime: auth0.StringValue(&version.Runtime), - Status: string(version.Status), - Deployed: deployed, - CreatedAt: timeAgo(auth0.TimeValue(version.CreatedAt)), - raw: version, - } -} - -func (r *Renderer) ActionVersion(version *management.ActionVersion) { - r.Heading(ansi.Bold(r.Tenant), "action version\n") - - v := ActionVersionView(version) - - r.Result(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(version)) - } - - r.Results(res) -} From ab333e75fe17833bab07cab04c76396d1f1d03d6 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 19 Mar 2021 15:17:38 -0300 Subject: [PATCH 2/4] Remove other action files --- internal/auth0/actions_mock.go | 376 --------------------------------- internal/validators/action.go | 61 ------ 2 files changed, 437 deletions(-) delete mode 100644 internal/auth0/actions_mock.go delete mode 100644 internal/validators/action.go diff --git a/internal/auth0/actions_mock.go b/internal/auth0/actions_mock.go deleted file mode 100644 index 4c19b92d1..000000000 --- a/internal/auth0/actions_mock.go +++ /dev/null @@ -1,376 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: actions.go - -// Package auth0 is a generated GoMock package. -package auth0 - -import ( - gomock "github.com/golang/mock/gomock" - management "gopkg.in/auth0.v5/management" - reflect "reflect" -) - -// MockActionAPI is a mock of ActionAPI interface -type MockActionAPI struct { - ctrl *gomock.Controller - recorder *MockActionAPIMockRecorder -} - -// MockActionAPIMockRecorder is the mock recorder for MockActionAPI -type MockActionAPIMockRecorder struct { - mock *MockActionAPI -} - -// NewMockActionAPI creates a new mock instance -func NewMockActionAPI(ctrl *gomock.Controller) *MockActionAPI { - mock := &MockActionAPI{ctrl: ctrl} - mock.recorder = &MockActionAPIMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockActionAPI) EXPECT() *MockActionAPIMockRecorder { - return m.recorder -} - -// Create mocks base method -func (m *MockActionAPI) Create(a *management.Action) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Create", a) - ret0, _ := ret[0].(error) - return ret0 -} - -// Create indicates an expected call of Create -func (mr *MockActionAPIMockRecorder) Create(a interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockActionAPI)(nil).Create), a) -} - -// Read mocks base method -func (m *MockActionAPI) Read(id string) (*management.Action, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Read", id) - ret0, _ := ret[0].(*management.Action) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Read indicates an expected call of Read -func (mr *MockActionAPIMockRecorder) Read(id interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockActionAPI)(nil).Read), id) -} - -// Update mocks base method -func (m *MockActionAPI) Update(id string, a *management.Action) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Update", id, a) - ret0, _ := ret[0].(error) - return ret0 -} - -// Update indicates an expected call of Update -func (mr *MockActionAPIMockRecorder) Update(id, a interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockActionAPI)(nil).Update), id, a) -} - -// Delete mocks base method -func (m *MockActionAPI) Delete(id string, opts ...management.RequestOption) error { - m.ctrl.T.Helper() - varargs := []interface{}{id} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Delete", varargs...) - ret0, _ := ret[0].(error) - return ret0 -} - -// Delete indicates an expected call of Delete -func (mr *MockActionAPIMockRecorder) Delete(id interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{id}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockActionAPI)(nil).Delete), varargs...) -} - -// List mocks base method -func (m *MockActionAPI) List(opts ...management.RequestOption) (*management.ActionList, error) { - m.ctrl.T.Helper() - varargs := []interface{}{} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "List", varargs...) - ret0, _ := ret[0].(*management.ActionList) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// List indicates an expected call of List -func (mr *MockActionAPIMockRecorder) List(opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockActionAPI)(nil).List), opts...) -} - -// MockActionVersionAPI is a mock of ActionVersionAPI interface -type MockActionVersionAPI struct { - ctrl *gomock.Controller - recorder *MockActionVersionAPIMockRecorder -} - -// MockActionVersionAPIMockRecorder is the mock recorder for MockActionVersionAPI -type MockActionVersionAPIMockRecorder struct { - mock *MockActionVersionAPI -} - -// NewMockActionVersionAPI creates a new mock instance -func NewMockActionVersionAPI(ctrl *gomock.Controller) *MockActionVersionAPI { - mock := &MockActionVersionAPI{ctrl: ctrl} - mock.recorder = &MockActionVersionAPIMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockActionVersionAPI) EXPECT() *MockActionVersionAPIMockRecorder { - return m.recorder -} - -// Create mocks base method -func (m *MockActionVersionAPI) Create(actionID string, v *management.ActionVersion) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Create", actionID, v) - ret0, _ := ret[0].(error) - return ret0 -} - -// Create indicates an expected call of Create -func (mr *MockActionVersionAPIMockRecorder) Create(actionID, v interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockActionVersionAPI)(nil).Create), actionID, v) -} - -// Read mocks base method -func (m *MockActionVersionAPI) Read(actionID, id string) (*management.ActionVersion, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Read", actionID, id) - ret0, _ := ret[0].(*management.ActionVersion) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Read indicates an expected call of Read -func (mr *MockActionVersionAPIMockRecorder) Read(actionID, id interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockActionVersionAPI)(nil).Read), actionID, id) -} - -// UpsertDraft mocks base method -func (m *MockActionVersionAPI) UpsertDraft(actionID string, v *management.ActionVersion) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpsertDraft", actionID, v) - ret0, _ := ret[0].(error) - return ret0 -} - -// UpsertDraft indicates an expected call of UpsertDraft -func (mr *MockActionVersionAPIMockRecorder) UpsertDraft(actionID, v interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsertDraft", reflect.TypeOf((*MockActionVersionAPI)(nil).UpsertDraft), actionID, v) -} - -// ReadDraft mocks base method -func (m *MockActionVersionAPI) ReadDraft(actionID string) (*management.ActionVersion, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ReadDraft", actionID) - ret0, _ := ret[0].(*management.ActionVersion) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ReadDraft indicates an expected call of ReadDraft -func (mr *MockActionVersionAPIMockRecorder) ReadDraft(actionID interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadDraft", reflect.TypeOf((*MockActionVersionAPI)(nil).ReadDraft), actionID) -} - -// Delete mocks base method -func (m *MockActionVersionAPI) Delete(actionID, id string, opts ...management.RequestOption) error { - m.ctrl.T.Helper() - varargs := []interface{}{actionID, id} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Delete", varargs...) - ret0, _ := ret[0].(error) - return ret0 -} - -// Delete indicates an expected call of Delete -func (mr *MockActionVersionAPIMockRecorder) Delete(actionID, id interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{actionID, id}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockActionVersionAPI)(nil).Delete), varargs...) -} - -// List mocks base method -func (m *MockActionVersionAPI) List(actionID string, opts ...management.RequestOption) (*management.ActionVersionList, error) { - m.ctrl.T.Helper() - varargs := []interface{}{actionID} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "List", varargs...) - ret0, _ := ret[0].(*management.ActionVersionList) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// List indicates an expected call of List -func (mr *MockActionVersionAPIMockRecorder) List(actionID interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{actionID}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockActionVersionAPI)(nil).List), varargs...) -} - -// Test mocks base method -func (m *MockActionVersionAPI) Test(actionID, id string, payload management.Object) (management.Object, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Test", actionID, id, payload) - ret0, _ := ret[0].(management.Object) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Test indicates an expected call of Test -func (mr *MockActionVersionAPIMockRecorder) Test(actionID, id, payload interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Test", reflect.TypeOf((*MockActionVersionAPI)(nil).Test), actionID, id, payload) -} - -// Deploy mocks base method -func (m *MockActionVersionAPI) Deploy(actionID, id string) (*management.ActionVersion, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Deploy", actionID, id) - ret0, _ := ret[0].(*management.ActionVersion) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Deploy indicates an expected call of Deploy -func (mr *MockActionVersionAPIMockRecorder) Deploy(actionID, id interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Deploy", reflect.TypeOf((*MockActionVersionAPI)(nil).Deploy), actionID, id) -} - -// MockActionBindingAPI is a mock of ActionBindingAPI interface -type MockActionBindingAPI struct { - ctrl *gomock.Controller - recorder *MockActionBindingAPIMockRecorder -} - -// MockActionBindingAPIMockRecorder is the mock recorder for MockActionBindingAPI -type MockActionBindingAPIMockRecorder struct { - mock *MockActionBindingAPI -} - -// NewMockActionBindingAPI creates a new mock instance -func NewMockActionBindingAPI(ctrl *gomock.Controller) *MockActionBindingAPI { - mock := &MockActionBindingAPI{ctrl: ctrl} - mock.recorder = &MockActionBindingAPIMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockActionBindingAPI) EXPECT() *MockActionBindingAPIMockRecorder { - return m.recorder -} - -// Create mocks base method -func (m *MockActionBindingAPI) Create(triggerID management.TriggerID, action *management.Action) (*management.ActionBinding, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Create", triggerID, action) - ret0, _ := ret[0].(*management.ActionBinding) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Create indicates an expected call of Create -func (mr *MockActionBindingAPIMockRecorder) Create(triggerID, action interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockActionBindingAPI)(nil).Create), triggerID, action) -} - -// List mocks base method -func (m *MockActionBindingAPI) List(triggerID management.TriggerID, opts ...management.RequestOption) (*management.ActionBindingList, error) { - m.ctrl.T.Helper() - varargs := []interface{}{triggerID} - for _, a := range opts { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "List", varargs...) - ret0, _ := ret[0].(*management.ActionBindingList) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// List indicates an expected call of List -func (mr *MockActionBindingAPIMockRecorder) List(triggerID interface{}, opts ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{triggerID}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockActionBindingAPI)(nil).List), varargs...) -} - -// Update mocks base method -func (m *MockActionBindingAPI) Update(triggerID management.TriggerID, v []*management.ActionBinding) (*management.ActionBindingList, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Update", triggerID, v) - ret0, _ := ret[0].(*management.ActionBindingList) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Update indicates an expected call of Update -func (mr *MockActionBindingAPIMockRecorder) Update(triggerID, v interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockActionBindingAPI)(nil).Update), triggerID, v) -} - -// MockActionExecutionAPI is a mock of ActionExecutionAPI interface -type MockActionExecutionAPI struct { - ctrl *gomock.Controller - recorder *MockActionExecutionAPIMockRecorder -} - -// MockActionExecutionAPIMockRecorder is the mock recorder for MockActionExecutionAPI -type MockActionExecutionAPIMockRecorder struct { - mock *MockActionExecutionAPI -} - -// NewMockActionExecutionAPI creates a new mock instance -func NewMockActionExecutionAPI(ctrl *gomock.Controller) *MockActionExecutionAPI { - mock := &MockActionExecutionAPI{ctrl: ctrl} - mock.recorder = &MockActionExecutionAPIMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockActionExecutionAPI) EXPECT() *MockActionExecutionAPIMockRecorder { - return m.recorder -} - -// Read mocks base method -func (m *MockActionExecutionAPI) Read(id string) (*management.ActionExecution, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Read", id) - ret0, _ := ret[0].(*management.ActionExecution) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Read indicates an expected call of Read -func (mr *MockActionExecutionAPIMockRecorder) Read(id interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockActionExecutionAPI)(nil).Read), id) -} diff --git a/internal/validators/action.go b/internal/validators/action.go deleted file mode 100644 index 9e81cef13..000000000 --- a/internal/validators/action.go +++ /dev/null @@ -1,61 +0,0 @@ -package validators - -import ( - "fmt" - "regexp" - "strings" - - "gopkg.in/auth0.v5/management" -) - -var ValidTriggerIDs = []string{ - string(management.PostLogin), - string(management.ClientCredentials), - string(management.PreUserRegistration), - string(management.PostUserRegistration), -} - -// TriggerID checks that the provided trigger is valid. -func TriggerID(trigger string) error { - for _, id := range ValidTriggerIDs { - if trigger == id { - return nil - } - } - - return fmt.Errorf("%s is not a valid trigger type (%s)", trigger, strings.Join(ValidTriggerIDs, ", ")) -} - -var semverRe = regexp.MustCompile(`^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`) - -// Dependencies parses a slice of dependencies of the format @ and returns them in their -// management.Dependency form. -func Dependencies(deps []string) ([]management.Dependency, error) { - dependencies := make([]management.Dependency, 0) - for _, dep := range deps { - name, version, err := splitNameVersion(dep) - if err != nil { - return nil, err - } - dependencies = append(dependencies, management.Dependency{ - Name: name, - Version: version, - }) - } - return dependencies, nil -} - -func splitNameVersion(val string) (string, string, error) { - parts := strings.SplitN(val, "@", 2) - if len(parts) != 2 { - return "", "", fmt.Errorf("dependency %s missing version", val) - } - - name, version := parts[0], parts[1] - - if !semverRe.MatchString(version) { - return "", "", fmt.Errorf("invalid semver %s for dependency %s", name, version) - } - - return name, version, nil -} From f4f898c84e78d89583ef450012950e9ac1423689 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 19 Mar 2021 15:27:42 -0300 Subject: [PATCH 3/4] Remove remaining actions related logic --- internal/auth/auth.go | 1 - internal/auth/auth_test.go | 1 - internal/display/logs.go | 48 +------------------------------------- 3 files changed, 1 insertion(+), 49 deletions(-) diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 2bec08b66..a7e5543e5 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -25,7 +25,6 @@ const ( var requiredScopes = []string{ "openid", "offline_access", // <-- to get a refresh token. - "create:actions", "delete:actions", "read:actions", "update:actions", "create:clients", "delete:clients", "read:clients", "update:clients", "create:resource_servers", "delete:resource_servers", "read:resource_servers", "update:resource_servers", "read:client_keys", "read:logs", diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 8dee1524a..7e50244da 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -5,7 +5,6 @@ import "testing" func TestRequiredScopes(t *testing.T) { t.Run("verify CRUD", func(t *testing.T) { crudResources := []string{ - "actions", "clients", "resource_servers", } diff --git a/internal/display/logs.go b/internal/display/logs.go index 4f4c82f2c..7457b5e17 100644 --- a/internal/display/logs.go +++ b/internal/display/logs.go @@ -37,28 +37,6 @@ func (v *logView) AsTableHeader() []string { return []string{"Type", "Description", "Date", "Connection", "Client"} } -func (v *logView) getActionExecutionID() string { - if v.Details["actions"] == nil { - return "" - } - - actions, ok := v.Details["actions"].(map[string]interface{}) - if ok && actions["executions"] != nil { - execs, ok := actions["executions"].([]interface{}) - if ok { - v, ok := execs[0].(string) - if ok { - return v - } - return "" - } else { - return "" - } - } else { - return "" - } -} - func (v *logView) getConnection() string { if v.Details["prompts"] == nil { return notApplicable @@ -117,31 +95,7 @@ func (v *logView) Extras() []string { } raw, _ := yaml.Marshal(v.Log) - fallback := []string{ansi.Faint(indent(string(raw), "\t"))} - - id := v.getActionExecutionID() - if id == "" { - return fallback - } - - exec, err := v.ActionExecutionAPI.Read(id) - if err != nil { - return fallback - } - - res := []string{ansi.Bold("\t=== ACTION EXECUTIONS:")} - for _, r := range exec.Results { - if r.Response.Error == nil { - res = append(res, ansi.Faint(fmt.Sprintf("\t✓ Action %s logs", auth0.StringValue(r.ActionName)))) - } else { - stack := strings.ReplaceAll(r.Response.Error["stack"], "\n", "\n\t\t") - logs := strings.ReplaceAll(auth0.StringValue(r.Response.Logs), "\n", "\n\t\t") - message := fmt.Sprintf("\t✘ Action %s\n\t\t%s\n\t\t%s\n", auth0.StringValue(r.ActionName), logs, stack) - res = append(res, aurora.BrightRed(message).String()) - } - } - - return []string{strings.Join(res, "\n")} + return []string{ansi.Faint(indent(string(raw), "\t"))} } func (v *logView) category() logCategory { From df1bb2cffa5688db9725a40253094b06c1fe5084 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 19 Mar 2021 16:53:02 -0300 Subject: [PATCH 4/4] Remove unused method --- internal/cli/cli.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 1e2c36e73..9cf7221ea 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -348,14 +348,6 @@ func (c *cli) initContext() (err error) { return nil } -func mustRequireFlags(cmd *cobra.Command, flags ...string) { - for _, f := range flags { - if err := cmd.MarkFlagRequired(f); err != nil { - panic(err) - } - } -} - func canPrompt(cmd *cobra.Command) bool { noInput, err := cmd.Root().Flags().GetBool("no-input")