From 84a5b5cb592ed2d52908cc93a96eab74169234e0 Mon Sep 17 00:00:00 2001 From: Sam Gartner Date: Mon, 5 Aug 2024 17:13:18 -0500 Subject: [PATCH] Add the user field to rancher clients. Update client.go update name --- clients/rancher/client.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clients/rancher/client.go b/clients/rancher/client.go index a4d120f9..e2745e77 100644 --- a/clients/rancher/client.go +++ b/clients/rancher/client.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "strings" "github.com/pkg/errors" "github.com/rancher/norman/httperror" @@ -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, @@ -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 }