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

Function collectAPIInputs

internal/cli/quickstarts.go:822–874  ·  view source on GitHub ↗
(cmd *cobra.Command, cli *cli, inputs *SetupInputs)

Source from the content-addressed store, hash-verified

820}
821
822func collectAPIInputs(cmd *cobra.Command, cli *cli, inputs *SetupInputs) error {
823 // Identifier.
824 if !setupIdentifier.IsSet(cmd) {
825 defaultID := inputs.Identifier
826 if defaultID == "" && inputs.Name != "" {
827 slug := strings.ToLower(strings.ReplaceAll(inputs.Name, " ", "-"))
828 defaultID = "https://" + slug
829 }
830 inputs.Identifier = defaultID
831 if err := setupIdentifier.Ask(cmd, &inputs.Identifier, &defaultID); err != nil {
832 return fmt.Errorf("failed to enter API identifier: %w", err)
833 }
834 }
835 if inputs.Identifier == "" {
836 return fmt.Errorf("API identifier cannot be empty: use --identifier flag")
837 }
838 if err := validateAPIIdentifier(inputs.Identifier); err != nil {
839 return err
840 }
841
842 // Fail fast if the (possibly user-overridden) identifier is already taken — avoids creating an orphaned app.
843 if _, err := cli.api.ResourceServer.Read(cmd.Context(), url.PathEscape(inputs.Identifier)); err == nil {
844 return fmt.Errorf("an API with identifier %q already exists; use a different identifier or delete the existing API first", inputs.Identifier)
845 }
846
847 // Token lifetime.
848 if inputs.TokenLifetime == "" {
849 defaultLifetime := strconv.Itoa(apiDefaultTokenLifetime)
850 inputs.TokenLifetime = defaultLifetime
851 if err := setupTokenLifetime.Ask(cmd, &inputs.TokenLifetime, &defaultLifetime); err != nil {
852 return fmt.Errorf("failed to enter token lifetime: %w", err)
853 }
854 if inputs.TokenLifetime == "" {
855 cli.renderer.Warnf("Token lifetime left blank; using default %d seconds (24 hours)", apiDefaultTokenLifetime)
856 inputs.TokenLifetime = strconv.Itoa(apiDefaultTokenLifetime)
857 }
858 }
859
860 // Signing algorithm.
861 if inputs.SigningAlg == "" {
862 signingAlgs := []string{"RS256", "PS256", "HS256"}
863 defaultAlg := "RS256"
864 inputs.SigningAlg = defaultAlg
865 if err := setupSigningAlg.Select(cmd, &inputs.SigningAlg, signingAlgs, &defaultAlg); err != nil {
866 return fmt.Errorf("failed to select signing algorithm: %w", err)
867 }
868 }
869 if alg := inputs.SigningAlg; alg != "RS256" && alg != "PS256" && alg != "HS256" {
870 return fmt.Errorf("invalid signing algorithm %q: must be RS256, PS256, or HS256", alg)
871 }
872
873 return nil
874}
875
876// handleProjectDetection runs project auto-detection for app flows and reconciles
877// the detected values with explicit flags.

Callers 1

runSetupQuickstartFunction · 0.85

Calls 7

validateAPIIdentifierFunction · 0.85
IsSetMethod · 0.80
ErrorfMethod · 0.80
WarnfMethod · 0.80
SelectMethod · 0.80
ReadMethod · 0.65
AskMethod · 0.45

Tested by

no test coverage detected