Skip to content

Commit

Permalink
feat: replace deprecated endpoint for pinging Konnect
Browse files Browse the repository at this point in the history
  • Loading branch information
GGabriele committed Feb 9, 2023
1 parent f03e00d commit d626d97
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
8 changes: 2 additions & 6 deletions cmd/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ func pingKonnect(ctx context.Context) error {
if err != nil {
return fmt.Errorf("authenticating with Konnect: %w", err)
}
fullName := res.FullName
if res.FullName == "" {
fullName = fmt.Sprintf("%s %s", res.FirstName, res.LastName)
}
fmt.Printf("Successfully Konnected as %s (%s)!\n",
fullName, res.Organization)

fmt.Printf("Successfully Konnected as %s organization!\n", res.Name)
if konnectConfig.Debug {
fmt.Printf("Organization ID: %s\n", res.OrganizationID)
}
Expand Down
30 changes: 9 additions & 21 deletions konnect/login_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,9 @@ import (
"strings"
)

type user struct {
FullName string `json:"full_name,omitempty"`
}

type org struct {
ID string
Name string
}

type UserInfo struct {
Profile user
ID string
Email string
Org org
type OrgUserInfo struct {
Name string `json:"name,omitempty"`
OrgID string `json:"id,omitempty"`
}

type AuthService service
Expand Down Expand Up @@ -128,24 +117,23 @@ func (s *AuthService) LoginV2(ctx context.Context, email,
)
}

info, err := s.UserInfo(ctx)
info, err := s.OrgUserInfo(ctx)
if err != nil {
return AuthResponse{}, err
}
authResponse.FullName = info.Profile.FullName
authResponse.Organization = info.Org.Name
authResponse.OrganizationID = info.Org.ID
authResponse.Name = info.Name
authResponse.OrganizationID = info.OrgID
return authResponse, nil
}

func (s *AuthService) UserInfo(ctx context.Context) (*UserInfo, error) {
func (s *AuthService) OrgUserInfo(ctx context.Context) (*OrgUserInfo, error) {
method := http.MethodGet
req, err := s.client.NewRequest(method, "/konnect-api/api/userinfo/", nil, nil)
req, err := s.client.NewRequest(method, "/v2/organizations/me", nil, nil)
if err != nil {
return nil, err
}

info := &UserInfo{}
info := &OrgUserInfo{}
_, err = s.client.Do(ctx, req, info)
if err != nil {
return nil, err
Expand Down
10 changes: 6 additions & 4 deletions konnect/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ type ControlPlaneType struct {

// AuthResponse is authentication response wrapper for login.
type AuthResponse struct {
Organization string `json:"org_name"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Name string `json:"name"`
OrganizationID string `json:"org_id"`

FullName string `json:"full_name"`
// deprecated fields
Organization string `json:"org_name"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
FullName string `json:"full_name"`
}

0 comments on commit d626d97

Please sign in to comment.