Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DXCDT-590: Interactive custom text prompt selector #913

Merged
merged 5 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading