Skip to content

Commit

Permalink
Merge pull request #250 from susesgartner/client_update
Browse files Browse the repository at this point in the history
Add the user field to rancher clients.
  • Loading branch information
Israel Gomez authored Aug 7, 2024
2 parents caf580b + 84a5b5c commit 21e0438
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions clients/rancher/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
"strings"

"github.com/pkg/errors"
"github.com/rancher/norman/httperror"
Expand Down Expand Up @@ -52,6 +53,7 @@ type Client struct {
// Flags is the environment flags used by the client to test selectively against a rancher instance.
Flags *environmentflag.EnvironmentFlags
restConfig *rest.Config
UserID string
}

// NewClient is the constructor to the initializing a rancher Client. It takes a bearer token and session.Session. If bearer token is not provided,
Expand Down Expand Up @@ -113,6 +115,14 @@ func NewClient(bearerToken string, session *session.Session) (*Client, error) {

c.WranglerContext = wranglerContext

splitBearerKey := strings.Split(bearerToken, ":")
token, err := c.Management.Token.ByID(splitBearerKey[0])
if err != nil {
return nil, err
}

c.UserID = token.UserID

return c, nil
}

Expand Down

0 comments on commit 21e0438

Please sign in to comment.