diff --git a/internal/cli/custom_domains.go b/internal/cli/custom_domains.go index 0e52417b5..4e19c5976 100644 --- a/internal/cli/custom_domains.go +++ b/internal/cli/custom_domains.go @@ -2,6 +2,7 @@ package cli import ( "context" + "errors" "fmt" "net/url" @@ -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 { diff --git a/internal/cli/input.go b/internal/cli/input.go index e805ed6c8..8b577f14f 100644 --- a/internal/cli/input.go +++ b/internal/cli/input.go @@ -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 } diff --git a/internal/display/custom_domain.go b/internal/display/custom_domain.go index 936623bc8..298f200ae 100644 --- a/internal/display/custom_domain.go +++ b/internal/display/custom_domain.go @@ -13,6 +13,8 @@ type customDomainView struct { Primary string ProvisioningType string VerificationMethod string + VerificationRecord string + VerificationDomain string TLSPolicy string CustomClientIPHeader string raw interface{} @@ -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{} { @@ -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 { diff --git a/test/integration/custom-domains-test-cases.yaml b/test/integration/custom-domains-test-cases.yaml index 8d0fd8ad6..59a318623 100644 --- a/test/integration/custom-domains-test-cases.yaml +++ b/test/integration/custom-domains-test-cases.yaml @@ -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 @@ -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 @@ -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