Skip to content

Commit

Permalink
Add pagination to extension schema
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgajard committed May 2, 2024
1 parent a3f7d22 commit 3f7de69
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions pagerdutyplugin/data_source_pagerduty_extension_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,37 @@ func (d *dataSourceExtensionSchema) Read(ctx context.Context, req datasource.Rea
}

var found *pagerduty.ExtensionSchema
err := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
list, err := d.client.ListExtensionSchemasWithContext(ctx, pagerduty.ListExtensionSchemaOptions{Limit: 100})
if err != nil {
if util.IsBadRequestError(err) {
return retry.NonRetryableError(err)
offset := 0
more := true
for more {
err := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
o := pagerduty.ListExtensionSchemaOptions{Limit: 20, Offset: uint(offset), Total: true}
list, err := d.client.ListExtensionSchemasWithContext(ctx, o)
if err != nil {
if util.IsBadRequestError(err) {
return retry.NonRetryableError(err)
}
return retry.RetryableError(err)
}
return retry.RetryableError(err)
}

for _, extensionSchema := range list.ExtensionSchemas {
if strings.EqualFold(extensionSchema.Label, searchName.ValueString()) {
found = &extensionSchema
break
for _, extensionSchema := range list.ExtensionSchemas {
if strings.EqualFold(extensionSchema.Label, searchName.ValueString()) {
found = &extensionSchema
more = false
return nil
}
}

more = list.More
offset += len(list.ExtensionSchemas)
return nil
})
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Error reading PagerDuty extension schema %s", searchName),
err.Error(),
)
}
return nil
})
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Error reading PagerDuty extension schema %s", searchName),
err.Error(),
)
}

if found == nil {
Expand Down

0 comments on commit 3f7de69

Please sign in to comment.