MCPcopy Create free account
hub / github.com/auth0/auth0-cli / resolveAPIAppLink

Function resolveAPIAppLink

internal/cli/quickstarts.go:726–783  ·  view source on GitHub ↗

resolveAPIAppLink handles the API flow's app-linking decision. It either sets inputs.LinkedAppID (via picker or flag) or flips inputs.App=true so the regular App-creation flow runs and the new client ID is assigned later.

(
	cmd *cobra.Command,
	cli *cli,
	inputs *SetupInputs,
	canPromptFlag bool,
)

Source from the content-addressed store, hash-verified

724// It either sets inputs.LinkedAppID (via picker or flag) or flips inputs.App=true
725// so the regular App-creation flow runs and the new client ID is assigned later.
726func resolveAPIAppLink(
727 cmd *cobra.Command,
728 cli *cli,
729 inputs *SetupInputs,
730 canPromptFlag bool,
731) error {
732 if !inputs.API {
733 return nil
734 }
735
736 // --app and --api both set: create a new app and link it.
737 if inputs.App {
738 return nil
739 }
740
741 // --linked-app-id flag already provided.
742 if inputs.LinkedAppID != "" {
743 return nil
744 }
745
746 if !canPromptFlag {
747 return fmt.Errorf("in --no-input mode with --api, specify --app to create a new app or --linked-app-id <client-id> to link an existing one")
748 }
749
750 const (
751 actionCreateNew = "Create a new app"
752 actionLink = "Link to an existing app"
753 )
754
755 var action string
756 actionQ := prompt.SelectInput(
757 "link-app-action",
758 "How should this API be associated with an app?",
759 "Create a new app to link with the API, or link to an existing one in the tenant.",
760 []string{actionCreateNew, actionLink},
761 actionCreateNew,
762 true,
763 )
764 if err := prompt.AskOne(actionQ, &action); err != nil {
765 return fmt.Errorf("failed to select link action: %w", err)
766 }
767
768 if action == actionCreateNew {
769 inputs.App = true
770 return nil
771 }
772
773 // Link to an existing app via the standard app picker.
774 appPicker := Argument{
775 Name: "Application",
776 Help: "Select an existing application to authorize for this API.",
777 }
778 return appPicker.Pick(
779 cmd,
780 &inputs.LinkedAppID,
781 cli.appPickerOptions(management.Parameter("app_type", "native,spa,regular_web")),
782 )
783}

Callers 1

runSetupQuickstartFunction · 0.85

Calls 5

PickMethod · 0.95
SelectInputFunction · 0.92
AskOneFunction · 0.92
ErrorfMethod · 0.80
appPickerOptionsMethod · 0.80

Tested by

no test coverage detected