Skip to content

Commit acdd92c

Browse files
authored
Revert checkpoint pagination and use LIST endpoint for custom domains (#1306)
1 parent 3ddbf3e commit acdd92c

7 files changed

Lines changed: 73 additions & 164 deletions

internal/cli/custom_domains.go

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func listCustomDomainsCmd(cli *cli) *cobra.Command {
119119
var list []*management.CustomDomain
120120

121121
if err := ansi.Waiting(func() (err error) {
122-
list, err = cli.ListAllCustomDomains(cmd.Context())
122+
list, err = cli.api.CustomDomain.List(cmd.Context())
123123
return err
124124
}); err != nil {
125125
return fmt.Errorf("failed to list custom domains: %w", err)
@@ -504,7 +504,7 @@ func apiTLSPolicyFor(v string) *string {
504504
func (c *cli) customDomainsPickerOptions(ctx context.Context) (pickerOptions, error) {
505505
var opts pickerOptions
506506

507-
domains, err := c.ListAllCustomDomains(ctx)
507+
domains, err := c.api.CustomDomain.List(ctx)
508508
if err != nil {
509509
var errStatus management.Error
510510
errors.As(err, &errStatus)
@@ -529,34 +529,3 @@ func (c *cli) customDomainsPickerOptions(ctx context.Context) (pickerOptions, er
529529

530530
return opts, nil
531531
}
532-
533-
func (c *cli) ListAllCustomDomains(ctx context.Context) ([]*management.CustomDomain, error) {
534-
var (
535-
from string
536-
allDomains []*management.CustomDomain
537-
options = []management.RequestOption{
538-
management.Take(100),
539-
}
540-
)
541-
542-
for {
543-
if from != "" {
544-
options = append(options, management.From(from))
545-
}
546-
547-
list, err := c.api.CustomDomain.ListWithPagination(ctx, options...)
548-
if err != nil {
549-
return nil, err
550-
}
551-
552-
allDomains = append(allDomains, list.CustomDomains...)
553-
554-
if !list.HasNext() {
555-
break
556-
}
557-
558-
from = list.Next
559-
}
560-
561-
return allDomains, nil
562-
}

internal/cli/custom_domains_test.go

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,24 @@ func TestAPITLSPolicyFor(t *testing.T) {
8787

8888
func TestCustomDomainsPickerOptions(t *testing.T) {
8989
tests := []struct {
90-
name string
91-
customDomainsList *management.CustomDomainList
92-
apiError error
93-
assertOutput func(t testing.TB, options pickerOptions)
94-
assertError func(t testing.TB, err error)
90+
name string
91+
customDomains []*management.CustomDomain
92+
apiError error
93+
assertOutput func(t testing.TB, options pickerOptions)
94+
assertError func(t testing.TB, err error)
9595
}{
9696
{
9797
name: "happy path",
98-
customDomainsList: &management.CustomDomainList{
99-
CustomDomains: []*management.CustomDomain{
100-
{
101-
ID: auth0.String("some-id-1"),
102-
Domain: auth0.String("some-domain-1"),
103-
Status: auth0.String("ready"),
104-
},
105-
{
106-
ID: auth0.String("some-id-2"),
107-
Domain: auth0.String("some-domain-2"),
108-
Status: auth0.String("ready"),
109-
},
98+
customDomains: []*management.CustomDomain{
99+
{
100+
ID: auth0.String("some-id-1"),
101+
Domain: auth0.String("some-domain-1"),
102+
Status: auth0.String("ready"),
103+
},
104+
{
105+
ID: auth0.String("some-id-2"),
106+
Domain: auth0.String("some-domain-2"),
107+
Status: auth0.String("ready"),
110108
},
111109
},
112110
assertOutput: func(t testing.TB, options pickerOptions) {
@@ -122,18 +120,16 @@ func TestCustomDomainsPickerOptions(t *testing.T) {
122120
},
123121
{
124122
name: "custom domains with a non-ready status",
125-
customDomainsList: &management.CustomDomainList{
126-
CustomDomains: []*management.CustomDomain{
127-
{
128-
ID: auth0.String("some-id-1"),
129-
Domain: auth0.String("some-domain-1"),
130-
Status: auth0.String("pending_verification"),
131-
},
132-
{
133-
ID: auth0.String("some-id-2"),
134-
Domain: auth0.String("some-domain-2"),
135-
Status: auth0.String("ready"),
136-
},
123+
customDomains: []*management.CustomDomain{
124+
{
125+
ID: auth0.String("some-id-1"),
126+
Domain: auth0.String("some-domain-1"),
127+
Status: auth0.String("pending_verification"),
128+
},
129+
{
130+
ID: auth0.String("some-id-2"),
131+
Domain: auth0.String("some-domain-2"),
132+
Status: auth0.String("ready"),
137133
},
138134
},
139135
assertOutput: func(t testing.TB, options pickerOptions) {
@@ -148,10 +144,8 @@ func TestCustomDomainsPickerOptions(t *testing.T) {
148144
},
149145
},
150146
{
151-
name: "no custom domains",
152-
customDomainsList: &management.CustomDomainList{
153-
CustomDomains: []*management.CustomDomain{},
154-
},
147+
name: "no custom domains",
148+
customDomains: []*management.CustomDomain{},
155149
assertOutput: func(t testing.TB, options pickerOptions) {
156150
t.Fail()
157151
},
@@ -188,8 +182,8 @@ func TestCustomDomainsPickerOptions(t *testing.T) {
188182

189183
customDomainAPI := mock.NewMockCustomDomainAPI(ctrl)
190184
customDomainAPI.EXPECT().
191-
ListWithPagination(gomock.Any(), gomock.Any()).
192-
Return(test.customDomainsList, test.apiError)
185+
List(gomock.Any()).
186+
Return(test.customDomains, test.apiError)
193187

194188
cli := &cli{
195189
api: &auth0.API{CustomDomain: customDomainAPI},

internal/cli/terraform_fetcher.go

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -259,42 +259,24 @@ func (f *connectionResourceFetcher) FetchData(ctx context.Context) (importDataLi
259259
}
260260

261261
func (f *customDomainResourceFetcher) FetchData(ctx context.Context) (importDataList, error) {
262-
var (
263-
data importDataList
264-
from string
265-
options = []management.RequestOption{management.Take(100)}
266-
allDomains []*management.CustomDomain
267-
)
262+
var data importDataList
268263

269-
for {
270-
if from != "" {
271-
options = append([]management.RequestOption{management.From(from)}, options...)
264+
customDomains, err := f.api.CustomDomain.List(ctx)
265+
if err != nil {
266+
errNotEnabled := []string{
267+
"The account is not allowed to perform this operation, please contact our support team",
268+
"There must be a verified credit card on file to perform this operation",
272269
}
273270

274-
list, err := f.api.CustomDomain.ListWithPagination(ctx, options...)
275-
if err != nil {
276-
errNotEnabled := []string{
277-
"The account is not allowed to perform this operation, please contact our support team",
278-
"There must be a verified credit card on file to perform this operation",
279-
}
280-
281-
for _, e := range errNotEnabled {
282-
if strings.Contains(err.Error(), e) {
283-
return data, nil
284-
}
271+
for _, e := range errNotEnabled {
272+
if strings.Contains(err.Error(), e) {
273+
return data, nil
285274
}
286-
return nil, err
287275
}
288-
289-
allDomains = append(allDomains, list.CustomDomains...)
290-
291-
if !list.HasNext() {
292-
break
293-
}
294-
from = list.Next
276+
return nil, err
295277
}
296278

297-
for _, domain := range allDomains {
279+
for _, domain := range customDomains {
298280
data = append(data, importDataItem{
299281
ResourceName: "auth0_custom_domain." + sanitizeResourceName(domain.GetDomain()),
300282
ImportID: domain.GetID(),

internal/cli/terraform_fetcher_test.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -581,20 +581,19 @@ func TestCustomDomainResourceFetcher_FetchData(t *testing.T) {
581581

582582
customDomainAPI := mock.NewMockCustomDomainAPI(ctrl)
583583
customDomainAPI.EXPECT().
584-
ListWithPagination(gomock.Any(), gomock.Any()).
584+
List(gomock.Any()).
585585
Return(
586-
&management.CustomDomainList{
587-
CustomDomains: []*management.CustomDomain{
588-
{
589-
ID: auth0.String("cd_XDVfBNsfL2vj7Wm1"),
590-
Domain: auth0.String("travel0.com"),
591-
},
592-
{
593-
ID: auth0.String("cd_XDVfBNsfL2vj7Wm1"),
594-
Domain: auth0.String("enterprise.travel0.com"),
595-
},
586+
[]*management.CustomDomain{
587+
{
588+
ID: auth0.String("cd_XDVfBNsfL2vj7Wm1"),
589+
Domain: auth0.String("travel0.com"),
596590
},
597-
}, nil,
591+
{
592+
ID: auth0.String("cd_XDVfBNsfL2vj7Wm1"),
593+
Domain: auth0.String("enterprise.travel0.com"),
594+
},
595+
},
596+
nil,
598597
)
599598

600599
fetcher := customDomainResourceFetcher{
@@ -625,7 +624,7 @@ func TestCustomDomainResourceFetcher_FetchData(t *testing.T) {
625624

626625
customDomainAPI := mock.NewMockCustomDomainAPI(ctrl)
627626
customDomainAPI.EXPECT().
628-
ListWithPagination(gomock.Any(), gomock.Any()).
627+
List(gomock.Any()).
629628
Return(nil, fmt.Errorf("failed to list custom domains"))
630629

631630
fetcher := customDomainResourceFetcher{
@@ -644,7 +643,7 @@ func TestCustomDomainResourceFetcher_FetchData(t *testing.T) {
644643

645644
customDomainAPI := mock.NewMockCustomDomainAPI(ctrl)
646645
customDomainAPI.EXPECT().
647-
ListWithPagination(gomock.Any(), gomock.Any()).
646+
List(gomock.Any()).
648647
Return(nil, fmt.Errorf("403 Forbidden: The account is not allowed to perform this operation, please contact our support team"))
649648

650649
fetcher := customDomainResourceFetcher{
@@ -664,7 +663,7 @@ func TestCustomDomainResourceFetcher_FetchData(t *testing.T) {
664663

665664
customDomainAPI := mock.NewMockCustomDomainAPI(ctrl)
666665
customDomainAPI.EXPECT().
667-
ListWithPagination(gomock.Any(), gomock.Any()).
666+
List(gomock.Any()).
668667
Return(nil, fmt.Errorf("403 Forbidden: There must be a verified credit card on file to perform this operation"))
669668

670669
fetcher := customDomainResourceFetcher{

internal/cli/test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func selectClientToUseForTestsAndValidateExistence(cli *cli, cmd *cobra.Command,
370370
func (c *cli) customDomainPickerOptions(ctx context.Context) (pickerOptions, error) {
371371
var opts pickerOptions
372372

373-
domains, err := c.ListAllCustomDomains(ctx)
373+
domains, err := c.api.CustomDomain.List(ctx)
374374
if err != nil {
375375
errStatus := err.(management.Error)
376376
// 403 is a valid response for free tenants that don't have

internal/cli/universal_login_templates.go

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -264,44 +264,17 @@ func (cli *cli) fetchTemplateData(ctx context.Context) (*TemplateData, error) {
264264
}
265265

266266
func ensureCustomDomainIsEnabled(ctx context.Context, api *auth0.API) error {
267-
var (
268-
from string
269-
allDomains []*management.CustomDomain
270-
options = []management.RequestOption{management.Take(100)}
271-
customDomain *management.CustomDomainList
272-
err error
273-
)
274-
275-
for {
276-
reqOptions := append([]management.RequestOption{}, options...)
277-
if from != "" {
278-
reqOptions = append(reqOptions, management.From(from))
279-
}
280-
281-
customDomain, err = api.CustomDomain.ListWithPagination(ctx, reqOptions...)
282-
if err != nil {
283-
break
284-
}
285-
286-
allDomains = append(allDomains, customDomain.CustomDomains...)
287-
288-
if !customDomain.HasNext() {
289-
break
290-
}
291-
292-
from = customDomain.Next
293-
}
294-
267+
domains, err := api.CustomDomain.List(ctx)
295268
if err != nil {
296269
if mErr, ok := err.(management.Error); ok && mErr.Status() == http.StatusForbidden {
297-
return errNotAllowed // 403 is expected for tenants without custom domain support.
270+
return errNotAllowed // 403 is a valid response for free tenants that don't have custom domains enabled.
298271
}
299272

300273
return err
301274
}
302275

303276
const domainIsVerified = "ready"
304-
for _, domain := range allDomains {
277+
for _, domain := range domains {
305278
if domain.GetStatus() == domainIsVerified {
306279
return nil
307280
}

0 commit comments

Comments
 (0)