Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/auth0_domains.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ With a custom domain, your users feel confident that they are providing their cr
## Commands

- [auth0 domains create](auth0_domains_create.md) - Create a custom domain
- [auth0 domains default](auth0_domains_default.md) - Manage the default custom domain
- [auth0 domains delete](auth0_domains_delete.md) - Delete a custom domain
- [auth0 domains list](auth0_domains_list.md) - List your custom domains
- [auth0 domains show](auth0_domains_show.md) - Show a custom domain
Expand Down
1 change: 1 addition & 0 deletions docs/auth0_domains_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ auth0 domains create [flags]
## Related Commands

- [auth0 domains create](auth0_domains_create.md) - Create a custom domain
- [auth0 domains default](auth0_domains_default.md) - Manage the default custom domain
- [auth0 domains delete](auth0_domains_delete.md) - Delete a custom domain
- [auth0 domains list](auth0_domains_list.md) - List your custom domains
- [auth0 domains show](auth0_domains_show.md) - Show a custom domain
Expand Down
14 changes: 14 additions & 0 deletions docs/auth0_domains_default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
layout: default
has_toc: false
has_children: true
---
# auth0 domains default

Manage the default custom domain for the tenant. Use sub-commands to show or set the default domain.

## Commands

- [auth0 domains default set](auth0_domains_default_set.md) - Set the default custom domain
- [auth0 domains default show](auth0_domains_default_show.md) - Show the default custom domain

53 changes: 53 additions & 0 deletions docs/auth0_domains_default_set.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
layout: default
parent: auth0 domains default
has_toc: false
---
# auth0 domains default set

Set the default custom domain for the tenant.

To set interactively, use `auth0 domains default set` with no arguments.

To set non-interactively, supply the domain name as an argument or through the flag.

## Usage
```
auth0 domains default set [flags]
```

## Examples

```
auth0 domains default set
auth0 domains default set <domain>
auth0 domains default set --domain <domain>
auth0 domains default set --domain <domain> --json
```


## Flags

```
-d, --domain string Domain name.
--json Output in json format.
--json-compact Output in compact json format.
```


## Inherited Flags

```
--debug Enable debug mode.
--no-color Disable colors.
--no-input Disable interactivity.
--tenant string Specific tenant to use.
```


## Related Commands

- [auth0 domains default set](auth0_domains_default_set.md) - Set the default custom domain
- [auth0 domains default show](auth0_domains_default_show.md) - Show the default custom domain


47 changes: 47 additions & 0 deletions docs/auth0_domains_default_show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
layout: default
parent: auth0 domains default
has_toc: false
---
# auth0 domains default show

Display the default custom domain configuration for the tenant.

## Usage
```
auth0 domains default show [flags]
```

## Examples

```
auth0 domains default show
auth0 domains default show --json
auth0 domains default show --json-compact
```


## Flags

```
--json Output in json format.
--json-compact Output in compact json format.
```


## Inherited Flags

```
--debug Enable debug mode.
--no-color Disable colors.
--no-input Disable interactivity.
--tenant string Specific tenant to use.
```


## Related Commands

- [auth0 domains default set](auth0_domains_default_set.md) - Set the default custom domain
- [auth0 domains default show](auth0_domains_default_show.md) - Show the default custom domain


1 change: 1 addition & 0 deletions docs/auth0_domains_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ auth0 domains delete [flags]
## Related Commands

- [auth0 domains create](auth0_domains_create.md) - Create a custom domain
- [auth0 domains default](auth0_domains_default.md) - Manage the default custom domain
- [auth0 domains delete](auth0_domains_delete.md) - Delete a custom domain
- [auth0 domains list](auth0_domains_list.md) - List your custom domains
- [auth0 domains show](auth0_domains_show.md) - Show a custom domain
Expand Down
1 change: 1 addition & 0 deletions docs/auth0_domains_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ auth0 domains list [flags]
## Related Commands

- [auth0 domains create](auth0_domains_create.md) - Create a custom domain
- [auth0 domains default](auth0_domains_default.md) - Manage the default custom domain
- [auth0 domains delete](auth0_domains_delete.md) - Delete a custom domain
- [auth0 domains list](auth0_domains_list.md) - List your custom domains
- [auth0 domains show](auth0_domains_show.md) - Show a custom domain
Expand Down
1 change: 1 addition & 0 deletions docs/auth0_domains_show.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ auth0 domains show [flags]
## Related Commands

