Skip to content

Commit f6633b3

Browse files
committed
addressing comments
1 parent c3d262f commit f6633b3

File tree

4 files changed

+48
-38
lines changed

4 files changed

+48
-38
lines changed

cmd/ping.go

+41-34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
"fmt"
56
"net/url"
67

@@ -20,43 +21,11 @@ can connect to Kong's Admin API.`,
2021
Args: validateNoArgs,
2122
RunE: func(cmd *cobra.Command, args []string) error {
2223
ctx := cmd.Context()
23-
cmdStr := "ping"
24-
var version string
25-
var err error
2624
mode := getMode(nil)
2725
if mode == modeKonnect {
28-
// get Konnect client
29-
httpClient := utils.HTTPClient()
30-
konnectClient, err := utils.GetKonnectClient(httpClient, konnectConfig)
31-
if err != nil {
32-
return err
33-
}
34-
u, _ := url.Parse(konnectConfig.Address)
35-
// authenticate with konnect
36-
res, err := authenticate(ctx, konnectClient, u.Host)
37-
if err != nil {
38-
return fmt.Errorf("authenticating with Konnect: %w", err)
39-
}
40-
fullName := res.FullName
41-
if res.FullName == "" {
42-
fullName = fmt.Sprintf("%s %s", res.FirstName, res.LastName)
43-
}
44-
fmt.Printf("Successfully Konnected as %s (%s)!\n",
45-
fullName, res.Organization)
46-
if konnectConfig.Debug {
47-
fmt.Printf("Organization ID: %s\n", res.OrganizationID)
48-
}
49-
} else {
50-
wsConfig := rootConfig.ForWorkspace(pingWorkspace)
51-
version, err = fetchKongVersion(ctx, wsConfig)
52-
if err != nil {
53-
return fmt.Errorf("reading Kong version: %w", err)
54-
}
55-
fmt.Println("Successfully connected to Kong!")
56-
fmt.Println("Kong version: ", version)
26+
return pingKonnect(ctx)
5727
}
58-
_ = sendAnalytics(cmdStr, version, mode)
59-
return nil
28+
return pingKong(ctx)
6029
},
6130
}
6231

@@ -66,3 +35,41 @@ can connect to Kong's Admin API.`,
6635
"Useful when RBAC permissions are scoped to a Workspace.")
6736
return pingCmd
6837
}
38+
39+
func pingKonnect(ctx context.Context) error {
40+
// get Konnect client
41+
httpClient := utils.HTTPClient()
42+
konnectClient, err := utils.GetKonnectClient(httpClient, konnectConfig)
43+
if err != nil {
44+
return err
45+
}
46+
u, _ := url.Parse(konnectConfig.Address)
47+
// authenticate with konnect
48+
res, err := authenticate(ctx, konnectClient, u.Host)
49+
if err != nil {
50+
return fmt.Errorf("authenticating with Konnect: %w", err)
51+
}
52+
fullName := res.FullName
53+
if res.FullName == "" {
54+
fullName = fmt.Sprintf("%s %s", res.FirstName, res.LastName)
55+
}
56+
fmt.Printf("Successfully Konnected as %s (%s)!\n",
57+
fullName, res.Organization)
58+
if konnectConfig.Debug {
59+
fmt.Printf("Organization ID: %s\n", res.OrganizationID)
60+
}
61+
_ = sendAnalytics("ping", "", modeKonnect)
62+
return nil
63+
}
64+
65+
func pingKong(ctx context.Context) error {
66+
wsConfig := rootConfig.ForWorkspace(pingWorkspace)
67+
version, err := fetchKongVersion(ctx, wsConfig)
68+
if err != nil {
69+
return fmt.Errorf("reading Kong version: %w", err)
70+
}
71+
fmt.Println("Successfully connected to Kong!")
72+
fmt.Println("Kong version: ", version)
73+
_ = sendAnalytics("ping", version, modeKong)
74+
return nil
75+
}

file/reader.go

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ func Get(ctx context.Context, fileContent *Content, opt RenderConfig, dumpConfig
7878
builder.client = wsClient
7979
builder.ctx = ctx
8080
builder.skipCACerts = dumpConfig.SkipCACerts
81+
// Konnect doesn't support the schema endpoint yet,
82+
// therefore dynamic defaults injection must be disabled
8183
if dumpConfig.KonnectRuntimeGroup != "" {
8284
builder.disableDynamicDefaults = true
8385
}

konnect/login_service.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package konnect
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
67
"net/http/cookiejar"
78
"net/url"
@@ -61,12 +62,12 @@ func (s *AuthService) LoginV2(ctx context.Context, email,
6162
}
6263
req, err := s.client.NewRequest(http.MethodPost, authEndpointV2, nil, body)
6364
if err != nil {
64-
return AuthResponse{}, err
65+
return AuthResponse{}, fmt.Errorf("build http request: %v", err)
6566
}
6667
var authResponse AuthResponse
6768
resp, err := s.client.Do(ctx, req, &authResponse)
6869
if err != nil {
69-
return AuthResponse{}, err
70+
return AuthResponse{}, fmt.Errorf("authenticate http request: %v", err)
7071
}
7172
url, _ := url.Parse(s.client.baseURL)
7273
jar, err := cookiejar.New(nil)
@@ -79,7 +80,7 @@ func (s *AuthService) LoginV2(ctx context.Context, email,
7980

8081
info, err := s.UserInfo(ctx)
8182
if err != nil {
82-
return AuthResponse{}, err
83+
return AuthResponse{}, fmt.Errorf("fetch user-info: %v", err)
8384
}
8485
authResponse.FullName = info.Profile.FullName
8586
authResponse.Organization = info.Org.Name

utils/analytics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func collectStats(cmd, deckVersion, kongVersion, mode string) map[string]string
6565
if mode == konnectMode {
6666
result["mode"] = mode
6767
}
68-
if kongVersion != "" || mode != konnectMode {
68+
if kongVersion != "" && mode != konnectMode {
6969
result["kv"] = kongVersion
7070
}
7171
info, err := host.Info()

0 commit comments

Comments
 (0)