From 522c5b8d15b9996f6bef1bc77818c48746e84ed3 Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Thu, 3 Oct 2024 11:34:07 +0530 Subject: [PATCH 1/8] Fix Custom Domains Data Display and Delete Method for All Commands --- internal/cli/custom_domains.go | 4 +- internal/cli/input.go | 6 +-- internal/display/custom_domain.go | 62 +++++++++++++++++++++++++------ 3 files changed, 57 insertions(+), 15 deletions(-) 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..c57e0f153 100644 --- a/internal/cli/input.go +++ b/internal/cli/input.go @@ -60,15 +60,15 @@ func askPassword(i commandInput, value interface{}, isUpdate bool) error { } func askMultiSelect(i commandInput, value interface{}, options ...string) error { - v := reflect.ValueOf(value) - if v.Kind() != reflect.Slice || v.Len() <= 0 { + v := reflect.Indirect(reflect.ValueOf(value)) + + if v.Kind() != reflect.Slice { 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..2abde922f 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", ansi.Faint(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 { From cb70d2b5d607d13f5ef6a79b1472e362cea70805 Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Thu, 3 Oct 2024 12:28:24 +0530 Subject: [PATCH 2/8] Fix Alignment of tests --- internal/display/custom_domain.go | 2 +- test/integration/custom-domains-test-cases.yaml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/display/custom_domain.go b/internal/display/custom_domain.go index 2abde922f..298f200ae 100644 --- a/internal/display/custom_domain.go +++ b/internal/display/custom_domain.go @@ -36,7 +36,7 @@ func (v *customDomainView) KeyValues() [][]string { var keyValues [][]string if v.ID != "" { - keyValues = append(keyValues, []string{"ID", ansi.Faint(v.ID)}) + keyValues = append(keyValues, []string{"ID", v.ID}) } if v.Domain != "" { keyValues = append(keyValues, []string{"DOMAIN", v.Domain}) diff --git a/test/integration/custom-domains-test-cases.yaml b/test/integration/custom-domains-test-cases.yaml index 8d0fd8ad6..ff9e81479 100644 --- a/test/integration/custom-domains-test-cases.yaml +++ b/test/integration/custom-domains-test-cases.yaml @@ -22,7 +22,7 @@ tests: exit-code: 0 stdout: contains: - - "ID cd_" + - "ID cd_" - "DOMAIN auth0-cli-integration-test.com" - "STATUS pending_verification" - "PROVISIONING TYPE auth0_managed_certs" @@ -39,7 +39,7 @@ tests: exit-code: 0 stdout: contains: - - "ID cd_" + - "ID cd_" - "DOMAIN auth0-cli-integration-test.com" - "STATUS pending_verification" - "PROVISIONING TYPE auth0_managed_certs" @@ -49,7 +49,7 @@ tests: exit-code: 0 stdout: contains: - - "ID cd_" + - "ID cd_" - "DOMAIN auth0-cli-integration-test.com" - "STATUS pending_verification" - "PROVISIONING TYPE auth0_managed_certs" @@ -59,7 +59,7 @@ tests: exit-code: 0 stdout: contains: - - "ID cd_" + - "ID cd_" - "DOMAIN auth0-cli-integration-test.com" - "STATUS pending_verification" - "PROVISIONING TYPE auth0_managed_certs" @@ -70,7 +70,7 @@ tests: exit-code: 0 stdout: contains: - - "ID cd_" + - "ID cd_" - "DOMAIN auth0-cli-integration-test.com" - "PROVISIONING TYPE auth0_managed_certs" - "TLS POLICY recommended" @@ -84,7 +84,7 @@ tests: exit-code: 0 stdout: contains: - - "ID cd_" + - "ID cd_" - "DOMAIN auth0-cli-integration-test.com" - "STATUS pending_verification" - "PROVISIONING TYPE self_managed_certs" From d669d52ba32ec8d05097b377ed2eae1ac69fd6a3 Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Thu, 3 Oct 2024 12:40:57 +0530 Subject: [PATCH 3/8] Fix Text Alignment of tests --- .../custom-domains-test-cases.yaml | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/test/integration/custom-domains-test-cases.yaml b/test/integration/custom-domains-test-cases.yaml index ff9e81479..33879c869 100644 --- a/test/integration/custom-domains-test-cases.yaml +++ b/test/integration/custom-domains-test-cases.yaml @@ -23,9 +23,9 @@ tests: stdout: contains: - "ID cd_" - - "DOMAIN auth0-cli-integration-test.com" - - "STATUS pending_verification" - - "PROVISIONING TYPE auth0_managed_certs" + - "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 @@ -40,9 +40,9 @@ tests: stdout: contains: - "ID cd_" - - "DOMAIN auth0-cli-integration-test.com" - - "STATUS pending_verification" - - "PROVISIONING TYPE auth0_managed_certs" + - "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 @@ -50,9 +50,9 @@ tests: stdout: contains: - "ID cd_" - - "DOMAIN auth0-cli-integration-test.com" - - "STATUS pending_verification" - - "PROVISIONING TYPE auth0_managed_certs" + - "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 @@ -60,10 +60,10 @@ tests: stdout: contains: - "ID cd_" - - "DOMAIN auth0-cli-integration-test.com" - - "STATUS pending_verification" - - "PROVISIONING TYPE auth0_managed_certs" - - "TLS POLICY recommended" + - "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 @@ -71,9 +71,9 @@ tests: stdout: contains: - "ID cd_" - - "DOMAIN auth0-cli-integration-test.com" - - "PROVISIONING TYPE auth0_managed_certs" - - "TLS POLICY recommended" + - "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 @@ -85,11 +85,11 @@ tests: stdout: contains: - "ID cd_" - - "DOMAIN auth0-cli-integration-test.com" - - "STATUS pending_verification" - - "PROVISIONING TYPE self_managed_certs" - - "VERIFICATION METHOD txt" - - "TLS POLICY recommended" + - "DOMAIN auth0-cli-integration-test.com" + - "STATUS pending_verification" + - "PROVISIONING TYPE self_managed_certs" + - "VERIFICATION METHOD txt" + - "TLS POLICY recommended" - "CUSTOM CLIENT IP HEADER" 011 - list custom domains with results: From b094b73f1cd23e3d4ff0794d13f49b71bf4a4b1e Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Thu, 3 Oct 2024 14:00:45 +0530 Subject: [PATCH 4/8] Removed Extra validations --- internal/cli/input.go | 10 +--------- test/integration/custom-domains-test-cases.yaml | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/internal/cli/input.go b/internal/cli/input.go index c57e0f153..805983436 100644 --- a/internal/cli/input.go +++ b/internal/cli/input.go @@ -2,11 +2,9 @@ package cli import ( "fmt" - "os" - "reflect" - "github.com/AlecAivazis/survey/v2/terminal" "github.com/auth0/go-auth0" + "os" "github.com/auth0/auth0-cli/internal/prompt" ) @@ -60,12 +58,6 @@ func askPassword(i commandInput, value interface{}, isUpdate bool) error { } func askMultiSelect(i commandInput, value interface{}, options ...string) error { - v := reflect.Indirect(reflect.ValueOf(value)) - - if v.Kind() != reflect.Slice { - 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) } diff --git a/test/integration/custom-domains-test-cases.yaml b/test/integration/custom-domains-test-cases.yaml index 33879c869..24fbe93ae 100644 --- a/test/integration/custom-domains-test-cases.yaml +++ b/test/integration/custom-domains-test-cases.yaml @@ -88,7 +88,7 @@ tests: - "DOMAIN auth0-cli-integration-test.com" - "STATUS pending_verification" - "PROVISIONING TYPE self_managed_certs" - - "VERIFICATION METHOD txt" + - "VERIFICATION METHOD TXT" - "TLS POLICY recommended" - "CUSTOM CLIENT IP HEADER" From c6d9b6d1344ce36d80dcb3646f6bedb55577889f Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Thu, 3 Oct 2024 14:03:34 +0530 Subject: [PATCH 5/8] Fixed Linting Issue --- internal/cli/input.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/cli/input.go b/internal/cli/input.go index 805983436..3db017bdb 100644 --- a/internal/cli/input.go +++ b/internal/cli/input.go @@ -2,9 +2,10 @@ package cli import ( "fmt" + "os" + "github.com/AlecAivazis/survey/v2/terminal" "github.com/auth0/go-auth0" - "os" "github.com/auth0/auth0-cli/internal/prompt" ) From 2720757b9f23236a71a2fe3c558ace3f58f19d30 Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Thu, 3 Oct 2024 14:16:57 +0530 Subject: [PATCH 6/8] Fixed All tests --- test/integration/custom-domains-test-cases.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/test/integration/custom-domains-test-cases.yaml b/test/integration/custom-domains-test-cases.yaml index 24fbe93ae..59a318623 100644 --- a/test/integration/custom-domains-test-cases.yaml +++ b/test/integration/custom-domains-test-cases.yaml @@ -90,7 +90,6 @@ tests: - "PROVISIONING TYPE self_managed_certs" - "VERIFICATION METHOD TXT" - "TLS POLICY recommended" - - "CUSTOM CLIENT IP HEADER" 011 - list custom domains with results: command: auth0 domains list From 142f226caa1c0edff7c9fa1c434b88fdafb0fd17 Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Fri, 4 Oct 2024 11:14:59 +0530 Subject: [PATCH 7/8] Added Check --- internal/cli/input.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/cli/input.go b/internal/cli/input.go index 3db017bdb..ec6e3ef9b 100644 --- a/internal/cli/input.go +++ b/internal/cli/input.go @@ -2,10 +2,10 @@ package cli import ( "fmt" - "os" - "github.com/AlecAivazis/survey/v2/terminal" "github.com/auth0/go-auth0" + "os" + "reflect" "github.com/auth0/auth0-cli/internal/prompt" ) @@ -59,6 +59,10 @@ func askPassword(i commandInput, value interface{}, isUpdate bool) error { } func askMultiSelect(i commandInput, value interface{}, options ...string) error { + 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) } From a42d2233629f000b58d3b96b9bd7aedf7faeb5d1 Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Fri, 4 Oct 2024 11:17:41 +0530 Subject: [PATCH 8/8] FIx linting --- internal/cli/input.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/cli/input.go b/internal/cli/input.go index ec6e3ef9b..8b577f14f 100644 --- a/internal/cli/input.go +++ b/internal/cli/input.go @@ -2,11 +2,12 @@ package cli import ( "fmt" - "github.com/AlecAivazis/survey/v2/terminal" - "github.com/auth0/go-auth0" "os" "reflect" + "github.com/AlecAivazis/survey/v2/terminal" + "github.com/auth0/go-auth0" + "github.com/auth0/auth0-cli/internal/prompt" )