- [auth0 domains create](auth0_domains_create.md) - Create a custom domain
- [auth0 domains default](auth0_domains_default.md) - Manage the default custom domain
- [auth0 domains delete](auth0_domains_delete.md) - Delete a custom domain
- [auth0 domains list](auth0_domains_list.md) - List your custom domains
- [auth0 domains show](auth0_domains_show.md) - Show a custom domain
Expand Down
1 change: 1 addition & 0 deletions docs/auth0_domains_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ auth0 domains update [flags]
## Related Commands

- [auth0 domains create](auth0_domains_create.md) - Create a custom domain
- [auth0 domains default](auth0_domains_default.md) - Manage the default custom domain
- [auth0 domains delete](auth0_domains_delete.md) - Delete a custom domain
- [auth0 domains list](auth0_domains_list.md) - List your custom domains
- [auth0 domains show](auth0_domains_show.md) - Show a custom domain
Expand Down
1 change: 1 addition & 0 deletions docs/auth0_domains_verify.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ auth0 domains verify [flags]
## Related Commands

- [auth0 domains create](auth0_domains_create.md) - Create a custom domain
- [auth0 domains default](auth0_domains_default.md) - Manage the default custom domain
- [auth0 domains delete](auth0_domains_delete.md) - Delete a custom domain
- [auth0 domains list](auth0_domains_list.md) - List your custom domains
- [auth0 domains show](auth0_domains_show.md) - Show a custom domain
Expand Down
6 changes: 6 additions & 0 deletions internal/auth0/custom_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@

// ListWithPagination lists all custom domains with support for pagination.
ListWithPagination(ctx context.Context, opts ...management.RequestOption) (c *management.CustomDomainList, err error)

// ReadDefault retrieves the default domain configuration for the tenant.
ReadDefault(ctx context.Context, opts ...management.RequestOption) (c *management.CustomDomainDefault, err error)

Check failure on line 34 in internal/auth0/custom_domain.go

View workflow job for this annotation

GitHub Actions / Vulnerabilities Scan

undefined: management.CustomDomainDefault

Check failure on line 34 in internal/auth0/custom_domain.go

View workflow job for this annotation

GitHub Actions / Build

undefined: management.CustomDomainDefault

Check failure on line 34 in internal/auth0/custom_domain.go

View workflow job for this annotation

GitHub Actions / Build

undefined: management.CustomDomainDefault

Check failure on line 34 in internal/auth0/custom_domain.go

View workflow job for this annotation

GitHub Actions / Build

undefined: management.CustomDomainDefault

Check failure on line 34 in internal/auth0/custom_domain.go

View workflow job for this annotation

GitHub Actions / Unit Tests

undefined: management.CustomDomainDefault

Check failure on line 34 in internal/auth0/custom_domain.go

View workflow job for this annotation

GitHub Actions / Checks

undefined: management.CustomDomainDefault

// UpdateDefault updates the default domain for the tenant.
UpdateDefault(ctx context.Context, c *management.CustomDomainDefault, opts ...management.RequestOption) error

Check failure on line 37 in internal/auth0/custom_domain.go

View workflow job for this annotation

GitHub Actions / Vulnerabilities Scan

undefined: management.CustomDomainDefault

Check failure on line 37 in internal/auth0/custom_domain.go

View workflow job for this annotation

GitHub Actions / Build

undefined: management.CustomDomainDefault

Check failure on line 37 in internal/auth0/custom_domain.go

View workflow job for this annotation

GitHub Actions / Build

undefined: management.CustomDomainDefault

Check failure on line 37 in internal/auth0/custom_domain.go

View workflow job for this annotation

GitHub Actions / Build

undefined: management.CustomDomainDefault

Check failure on line 37 in internal/auth0/custom_domain.go

View workflow job for this annotation

GitHub Actions / Unit Tests

undefined: management.CustomDomainDefault

Check failure on line 37 in internal/auth0/custom_domain.go

View workflow job for this annotation

GitHub Actions / Checks

undefined: management.CustomDomainDefault
}
40 changes: 40 additions & 0 deletions internal/auth0/mock/custom_domain_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions internal/cli/custom_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
cmd.AddCommand(updateCustomDomainCmd(cli))
cmd.AddCommand(deleteCustomDomainCmd(cli))
cmd.AddCommand(verifyCustomDomainCmd(cli))
cmd.AddCommand(defaultCustomDomainCmd(cli))

