Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Custom Domains Data Display and Delete Method for All Commands #1083

Merged
merged 10 commits into from
Oct 4, 2024
4 changes: 3 additions & 1 deletion internal/cli/custom_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"context"
"errors"
"fmt"
"net/url"

Expand Down Expand Up @@ -449,7 +450,8 @@ func (c *cli) customDomainsPickerOptions(ctx context.Context) (pickerOptions, er

domains, err := c.api.CustomDomain.List(ctx)
if err != nil {
errStatus := err.(management.Error)
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 {
Expand Down
4 changes: 1 addition & 3 deletions internal/cli/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,13 @@ func askPassword(i commandInput, value interface{}, isUpdate bool) error {
}

func askMultiSelect(i commandInput, value interface{}, options ...string) error {
v := reflect.ValueOf(value)
v := reflect.ValueOf(options)
if v.Kind() != reflect.Slice || v.Len() <= 0 {
return handleInputError(fmt.Errorf("there is not enough data to select from"))
}

if err := prompt.AskMultiSelect(i.GetLabel(), value, options...); err != nil {
return handleInputError(err)
}

return nil
}

Expand Down
62 changes: 51 additions & 11 deletions internal/display/custom_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type customDomainView struct {
Primary string
ProvisioningType string
VerificationMethod string
VerificationRecord string
VerificationDomain string
TLSPolicy string
CustomClientIPHeader string
raw interface{}
Expand All @@ -31,16 +33,40 @@ func (v *customDomainView) AsTableRow() []string {
}

func (v *customDomainView) KeyValues() [][]string {
return [][]string{
{"ID", ansi.Faint(v.ID)},
{"DOMAIN", v.Domain},
{"STATUS", v.Status},
{"PRIMARY", v.Primary},
{"PROVISIONING TYPE", v.ProvisioningType},
{"VERIFICATION METHOD", v.VerificationMethod},
{"TLS POLICY", v.TLSPolicy},
{"CUSTOM CLIENT IP HEADER", v.CustomClientIPHeader},
var keyValues [][]string

if v.ID != "" {
keyValues = append(keyValues, []string{"ID", v.ID})
}
if v.Domain != "" {
keyValues = append(keyValues, []string{"DOMAIN", v.Domain})
}
if v.Status != "" {
keyValues = append(keyValues, []string{"STATUS", v.Status})
}
if v.Primary != "" {
keyValues = append(keyValues, []string{"PRIMARY", v.Primary})
}
if v.ProvisioningType != "" {
keyValues = append(keyValues, []string{"PROVISIONING TYPE", v.ProvisioningType})
}
if v.VerificationMethod != "" {
keyValues = append(keyValues, []string{ansi.Cyan(ansi.Bold("VERIFICATION METHOD")), ansi.Cyan(ansi.Bold(v.VerificationMethod))})
}
if v.VerificationRecord != "" {
keyValues = append(keyValues, []string{ansi.Cyan(ansi.Bold("VERIFICATION RECORD VALUE")), ansi.Cyan(ansi.Bold(v.VerificationRecord))})
}
if v.VerificationDomain != "" {
keyValues = append(keyValues, []string{ansi.Cyan(ansi.Bold("VERIFICATION DOMAIN")), ansi.Cyan(ansi.Bold(v.VerificationDomain))})
}
if v.TLSPolicy != "" {
keyValues = append(keyValues, []string{"TLS POLICY", v.TLSPolicy})
}
if v.CustomClientIPHeader != "" {
keyValues = append(keyValues, []string{"CUSTOM CLIENT IP HEADER", v.CustomClientIPHeader})
}

return keyValues
}

func (v *customDomainView) Object() interface{} {
Expand Down Expand Up @@ -81,17 +107,31 @@ func (r *Renderer) CustomDomainUpdate(customDomain *management.CustomDomain) {
}

func makeCustomDomainView(customDomain *management.CustomDomain) *customDomainView {
return &customDomainView{
view := &customDomainView{
ID: ansi.Faint(customDomain.GetID()),
Domain: customDomain.GetDomain(),
Status: customDomainStatusColor(customDomain.GetStatus()),
Primary: boolean(customDomain.GetPrimary()),
ProvisioningType: customDomain.GetType(),
VerificationMethod: customDomain.GetVerificationMethod(),
TLSPolicy: customDomain.GetTLSPolicy(),
CustomClientIPHeader: customDomain.GetCustomClientIPHeader(),
raw: customDomain,
}

if len(customDomain.GetVerification().Methods) > 0 {
method := customDomain.GetVerification().Methods[0]
if name, ok := method["name"].(string); ok {
view.VerificationMethod = name
}
if record, ok := method["record"].(string); ok {
view.VerificationRecord = record
}
if domain, ok := method["domain"].(string); ok {
view.VerificationDomain = domain
}
}

return view
}

func customDomainStatusColor(v string) string {
Expand Down
55 changes: 27 additions & 28 deletions test/integration/custom-domains-test-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ tests:
exit-code: 0
stdout:
contains:
- "ID cd_"
- "DOMAIN auth0-cli-integration-test.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
- "ID cd_"
- "DOMAIN auth0-cli-integration-test.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"

004 - unsuccessfully create domain with same name:
command: auth0 domains create --domain "auth0-cli-integration-test.com" --no-input
Expand All @@ -39,41 +39,41 @@ tests:
exit-code: 0
stdout:
contains:
- "ID cd_"
- "DOMAIN auth0-cli-integration-test.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
- "ID cd_"
- "DOMAIN auth0-cli-integration-test.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"

006 - update domain minimal flags:
command: auth0 domains update $(./test/integration/scripts/get-custom-domain-id.sh) --no-input
exit-code: 0
stdout:
contains:
- "ID cd_"
- "DOMAIN auth0-cli-integration-test.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
- "ID cd_"
- "DOMAIN auth0-cli-integration-test.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"

007 - update domain maximal flags:
command: auth0 domains update $(./test/integration/scripts/get-custom-domain-id.sh) --policy recommended --no-input
exit-code: 0
stdout:
contains:
- "ID cd_"
- "DOMAIN auth0-cli-integration-test.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
- "TLS POLICY recommended"
- "ID cd_"
- "DOMAIN auth0-cli-integration-test.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE auth0_managed_certs"
- "TLS POLICY recommended"

008 - verify domain:
command: auth0 domains update $(./test/integration/scripts/get-custom-domain-id.sh) --policy recommended --no-input
exit-code: 0
stdout:
contains:
- "ID cd_"
- "DOMAIN auth0-cli-integration-test.com"
- "PROVISIONING TYPE auth0_managed_certs"
- "TLS POLICY recommended"
- "ID cd_"
- "DOMAIN auth0-cli-integration-test.com"
- "PROVISIONING TYPE auth0_managed_certs"
- "TLS POLICY recommended"

009 - delete domain:
command: auth0 domains delete $(./test/integration/scripts/get-custom-domain-id.sh) --no-input
Expand All @@ -84,13 +84,12 @@ tests:
exit-code: 0
stdout:
contains:
- "ID cd_"
- "DOMAIN auth0-cli-integration-test.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE self_managed_certs"
- "VERIFICATION METHOD txt"
- "TLS POLICY recommended"
- "CUSTOM CLIENT IP HEADER"
- "ID cd_"
- "DOMAIN auth0-cli-integration-test.com"
- "STATUS pending_verification"
- "PROVISIONING TYPE self_managed_certs"
- "VERIFICATION METHOD TXT"
- "TLS POLICY recommended"

011 - list custom domains with results:
command: auth0 domains list
Expand Down
Loading