diff --git a/.changelog/1493.txt b/.changelog/1493.txt new file mode 100644 index 00000000000..5ef7484fe4d --- /dev/null +++ b/.changelog/1493.txt @@ -0,0 +1,3 @@ +```release-note:bug +access_application,access_ca_certificate,access_group,access_identity_provider,access_mutual_tls_certificates,access_policyaccess_users,account_roles,d1pages_deployment,tunnel,turnstile,: All this endpoints are susceptible to returning wrong data due to the Struct not getting reset for every loop. +``` diff --git a/access_application.go b/access_application.go index 53ab80957e6..6749500029b 100644 --- a/access_application.go +++ b/access_application.go @@ -239,7 +239,7 @@ func (api *API) ListAccessApplications(ctx context.Context, rc *ResourceContaine } var applications []AccessApplication - var r AccessApplicationListResponse + var lastResultInfo *ResultInfo = nil for { uri := buildURI(baseURL, params) @@ -248,11 +248,13 @@ func (api *API) ListAccessApplications(ctx context.Context, rc *ResourceContaine if err != nil { return []AccessApplication{}, &ResultInfo{}, fmt.Errorf("%s: %w", errMakeRequestError, err) } + var r AccessApplicationListResponse err = json.Unmarshal(res, &r) if err != nil { return []AccessApplication{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + lastResultInfo = &r.ResultInfo applications = append(applications, r.Result...) params.ResultInfo = r.ResultInfo.Next() if params.ResultInfo.Done() || !autoPaginate { @@ -260,7 +262,7 @@ func (api *API) ListAccessApplications(ctx context.Context, rc *ResourceContaine } } - return applications, &r.ResultInfo, nil + return applications, lastResultInfo, nil } // GetAccessApplication returns a single application based on the application diff --git a/access_ca_certificate.go b/access_ca_certificate.go index 8f167875ed5..6385e3c3543 100644 --- a/access_ca_certificate.go +++ b/access_ca_certificate.go @@ -60,7 +60,7 @@ func (api *API) ListAccessCACertificates(ctx context.Context, rc *ResourceContai } var accessCACertificates []AccessCACertificate - var r AccessCACertificateListResponse + var lastResultInfo *ResultInfo = nil for { uri := buildURI(baseURL, params) @@ -68,11 +68,13 @@ func (api *API) ListAccessCACertificates(ctx context.Context, rc *ResourceContai if err != nil { return []AccessCACertificate{}, &ResultInfo{}, fmt.Errorf("%s: %w", errMakeRequestError, err) } + var r AccessCACertificateListResponse err = json.Unmarshal(res, &r) if err != nil { return []AccessCACertificate{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + lastResultInfo = &r.ResultInfo accessCACertificates = append(accessCACertificates, r.Result...) params.ResultInfo = r.ResultInfo.Next() if params.ResultInfo.Done() || !autoPaginate { @@ -80,7 +82,7 @@ func (api *API) ListAccessCACertificates(ctx context.Context, rc *ResourceContai } } - return accessCACertificates, &r.ResultInfo, nil + return accessCACertificates, lastResultInfo, nil } // GetAccessCACertificate returns a single CA certificate associated within diff --git a/access_group.go b/access_group.go index a521db8e021..ef2631faca1 100644 --- a/access_group.go +++ b/access_group.go @@ -280,7 +280,7 @@ func (api *API) ListAccessGroups(ctx context.Context, rc *ResourceContainer, par } var accessGroups []AccessGroup - var r AccessGroupListResponse + var lastResultInfo *ResultInfo = nil for { uri := buildURI(baseURL, params) @@ -288,11 +288,13 @@ func (api *API) ListAccessGroups(ctx context.Context, rc *ResourceContainer, par if err != nil { return []AccessGroup{}, &ResultInfo{}, fmt.Errorf("%s: %w", errMakeRequestError, err) } + var r AccessGroupListResponse err = json.Unmarshal(res, &r) if err != nil { return []AccessGroup{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + lastResultInfo = &r.ResultInfo accessGroups = append(accessGroups, r.Result...) params.ResultInfo = r.ResultInfo.Next() if params.ResultInfo.Done() || !autoPaginate { @@ -300,7 +302,7 @@ func (api *API) ListAccessGroups(ctx context.Context, rc *ResourceContainer, par } } - return accessGroups, &r.ResultInfo, nil + return accessGroups, lastResultInfo, nil } // GetAccessGroup returns a single group based on the group ID. diff --git a/access_identity_provider.go b/access_identity_provider.go index a1ffc8ced58..509ca83ae9b 100644 --- a/access_identity_provider.go +++ b/access_identity_provider.go @@ -132,7 +132,7 @@ func (api *API) ListAccessIdentityProviders(ctx context.Context, rc *ResourceCon } var accessProviders []AccessIdentityProvider - var r AccessIdentityProvidersListResponse + var lastResultInfo *ResultInfo = nil for { uri := buildURI(baseURL, params) @@ -140,11 +140,13 @@ func (api *API) ListAccessIdentityProviders(ctx context.Context, rc *ResourceCon if err != nil { return []AccessIdentityProvider{}, &ResultInfo{}, fmt.Errorf("%s: %w", errMakeRequestError, err) } + var r AccessIdentityProvidersListResponse err = json.Unmarshal(res, &r) if err != nil { return []AccessIdentityProvider{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + lastResultInfo = &r.ResultInfo accessProviders = append(accessProviders, r.Result...) params.ResultInfo = r.ResultInfo.Next() @@ -153,7 +155,7 @@ func (api *API) ListAccessIdentityProviders(ctx context.Context, rc *ResourceCon } } - return accessProviders, &r.ResultInfo, nil + return accessProviders, lastResultInfo, nil } // GetAccessIdentityProvider returns a single Access Identity diff --git a/access_mutual_tls_certificates.go b/access_mutual_tls_certificates.go index 393476c4283..7b3685d4008 100644 --- a/access_mutual_tls_certificates.go +++ b/access_mutual_tls_certificates.go @@ -83,7 +83,7 @@ func (api *API) ListAccessMutualTLSCertificates(ctx context.Context, rc *Resourc } var accessCertificates []AccessMutualTLSCertificate - var r AccessMutualTLSCertificateListResponse + var lastResultInfo *ResultInfo = nil for { uri := buildURI(baseURL, params) @@ -91,11 +91,13 @@ func (api *API) ListAccessMutualTLSCertificates(ctx context.Context, rc *Resourc if err != nil { return []AccessMutualTLSCertificate{}, &ResultInfo{}, fmt.Errorf("%s: %w", errMakeRequestError, err) } + var r AccessMutualTLSCertificateListResponse err = json.Unmarshal(res, &r) if err != nil { return []AccessMutualTLSCertificate{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + lastResultInfo = &r.ResultInfo accessCertificates = append(accessCertificates, r.Result...) params.ResultInfo = r.ResultInfo.Next() if params.ResultInfo.Done() || !autoPaginate { @@ -103,7 +105,7 @@ func (api *API) ListAccessMutualTLSCertificates(ctx context.Context, rc *Resourc } } - return accessCertificates, &r.ResultInfo, nil + return accessCertificates, lastResultInfo, nil } // GetAccessMutualTLSCertificate returns a single Access Mutual TLS diff --git a/access_policy.go b/access_policy.go index 0e1ae41c6d2..2bafa1ff5de 100644 --- a/access_policy.go +++ b/access_policy.go @@ -167,18 +167,20 @@ func (api *API) ListAccessPolicies(ctx context.Context, rc *ResourceContainer, p } var accessPolicies []AccessPolicy - var r AccessPolicyListResponse + var lastResultInfo *ResultInfo = nil for { uri := buildURI(baseURL, params) res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) if err != nil { return []AccessPolicy{}, &ResultInfo{}, fmt.Errorf("%s: %w", errMakeRequestError, err) } + var r AccessPolicyListResponse err = json.Unmarshal(res, &r) if err != nil { return []AccessPolicy{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + lastResultInfo = &r.ResultInfo accessPolicies = append(accessPolicies, r.Result...) params.ResultInfo = r.ResultInfo.Next() if params.ResultInfo.Done() || !autoPaginate { @@ -186,7 +188,7 @@ func (api *API) ListAccessPolicies(ctx context.Context, rc *ResourceContainer, p } } - return accessPolicies, &r.ResultInfo, nil + return accessPolicies, lastResultInfo, nil } // GetAccessPolicy returns a single policy based on the policy ID. diff --git a/access_users.go b/access_users.go index 233ceb2bb67..a94c26ddc2f 100644 --- a/access_users.go +++ b/access_users.go @@ -223,7 +223,7 @@ func (api *API) ListAccessUsers(ctx context.Context, rc *ResourceContainer, para } var accessUsers []AccessUser - var resultInfo *ResultInfo = nil + var lastResultInfo *ResultInfo = nil for { uri := buildURI(baseURL, params) @@ -232,12 +232,12 @@ func (api *API) ListAccessUsers(ctx context.Context, rc *ResourceContainer, para return []AccessUser{}, &ResultInfo{}, fmt.Errorf("%s: %w", errMakeRequestError, err) } var r AccessUserListResponse - resultInfo = &r.ResultInfo err = json.Unmarshal(res, &r) if err != nil { return []AccessUser{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + lastResultInfo = &r.ResultInfo accessUsers = append(accessUsers, r.Result...) params.ResultInfo = r.ResultInfo.Next() if params.ResultInfo.Done() || !autoPaginate { @@ -245,7 +245,7 @@ func (api *API) ListAccessUsers(ctx context.Context, rc *ResourceContainer, para } } - return accessUsers, resultInfo, nil + return accessUsers, lastResultInfo, nil } // GetAccessUserActiveSessions returns a list of active sessions for an user. diff --git a/account_roles.go b/account_roles.go index d216ae3105b..7b5e41c0616 100644 --- a/account_roles.go +++ b/account_roles.go @@ -64,7 +64,6 @@ func (api *API) ListAccountRoles(ctx context.Context, rc *ResourceContainer, par params.Page = 1 } var roles []AccountRole - var r AccountRolesListResponse for { uri := buildURI(fmt.Sprintf("/accounts/%s/roles", rc.Identifier), params) @@ -72,6 +71,7 @@ func (api *API) ListAccountRoles(ctx context.Context, rc *ResourceContainer, par if err != nil { return []AccountRole{}, err } + var r AccountRolesListResponse err = json.Unmarshal(res, &r) if err != nil { diff --git a/d1.go b/d1.go index 08a3ecc51fb..d3b8e805b0d 100644 --- a/d1.go +++ b/d1.go @@ -90,25 +90,27 @@ func (api *API) ListD1Databases(ctx context.Context, rc *ResourceContainer, para params.Page = 1 } var databases []D1Database - var r ListD1Response + var lastResultInfo *ResultInfo = nil for { uri := buildURI(baseURL, params) res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) if err != nil { return []D1Database{}, &ResultInfo{}, fmt.Errorf("%s: %w", errMakeRequestError, err) } + var r ListD1Response err = json.Unmarshal(res, &r) if err != nil { return []D1Database{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + lastResultInfo = &r.ResultInfo databases = append(databases, r.Result...) params.ResultInfo = r.ResultInfo.Next() if params.ResultInfo.Done() || !autoPaginate { break } } - return databases, &r.ResultInfo, nil + return databases, lastResultInfo, nil } // CreateD1Database creates a new database for an account. diff --git a/pages_deployment.go b/pages_deployment.go index b81a2c1b77a..0b3831ba6a8 100644 --- a/pages_deployment.go +++ b/pages_deployment.go @@ -147,7 +147,7 @@ func (api *API) ListPagesDeployments(ctx context.Context, rc *ResourceContainer, } var deployments []PagesProjectDeployment - var r pagesDeploymentListResponse + var lastResultInfo *ResultInfo = nil for { uri := buildURI(fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments", rc.Identifier, params.ProjectName), params) @@ -155,17 +155,19 @@ func (api *API) ListPagesDeployments(ctx context.Context, rc *ResourceContainer, if err != nil { return []PagesProjectDeployment{}, &ResultInfo{}, err } + var r pagesDeploymentListResponse err = json.Unmarshal(res, &r) if err != nil { return []PagesProjectDeployment{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + lastResultInfo = &r.ResultInfo deployments = append(deployments, r.Result...) params.ResultInfo = r.ResultInfo.Next() if params.Done() || !autoPaginate { break } } - return deployments, &r.ResultInfo, nil + return deployments, lastResultInfo, nil } // GetPagesDeploymentInfo returns a deployment for a Pages project. diff --git a/tunnel.go b/tunnel.go index 2f3f6d7c90d..2b28143069a 100644 --- a/tunnel.go +++ b/tunnel.go @@ -249,7 +249,7 @@ func (api *API) ListTunnels(ctx context.Context, rc *ResourceContainer, params T } var records []Tunnel - var listResponse TunnelsDetailResponse + var lastResultInfo *ResultInfo = nil for { uri := buildURI(fmt.Sprintf("/accounts/%s/cfd_tunnel", rc.Identifier), params) @@ -258,10 +258,12 @@ func (api *API) ListTunnels(ctx context.Context, rc *ResourceContainer, params T return []Tunnel{}, &ResultInfo{}, err } + var listResponse TunnelsDetailResponse err = json.Unmarshal(res, &listResponse) if err != nil { return []Tunnel{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + lastResultInfo = &listResponse.ResultInfo records = append(records, listResponse.Result...) params.ResultInfo = listResponse.ResultInfo.Next() @@ -270,7 +272,7 @@ func (api *API) ListTunnels(ctx context.Context, rc *ResourceContainer, params T } } - return records, &listResponse.ResultInfo, nil + return records, lastResultInfo, nil } // GetTunnel returns a single Argo tunnel. diff --git a/turnstile.go b/turnstile.go index 5bc9273cd9d..836d121315b 100644 --- a/turnstile.go +++ b/turnstile.go @@ -110,7 +110,7 @@ func (api *API) ListTurnstileWidgets(ctx context.Context, rc *ResourceContainer, } var widgets []TurnstileWidget - var r ListTurnstileWidgetResponse + var lastResultInfo *ResultInfo = nil for { uri := buildURI(fmt.Sprintf("/accounts/%s/challenges/widgets", rc.Identifier), params) res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) @@ -118,10 +118,12 @@ func (api *API) ListTurnstileWidgets(ctx context.Context, rc *ResourceContainer, if err != nil { return []TurnstileWidget{}, &ResultInfo{}, fmt.Errorf("%s: %w", errMakeRequestError, err) } + var r ListTurnstileWidgetResponse err = json.Unmarshal(res, &r) if err != nil { return []TurnstileWidget{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + lastResultInfo = &r.ResultInfo widgets = append(widgets, r.Result...) params.ResultInfo = r.ResultInfo.Next() @@ -130,7 +132,7 @@ func (api *API) ListTurnstileWidgets(ctx context.Context, rc *ResourceContainer, } } - return widgets, &r.ResultInfo, nil + return widgets, lastResultInfo, nil } // GetTurnstileWidget shows a single challenge widget configuration.