Skip to content
Open
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/iancoleman/strcase v0.3.0
github.com/ianlancetaylor/demangle v0.0.0-20260505044615-1ff4bf46051f
github.com/launchdarkly/api-client-go/v14 v14.0.0
github.com/launchdarkly/api-client-go/v24 v24.0.0
github.com/launchdarkly/go-sdk-common/v3 v3.4.0
github.com/launchdarkly/go-server-sdk/v7 v7.13.4
github.com/launchdarkly/sdk-meta/api v0.4.8
Expand Down Expand Up @@ -108,10 +108,10 @@ require (
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/mod v0.33.0 // indirect
golang.org/x/net v0.50.0 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
golang.org/x/tools v0.42.0 // indirect
gopkg.in/validator.v2 v2.0.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
314 changes: 4 additions & 310 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package client
import (
"fmt"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"
)

// New creates an LD API client. It's not set as a field on the struct because the CLI flags
Expand Down
28 changes: 28 additions & 0 deletions internal/client/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package client_test

import (
"context"
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/launchdarkly/ldcli/internal/client"
)

func TestNewSendsAPIVersion(t *testing.T) {
var got []string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
got = r.Header.Values("LD-API-Version")
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"_links": {}, "items": []}`))
}))
defer server.Close()

_, _, err := client.New("token", server.URL, "test-version").ProjectsApi.GetProjects(context.Background()).Execute()

require.NoError(t, err)
assert.Equal(t, []string{"20240415"}, got)
}
2 changes: 1 addition & 1 deletion internal/dev_server/adapters/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/launchdarkly/ldcli/internal/dev_server/adapters/internal"
"github.com/pkg/errors"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"
)

const ctxKeyApi = ctxKey("adapters.api")
Expand Down
2 changes: 1 addition & 1 deletion internal/dev_server/adapters/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"
)

func WithApiAndSdk(ctx context.Context, client ldapi.APIClient, streamingUrl string, sdkInitTimeout time.Duration) context.Context {
Expand Down
2 changes: 1 addition & 1 deletion internal/dev_server/adapters/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"time"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"
)

type ctxKey string
Expand Down
2 changes: 1 addition & 1 deletion internal/dev_server/adapters/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/dev_server/model/fill_variations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"
"github.com/launchdarkly/ldcli/internal/dev_server/adapters"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/dev_server/model/fill_variations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"testing"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"
"github.com/launchdarkly/go-sdk-common/v3/ldvalue"
"github.com/launchdarkly/go-server-sdk/v7/interfaces/flagstate"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion internal/dev_server/model/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/pkg/errors"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"
"github.com/launchdarkly/go-sdk-common/v3/ldcontext"
"github.com/launchdarkly/go-sdk-common/v3/ldvalue"
"github.com/launchdarkly/ldcli/internal/dev_server/adapters"
Expand Down
2 changes: 1 addition & 1 deletion internal/dev_server/model/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"
"github.com/launchdarkly/go-sdk-common/v3/ldcontext"
"github.com/launchdarkly/go-sdk-common/v3/ldvalue"
"github.com/launchdarkly/go-server-sdk/v7/interfaces/flagstate"
Expand Down
2 changes: 1 addition & 1 deletion internal/dev_server/model/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"
"github.com/launchdarkly/go-sdk-common/v3/ldcontext"
"github.com/launchdarkly/go-sdk-common/v3/ldvalue"
"github.com/launchdarkly/go-server-sdk/v7/interfaces/flagstate"
Expand Down
2 changes: 1 addition & 1 deletion internal/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"testing"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down
4 changes: 2 additions & 2 deletions internal/flags/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"fmt"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"

"github.com/launchdarkly/ldcli/internal/client"
"github.com/launchdarkly/ldcli/internal/errors"
Expand Down Expand Up @@ -131,7 +131,7 @@ func (c FlagsClient) Update(
client := client.New(accessToken, baseURI, c.cliVersion)
patch := []ldapi.PatchOperation{}
for _, i := range input {
patch = append(patch, *ldapi.NewPatchOperation(i.Op, i.Path, i.Value))
patch = append(patch, ldapi.PatchOperation{Op: i.Op, Path: i.Path, Value: i.Value})
}
flag, _, err := client.FeatureFlagsApi.
PatchFeatureFlag(ctx, projKey, key).
Expand Down
2 changes: 1 addition & 1 deletion internal/members/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"

"github.com/launchdarkly/ldcli/internal/client"
"github.com/launchdarkly/ldcli/internal/errors"
Expand Down
2 changes: 1 addition & 1 deletion internal/projects/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"

ldapi "github.com/launchdarkly/api-client-go/v14"
ldapi "github.com/launchdarkly/api-client-go/v24"

"github.com/launchdarkly/ldcli/internal/client"
"github.com/launchdarkly/ldcli/internal/errors"
Expand Down
6 changes: 6 additions & 0 deletions internal/resources/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"github.com/launchdarkly/ldcli/internal/errors"
)

// apiVersion is the LaunchDarkly REST API version sent with non-beta requests, so
// responses don't depend on the default version stored on the caller's access token.
const apiVersion = "20240415"

type UnauthenticatedClient interface {
MakeUnauthenticatedRequest(
method string,
Expand Down Expand Up @@ -56,6 +60,8 @@ func (c ResourcesClient) MakeRequest(
req.Header.Set("User-Agent", fmt.Sprintf("launchdarkly-cli/v%s", c.cliVersion))
if isBeta {
req.Header.Set("LD-API-Version", "beta")
} else {
req.Header.Set("LD-API-Version", apiVersion)
}
req.URL.RawQuery = query.Encode()

Expand Down
26 changes: 26 additions & 0 deletions internal/resources/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,32 @@ func TestMakeUnauthenticatedRequest(t *testing.T) {
})
}

func TestMakeRequestAPIVersion(t *testing.T) {
tests := map[string]struct {
isBeta bool
expected string
}{
"non-beta requests send the current API version": {isBeta: false, expected: "20240415"},
"beta requests send beta": {isBeta: true, expected: "beta"},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
var got []string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
got = r.Header.Values("LD-API-Version")
w.WriteHeader(http.StatusOK)
}))
defer server.Close()
c := resources.NewClient("test-version")

_, err := c.MakeRequest("token", "GET", server.URL, "application/json", nil, nil, tt.isBeta)

require.NoError(t, err)
assert.Equal(t, []string{tt.expected}, got)
})
}
}

func makeServer(t *testing.T, statusResponse int, responseBody string) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
Expand Down
Loading