pickOrganizationForGrantIfRequired checks if the client grant for the given audience requires an organization. If it does and no organization has been specified, it either fails with a descriptive error (if no organizations exist on the tenant) or opens an interactive picker to let the user select o
(cmd *cobra.Command, client *management.Client, audience string, organization *string)
| 485 | // specified, it either fails with a descriptive error (if no organizations exist |
| 486 | // on the tenant) or opens an interactive picker to let the user select one. |
| 487 | func (c *cli) pickOrganizationForGrantIfRequired(cmd *cobra.Command, client *management.Client, audience string, organization *string) error { |
| 488 | if *organization != "" { |
| 489 | return nil |
| 490 | } |
| 491 | |
| 492 | var list *management.ClientGrantList |
| 493 | if err := ansi.Waiting(func() (err error) { |
| 494 | list, err = c.api.ClientGrant.List( |
| 495 | cmd.Context(), |
| 496 | management.Parameter("audience", audience), |
| 497 | management.Parameter("client_id", client.GetClientID()), |
| 498 | ) |
| 499 | return err |
| 500 | }); err != nil { |
| 501 | return err |
| 502 | } |
| 503 | |
| 504 | if len(list.ClientGrants) == 0 || list.ClientGrants[0].GetOrganizationUsage() != "require" { |
| 505 | return nil |
| 506 | } |
| 507 | |
| 508 | return testOrganization.Pick(cmd, organization, c.organizationPickerOptionsForGrant(audience)) |
| 509 | } |
| 510 | |
| 511 | func (c *cli) organizationPickerOptionsForGrant(audience string) pickerOptionsFunc { |
| 512 | return func(ctx context.Context) (pickerOptions, error) { |
no test coverage detected