(cmd *cobra.Command, cli *cli, inputs *SetupInputs)
| 820 | } |
| 821 | |
| 822 | func 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. |
no test coverage detected