Skip to content

Commit

Permalink
Convert audience into a drop down in interactive mode in test token cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Nov 10, 2023
1 parent ff1bd0a commit 350ae79
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion internal/cli/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func testTokenCmd(cli *cli) *cobra.Command {
return err
}

if err := testAudience.Ask(cmd, &inputs.Audience, nil); err != nil {
if err := testAudienceRequired.Pick(cmd, &inputs.Audience, cli.audiencePickerOptions); err != nil {
return err
}

Expand Down Expand Up @@ -342,6 +342,33 @@ func (c *cli) appPickerWithCreateOption(ctx context.Context) (pickerOptions, err
return enhancedOptions, nil
}

func (c *cli) audiencePickerOptions(ctx context.Context) (pickerOptions, error) {
resourceServerList, err := c.api.ResourceServer.List(ctx, management.PerPage(100))
if err != nil {
return nil, err
}

var opts pickerOptions
for _, resourceServer := range resourceServerList.ResourceServers {
label := fmt.Sprintf(
"%s %s",
resourceServer.GetName(),
ansi.Faint(fmt.Sprintf("(%s)", resourceServer.GetIdentifier())),
)

opts = append(opts, pickerOption{
label: label,
value: resourceServer.GetIdentifier(),
})
}

if len(opts) == 0 {
return nil, fmt.Errorf("no APIs found on the tenant")
}

return opts, nil
}

func checkClientIsAuthorizedForAPI(ctx context.Context, cli *cli, client *management.Client, audience string) error {
var list *management.ClientGrantList
if err := ansi.Waiting(func() (err error) {
Expand Down

0 comments on commit 350ae79

Please sign in to comment.