Skip to content

Commit

Permalink
DXCDT-590: Interactive custom text prompt selector (#913)
Browse files Browse the repository at this point in the history
* Adding interactive prompts selection to show and update command

* brining back showPromptsText function

* Fixing linting error

---------

Co-authored-by: Will Vedder <will.vedder@okta.com>
  • Loading branch information
willvedd and willvedd authored Nov 16, 2023
1 parent a3454d3 commit ff7566f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
36 changes: 31 additions & 5 deletions internal/cli/prompts_custom_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ var (
Help: "Text contents for the branding.",
IsRequired: true,
}

customTextPrompt = Argument{
Name: "Prompt",
Help: "ID of custom text prompt.",
}
)

type promptsTextInput struct {
Expand All @@ -59,18 +64,27 @@ func universalLoginPromptsTextCmd(cli *cli) *cobra.Command {
return cmd
}

func customTextPromptOptions(_ context.Context) (pickerOptions, error) {
var opts pickerOptions
for _, promptType := range customTextPromptTypes {
opts = append(opts, pickerOption{value: promptType, label: promptType})
}
return opts, nil
}

func showPromptsTextCmd(cli *cli) *cobra.Command {
var inputs promptsTextInput

cmd := &cobra.Command{
Use: "show",
Args: cobra.ExactArgs(1),
Args: cobra.MaximumNArgs(1),
Short: "Show the custom text for a prompt",
Long: "Show the custom text for a prompt.",
Example: ` auth0 universal-login prompts show <prompt>
auth0 universal-login prompts show <prompt> --language <language>
auth0 ul prompts show <prompt> -l <language>
auth0 ul prompts show signup -l es`,

RunE: showPromptsText(cli, &inputs),
}

Expand All @@ -84,7 +98,7 @@ func updatePromptsTextCmd(cli *cli) *cobra.Command {

cmd := &cobra.Command{
Use: "update",
Args: cobra.ExactArgs(1),
Args: cobra.MaximumNArgs(1),
Short: "Update the custom text for a prompt",
Long: "Update the custom text for a prompt.",
Example: ` auth0 universal-login prompts update <prompt>
Expand All @@ -100,9 +114,15 @@ func updatePromptsTextCmd(cli *cli) *cobra.Command {

func showPromptsText(cli *cli, inputs *promptsTextInput) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
inputs.Prompt = args[0]
brandingText := make(map[string]interface{})
if len(args) == 0 {
if err := customTextPrompt.Pick(cmd, &inputs.Prompt, customTextPromptOptions); err != nil {
return err
}
} else {
inputs.Prompt = args[0]
}

brandingText := make(map[string]interface{})
if err := ansi.Waiting(func() (err error) {
brandingText, err = cli.api.Prompt.CustomText(cmd.Context(), inputs.Prompt, inputs.Language)
return err
Expand All @@ -128,7 +148,13 @@ func showPromptsText(cli *cli, inputs *promptsTextInput) func(cmd *cobra.Command

func updateBrandingText(cli *cli, inputs *promptsTextInput) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
inputs.Prompt = args[0]
if len(args) == 0 {
if err := customTextPrompt.Pick(cmd, &inputs.Prompt, customTextPromptOptions); err != nil {
return err
}
} else {
inputs.Prompt = args[0]
}
inputs.Body = string(iostream.PipedInput())

brandingTextToEdit, err := fetchBrandingTextContentToEdit(cmd.Context(), cli, inputs)
Expand Down
5 changes: 3 additions & 2 deletions internal/cli/terraform_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,17 @@ func (f *promptResourceFetcher) FetchData(_ context.Context) (importDataList, er
}, nil
}

var customTextPromptTypes = []string{"login", "login-id", "login-password", "login-email-verification", "signup", "signup-id", "signup-password", "reset-password", "consent", "mfa-push", "mfa-otp", "mfa-voice", "mfa-phone", "mfa-webauthn", "mfa-sms", "mfa-email", "mfa-recovery-code", "mfa", "status", "device-flow", "email-verification", "email-otp-challenge", "organizations", "invitation", "common"}

func (f *promptCustomTextResourceFetcherResourceFetcher) FetchData(ctx context.Context) (importDataList, error) {
tenant, err := f.api.Tenant.Read(ctx)
if err != nil {
return nil, err
}
promptTypes := []string{"login", "login-id", "login-password", "login-email-verification", "signup", "signup-id", "signup-password", "reset-password", "consent", "mfa-push", "mfa-otp", "mfa-voice", "mfa-phone", "mfa-webauthn", "mfa-sms", "mfa-email", "mfa-recovery-code", "mfa", "status", "device-flow", "email-verification", "email-otp-challenge", "organizations", "invitation", "common"}

var data importDataList
for _, language := range tenant.GetEnabledLocales() {
for _, promptType := range promptTypes {
for _, promptType := range customTextPromptTypes {
data = append(data, importDataItem{
ResourceName: "auth0_prompt_custom_text." + sanitizeResourceName(language+"_"+promptType),
ImportID: promptType + "::" + language,
Expand Down

0 comments on commit ff7566f

Please sign in to comment.