diff --git a/access_application.go b/access_application.go index 6e62b2de2eb..4e73fdaa153 100644 --- a/access_application.go +++ b/access_application.go @@ -221,7 +221,7 @@ func (api *API) ListAccessApplications(ctx context.Context, rc *ResourceContaine } var applications []AccessApplication - var r AccessApplicationListResponse + var lastResultInfo ResultInfo for { uri := buildURI(baseURL, params) @@ -231,10 +231,12 @@ func (api *API) ListAccessApplications(ctx context.Context, rc *ResourceContaine 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 { @@ -242,7 +244,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_policy.go b/access_policy.go index 0e1ae41c6d2..c8fcb8de2b7 100644 --- a/access_policy.go +++ b/access_policy.go @@ -167,7 +167,7 @@ func (api *API) ListAccessPolicies(ctx context.Context, rc *ResourceContainer, p } var accessPolicies []AccessPolicy - var r AccessPolicyListResponse + var lastResultInfo ResultInfo for { uri := buildURI(baseURL, params) res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) @@ -175,10 +175,12 @@ func (api *API) ListAccessPolicies(ctx context.Context, rc *ResourceContainer, p 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/tunnel.go b/tunnel.go index 2f3f6d7c90d..f9fdc9f28a1 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 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.