Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple access application pages result in bad data returned #1447

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions access_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -231,18 +231,20 @@ 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 {
break
}
}

return applications, &r.ResultInfo, nil
return applications, &lastResultInfo, nil
}

// GetAccessApplication returns a single application based on the application
Expand Down
6 changes: 4 additions & 2 deletions access_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,26 +167,28 @@ 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)
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 {
break
}
}

return accessPolicies, &r.ResultInfo, nil
return accessPolicies, &lastResultInfo, nil
}

// GetAccessPolicy returns a single policy based on the policy ID.
Expand Down
6 changes: 4 additions & 2 deletions tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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.
Expand Down
Loading