Skip to content

Commit e5c3534

Browse files
committed
feat: replace deprecated endpoint for pinging Konnect
1 parent f03e00d commit e5c3534

File tree

5 files changed

+43
-31
lines changed

5 files changed

+43
-31
lines changed

cmd/ping.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,8 @@ func pingKonnect(ctx context.Context) error {
5353
if err != nil {
5454
return fmt.Errorf("authenticating with Konnect: %w", err)
5555
}
56-
fullName := res.FullName
57-
if res.FullName == "" {
58-
fullName = fmt.Sprintf("%s %s", res.FirstName, res.LastName)
59-
}
60-
fmt.Printf("Successfully Konnected as %s (%s)!\n",
61-
fullName, res.Organization)
56+
57+
fmt.Printf("Successfully Konnected to the %s organization!\n", res.Name)
6258
if konnectConfig.Debug {
6359
fmt.Printf("Organization ID: %s\n", res.OrganizationID)
6460
}

konnect/login_service.go

+9-21
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,9 @@ import (
1111
"strings"
1212
)
1313

14-
type user struct {
15-
FullName string `json:"full_name,omitempty"`
16-
}
17-
18-
type org struct {
19-
ID string
20-
Name string
21-
}
22-
23-
type UserInfo struct {
24-
Profile user
25-
ID string
26-
Email string
27-
Org org
14+
type OrgUserInfo struct {
15+
Name string `json:"name,omitempty"`
16+
OrgID string `json:"id,omitempty"`
2817
}
2918

3019
type AuthService service
@@ -128,24 +117,23 @@ func (s *AuthService) LoginV2(ctx context.Context, email,
128117
)
129118
}
130119

131-
info, err := s.UserInfo(ctx)
120+
info, err := s.OrgUserInfo(ctx)
132121
if err != nil {
133122
return AuthResponse{}, err
134123
}
135-
authResponse.FullName = info.Profile.FullName
136-
authResponse.Organization = info.Org.Name
137-
authResponse.OrganizationID = info.Org.ID
124+
authResponse.Name = info.Name
125+
authResponse.OrganizationID = info.OrgID
138126
return authResponse, nil
139127
}
140128

141-
func (s *AuthService) UserInfo(ctx context.Context) (*UserInfo, error) {
129+
func (s *AuthService) OrgUserInfo(ctx context.Context) (*OrgUserInfo, error) {
142130
method := http.MethodGet
143-
req, err := s.client.NewRequest(method, "/konnect-api/api/userinfo/", nil, nil)
131+
req, err := s.client.NewRequest(method, "/v2/organizations/me", nil, nil)
144132
if err != nil {
145133
return nil, err
146134
}
147135

148-
info := &UserInfo{}
136+
info := &OrgUserInfo{}
149137
_, err = s.client.Do(ctx, req, info)
150138
if err != nil {
151139
return nil, err

konnect/types.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,12 @@ type ControlPlaneType struct {
137137

138138
// AuthResponse is authentication response wrapper for login.
139139
type AuthResponse struct {
140-
Organization string `json:"org_name"`
141-
FirstName string `json:"first_name"`
142-
LastName string `json:"last_name"`
140+
Name string `json:"name"`
143141
OrganizationID string `json:"org_id"`
144142

145-
FullName string `json:"full_name"`
143+
// deprecated fields
144+
Organization string `json:"org_name"`
145+
FirstName string `json:"first_name"`
146+
LastName string `json:"last_name"`
147+
FullName string `json:"full_name"`
146148
}

tests/integration/ping_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build integration
2+
3+
package integration
4+
5+
import (
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func Test_KonnectPing(t *testing.T) {
12+
t.Run("konnect ping", func(t *testing.T) {
13+
runWhen(t, "konnect", "")
14+
require.NoError(t, ping())
15+
})
16+
}

tests/integration/test_utils.go

+10
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,13 @@ func dump(opts ...string) (string, error) {
261261

262262
return string(out), cmdErr
263263
}
264+
265+
func ping(opts ...string) error {
266+
deckCmd := cmd.NewRootCmd()
267+
args := []string{"ping"}
268+
if len(opts) > 0 {
269+
args = append(args, opts...)
270+
}
271+
deckCmd.SetArgs(args)
272+
return deckCmd.ExecuteContext(context.Background())
273+
}

0 commit comments

Comments
 (0)