return cmd
}
Expand Down Expand Up @@ -517,6 +518,101 @@
}
}

func defaultCustomDomainCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "default",
Short: "Manage the default custom domain",
Long: "Manage the default custom domain for the tenant. Use sub-commands to show or set the default domain.",
}

cmd.SetUsageTemplate(resourceUsageTemplate())
cmd.AddCommand(showDefaultCustomDomainCmd(cli))
cmd.AddCommand(setDefaultCustomDomainCmd(cli))

return cmd
}

func showDefaultCustomDomainCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "show",
Args: cobra.NoArgs,
Short: "Show the default custom domain",
Long: "Display the default custom domain configuration for the tenant.",
Example: ` auth0 domains default show
auth0 domains default show --json
auth0 domains default show --json-compact`,
RunE: func(cmd *cobra.Command, args []string) error {
var defaultDomain *management.CustomDomainDefault

Check failure on line 545 in internal/cli/custom_domains.go

View workflow job for this annotation

GitHub Actions / Vulnerabilities Scan

undefined: management.CustomDomainDefault

if err := ansi.Waiting(func() (err error) {
defaultDomain, err = cli.api.CustomDomain.ReadDefault(cmd.Context())
return err
}); err != nil {
return fmt.Errorf("failed to read default custom domain: %w", err)
}

cli.renderer.CustomDomainDefaultShow(defaultDomain)

return nil
},
}

cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
cmd.Flags().BoolVar(&cli.jsonCompact, "json-compact", false, "Output in compact json format.")

return cmd
}

func setDefaultCustomDomainCmd(cli *cli) *cobra.Command {
var inputs struct {
Domain string
}

cmd := &cobra.Command{
Use: "set",
Args: cobra.MaximumNArgs(1),
Short: "Set the default custom domain",
Long: "Set the default custom domain for the tenant.\n\n" +
"To set interactively, use `auth0 domains default set` with no arguments.\n\n" +
"To set non-interactively, supply the domain name as an argument or through the flag.",
Example: ` auth0 domains default set
auth0 domains default set <domain>
auth0 domains default set --domain <domain>
auth0 domains default set --domain <domain> --json`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
inputs.Domain = args[0]
}

if inputs.Domain == "" {
if err := customDomainDomain.Pick(cmd, &inputs.Domain, cli.customDomainNamePickerOptions); err != nil {
return err
}
}

defaultDomain := &management.CustomDomainDefault{

Check failure on line 593 in internal/cli/custom_domains.go

View workflow job for this annotation

GitHub Actions / Vulnerabilities Scan

undefined: management.CustomDomainDefault
Domain: &inputs.Domain,
}

if err := ansi.Waiting(func() error {
return cli.api.CustomDomain.UpdateDefault(cmd.Context(), defaultDomain)
}); err != nil {
return fmt.Errorf("failed to set default custom domain to %q: %w", inputs.Domain, err)
}

cli.renderer.CustomDomainDefaultUpdate(defaultDomain)

return nil
},
}

customDomainDomain.RegisterString(cmd, &inputs.Domain, "")
cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
cmd.Flags().BoolVar(&cli.jsonCompact, "json-compact", false, "Output in compact json format.")

return cmd
}

func apiVerificationMethodFor(v string) *string {
switch v {
case "txt":
Expand Down Expand Up @@ -565,3 +661,32 @@

return opts, nil
}

func (c *cli) customDomainNamePickerOptions(ctx context.Context) (pickerOptions, error) {
var opts pickerOptions

domains, err := c.api.CustomDomain.List(ctx)
if err != nil {
var errStatus management.Error
errors.As(err, &errStatus)
// 403 is a valid response for free tenants that don't have
// custom domains enabled.
if errStatus != nil && errStatus.Status() == 403 {
return nil, errNoCustomDomains
}

return nil, fmt.Errorf("failed to list custom domains: %w", err)
}

for _, d := range domains {
domain := d.GetDomain()
label := fmt.Sprintf("%s %s", domain, ansi.Faint("("+d.GetID()+")"))
opts = append(opts, pickerOption{value: domain, label: label})
}

if len(opts) == 0 {
return nil, errNoCustomDomains
}

return opts, nil
}
Loading
Loading