Skip to content

Commit

Permalink
fix: update api client on login
Browse files Browse the repository at this point in the history
previously our tests were not catching this problem because of the return nil.

With that fixed, the tests fail properly.
  • Loading branch information
dnephin committed Jun 14, 2022
1 parent 164153d commit fb97288
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ $ infra use development.kube-system`,
return err
}

err = updateKubeconfig(client, id)
err = updateKubeConfig(client, id)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func kubernetesSetContext(cluster, namespace string) error {
return nil
}

func updateKubeconfig(client *api.Client, id uid.ID) error {
func updateKubeConfig(client *api.Client, id uid.ID) error {
destinations, err := client.ListDestinations(api.ListDestinationsRequest{})
if err != nil {
return nil
return err
}

user, err := client.GetUser(id)
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ func loginToInfra(cli *CLI, lc loginClient, loginReq *api.LoginRequest, noAgent

return err
}
// Update the API client with the new access key from login
lc.APIClient.AccessKey = loginRes.AccessKey

if loginRes.PasswordUpdateRequired {
fmt.Fprintf(cli.Stderr, " Your password has expired. Please update your password (min. length 8).\n")
Expand All @@ -216,7 +218,6 @@ func loginToInfra(cli *CLI, lc loginClient, loginReq *api.LoginRequest, noAgent
}

logging.S.Debugf("call server: update user %s", loginRes.UserID)
lc.APIClient.AccessKey = loginRes.AccessKey
if _, err := lc.APIClient.UpdateUser(&api.UpdateUserRequest{ID: loginRes.UserID, Password: password}); err != nil {
return err
}
Expand All @@ -228,7 +229,7 @@ func loginToInfra(cli *CLI, lc loginClient, loginReq *api.LoginRequest, noAgent
return err
}

if err := updateKubeconfig(lc.APIClient, loginRes.UserID); err != nil {
if err := updateKubeConfig(lc.APIClient, loginRes.UserID); err != nil {
return err
}

Expand Down

0 comments on commit fb97288

Please sign in to comment.