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, )
| 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. |
| 726 | func 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 | } |
no test coverage detected