Skip to content

Commit

Permalink
Add user id to context config (#1962)
Browse files Browse the repository at this point in the history
* Add user id to context config

Signed-off-by: Javier López Barba <javier@okteto.com>

* Add comment clarifying the code to save context

Signed-off-by: Javier López Barba <javier@okteto.com>

* Run onnly if the context is an okteto context

Signed-off-by: Javier López Barba <javier@okteto.com>
  • Loading branch information
jLopezbarb committed Nov 16, 2021
1 parent c1921b9 commit 20236f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions cmd/context/use.go
Expand Up @@ -152,6 +152,17 @@ func getUserContext(ctx context.Context) (*okteto.UserContext, error) {
retries := 0
for retries <= 3 {
userContext, err := client.GetUserContext(ctx)

// If userID is not on context config file we add it and save it.
// this prevents from relogin to actual users
if okteto.Context().UserID == "" && okteto.Context().IsOkteto {
okteto.Context().UserID = userContext.User.ID
if err := okteto.WriteOktetoContextConfig(); err != nil {
log.Infof("error updating okteto contexts: %v", err)
return nil, fmt.Errorf(errors.ErrCorruptedOktetoContexts, config.GetOktetoContextsStorePath())
}
}

if err == nil {
return userContext, nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/okteto/context.go
Expand Up @@ -55,7 +55,7 @@ var (
// OktetoContext contains the information related to an okteto context
type OktetoContext struct {
Name string `json:"name" yaml:"name,omitempty"`
UserID string `json:"-"`
UserID string `json:"id,omitempty" yaml:"id,omitempty"`
Username string `json:"username,omitempty" yaml:"username,omitempty"`
Token string `json:"token,omitempty" yaml:"token,omitempty"`
Namespace string `json:"namespace" yaml:"namespace,omitempty"`
Expand Down Expand Up @@ -107,6 +107,7 @@ func InitContextWithDeprecatedToken() {
Builder: token.Buildkit,
Certificate: base64.StdEncoding.EncodeToString(certificateBytes),
IsOkteto: true,
UserID: token.ID,
}
ctxStore.CurrentContext = token.URL

Expand Down

0 comments on commit 20236f8

Please sign in to comment.