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

Function openAPICmd

internal/cli/apis.go:584–634  ·  view source on GitHub ↗
(cli *cli)

Source from the content-addressed store, hash-verified

582}
583
584func openAPICmd(cli *cli) *cobra.Command {
585 var inputs struct {
586 ID string
587 }
588
589 cmd := &cobra.Command{
590 Use: "open",
591 Args: cobra.MaximumNArgs(1),
592 Short: "Open the settings page of an API",
593 Long: "Open an APIs' settings page in the Auth0 Dashboard.",
594 Example: ` auth0 apis open
595 auth0 apis open <api-id|api-audience>`,
596 RunE: func(cmd *cobra.Command, args []string) error {
597 if len(args) == 0 {
598 err := apiID.Pick(cmd, &inputs.ID, cli.apiPickerOptions)
599 if err != nil {
600 return err
601 }
602 } else {
603 inputs.ID = args[0]
604 }
605
606 // Heuristics to determine if this a valid ID, or an audience value
607 // Audiences are usually URLs, but not necessarily. Whereas IDs have a length of 24
608 // So here if the value is not a URL, we then check if has the length of an ID
609 // If the length check fails, we know it's a non-URL audience value
610 // This will fail for non-URL audience values with the same length as the ID
611 // But it should cover the vast majority of users.
612 if _, err := url.ParseRequestURI(inputs.ID); err == nil || len(inputs.ID) != 24 {
613 if err := ansi.Waiting(func() error {
614 api, err := cli.api.ResourceServer.Read(cmd.Context(), inputs.ID)
615 if err != nil {
616 return err
617 }
618
619 inputs.ID = api.GetID()
620
621 return nil
622 }); err != nil {
623 return fmt.Errorf("failed to read API with ID %q: %w", inputs.ID, err)
624 }
625 }
626
627 openManageURL(cli, cli.Config.DefaultTenant, formatAPISettingsPath(inputs.ID))
628
629 return nil
630 },
631 }
632
633 return cmd
634}
635
636func listScopesCmd(cli *cli) *cobra.Command {
637 var inputs struct {

Callers 1

apisCmdFunction · 0.85

Calls 6

WaitingFunction · 0.92
openManageURLFunction · 0.85
formatAPISettingsPathFunction · 0.85
ErrorfMethod · 0.80
ReadMethod · 0.65
PickMethod · 0.45

Tested by

no test coverage detected