Skip to content

Commit

Permalink
Add the user field to rancher clients.
Browse files Browse the repository at this point in the history
Update client.go

update name
  • Loading branch information
susesgartner committed Aug 6, 2024
1 parent bdce62c commit 84a5b5c
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 84a5b5c

Please sign in to comment.