Skip to content

Commit a7385e8

Browse files
authored
[REL-6409] update API version and client (#504)
<!-- ld-jira-link --> --- Related Jira issue: [REL-6409: Bump ld API version in ld-find-code-refs](https://launchdarkly.atlassian.net/browse/REL-6409) <!-- end-ld-jira-link -->
1 parent 3a24ad6 commit a7385e8

File tree

1,006 files changed

+188437
-148335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,006 files changed

+188437
-148335
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
)
2222

2323
require (
24-
github.com/launchdarkly/api-client-go/v15 v15.1.0
24+
github.com/launchdarkly/api-client-go/v17 v17.2.0
2525
github.com/wasilibs/go-re2 v1.10.0
2626
)
2727

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
166166
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
167167
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
168168
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
169-
github.com/launchdarkly/api-client-go/v15 v15.1.0 h1:SSBqU4x36OWJql7uKuEl6awsPNC3bMFWSiDI/s3OD/I=
170-
github.com/launchdarkly/api-client-go/v15 v15.1.0/go.mod h1:7dpsX/epfhhRbCv5sEIxKng0xxYbzRYXlp0oJB3+XrQ=
169+
github.com/launchdarkly/api-client-go/v17 v17.2.0 h1:5CJxDaL7ZgqALAcohNUMlV7hfXR65s2czZ4XmZjW/qI=
170+
github.com/launchdarkly/api-client-go/v17 v17.2.0/go.mod h1:lMTmhEjepXfam8xm8b0ERBJbV9g8vdu9nbKueDXcB5o=
171171
github.com/launchdarkly/json-patch v0.0.0-20180720210516-dd68d883319f h1:jfiPiz2hE/7mHv2NOS4cm07sSJCsKlbxmR7pzPhhvpU=
172172
github.com/launchdarkly/json-patch v0.0.0-20180720210516-dd68d883319f/go.mod h1:CHbYdMs8UjvNnS2fatlQvi4UYnBTRYGxRHc/0kQupSQ=
173173
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=

internal/ld/ld.go

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
h "github.com/hashicorp/go-retryablehttp"
2121
"github.com/olekukonko/tablewriter"
2222

23-
ldapi "github.com/launchdarkly/api-client-go/v15"
23+
ldapi "github.com/launchdarkly/api-client-go/v17"
2424
jsonpatch "github.com/launchdarkly/json-patch"
2525
"github.com/launchdarkly/ld-find-code-refs/v2/internal/log"
2626
"github.com/launchdarkly/ld-find-code-refs/v2/internal/validation"
@@ -40,7 +40,7 @@ type ApiOptions struct {
4040
}
4141

4242
const (
43-
apiVersion = "20220603"
43+
apiVersion = "20240415"
4444
apiVersionHeader = "LD-API-Version"
4545
v2ApiPath = "/api/v2"
4646
reposPath = "/code-refs/repositories"
@@ -122,6 +122,10 @@ func (c ApiClient) getPath(path string) string {
122122
return fmt.Sprintf("%s%s%s", c.Options.BaseUri, v2ApiPath, path)
123123
}
124124

125+
func (c ApiClient) getPathFromLink(path string) string {
126+
return fmt.Sprintf("%s%s", c.Options.BaseUri, path)
127+
}
128+
125129
func (c ApiClient) GetFlagKeyList(projKey string, skipArchivedFlags bool) ([]string, error) {
126130
env, err := c.getProjectEnvironment(projKey)
127131
if err != nil {
@@ -202,32 +206,53 @@ func (c ApiClient) getProjectEnvironment(projKey string) (*ldapi.Environment, er
202206
}
203207

204208
func (c ApiClient) getFlags(projKey string, params url.Values) ([]ldapi.FeatureFlag, error) {
205-
url := c.getPath(fmt.Sprintf("/flags/%s", projKey)) //nolint:perfsprint
206-
req, err := h.NewRequest(http.MethodGet, url, nil)
207-
if err != nil {
208-
return nil, err
209+
// If no limit is set, use the maximum allowed
210+
if params.Get("limit") == "" {
211+
params.Set("limit", "100")
209212
}
210-
req.URL.RawQuery = params.Encode()
211213

212-
res, err := c.do(req)
213-
if err != nil {
214-
return nil, err
215-
}
214+
var allFlags []ldapi.FeatureFlag
215+
nextUrl := c.getPath(fmt.Sprintf("/flags/%s", projKey)) //nolint:perfsprint
216+
for nextUrl != "" {
217+
req, err := h.NewRequest(http.MethodGet, nextUrl, nil)
218+
if err != nil {
219+
return nil, err
220+
}
216221

217-
resBytes, err := io.ReadAll(res.Body)
218-
if res != nil {
219-
defer res.Body.Close()
220-
}
221-
if err != nil {
222-
return nil, err
223-
}
222+
if nextUrl == c.getPath(fmt.Sprintf("/flags/%s", projKey)) { //nolint:perfsprint
223+
req.URL.RawQuery = params.Encode()
224+
}
224225

225-
var flags ldapi.FeatureFlags
226-
if err := json.Unmarshal(resBytes, &flags); err != nil {
227-
return nil, err
226+
log.Info.Printf("Requesting flags from %s", nextUrl)
227+
res, err := c.do(req)
228+
if err != nil {
229+
return nil, err
230+
}
231+
232+
resBytes, err := io.ReadAll(res.Body)
233+
if res != nil {
234+
defer res.Body.Close()
235+
}
236+
if err != nil {
237+
return nil, err
238+
}
239+
var flagsPage ldapi.FeatureFlags
240+
if err := json.Unmarshal(resBytes, &flagsPage); err != nil {
241+
return nil, err
242+
}
243+
244+
allFlags = append(allFlags, flagsPage.Items...)
245+
if flagsPage.TotalCount != nil && len(allFlags) >= int(*flagsPage.TotalCount) {
246+
break
247+
}
248+
249+
nextLink, ok := flagsPage.Links["next"]
250+
if ok {
251+
nextUrl = c.getPathFromLink(*nextLink.Href)
252+
}
228253
}
229254

230-
return flags.Items, nil
255+
return allFlags, nil
231256
}
232257

233258
func (c ApiClient) patchCodeReferenceRepository(currentRepo, repo RepoParams) error {

vendor/github.com/launchdarkly/api-client-go/v15/api_access_tokens.go

Lines changed: 0 additions & 1024 deletions
This file was deleted.

vendor/github.com/launchdarkly/api-client-go/v15/api_account_members.go

Lines changed: 0 additions & 1139 deletions
This file was deleted.

vendor/github.com/launchdarkly/api-client-go/v15/api_account_members_beta.go

Lines changed: 0 additions & 319 deletions
This file was deleted.

vendor/github.com/launchdarkly/api-client-go/v15/api_account_usage_beta.go

Lines changed: 0 additions & 2297 deletions
This file was deleted.

vendor/github.com/launchdarkly/api-client-go/v15/api_applications_beta.go

Lines changed: 0 additions & 1295 deletions
This file was deleted.

vendor/github.com/launchdarkly/api-client-go/v15/api_approvals.go

Lines changed: 0 additions & 2338 deletions
This file was deleted.

vendor/github.com/launchdarkly/api-client-go/v15/api_audit_log.go

Lines changed: 0 additions & 391 deletions
This file was deleted.

0 commit comments

Comments
 (0)