@@ -59,6 +59,7 @@ type WorkloadIdentityFederationFlow struct {
5959type WorkloadIdentityFederationFlowConfig struct {
6060 TokenUrl string
6161 ClientID string
62+ FederatedToken string // Static token string. This is optional, if not set the token will be read from file.
6263 FederatedTokenFilePath string
6364 TokenExpiration string // Not supported yet
6465 BackgroundTokenRefreshContext context.Context // Functionality is enabled if this isn't nil
@@ -139,7 +140,7 @@ func (c *WorkloadIdentityFederationFlow) Init(cfg *WorkloadIdentityFederationFlo
139140 c .config .ClientID = getEnvOrDefault (clientIDEnv , "" )
140141 }
141142
142- if c .config .FederatedTokenFilePath == "" {
143+ if c .config .FederatedToken == "" && c . config . FederatedTokenFilePath == "" {
143144 c .config .FederatedTokenFilePath = getEnvOrDefault (FederatedTokenFileEnv , defaultFederatedTokenPath )
144145 }
145146
@@ -161,12 +162,6 @@ func (c *WorkloadIdentityFederationFlow) Init(cfg *WorkloadIdentityFederationFlo
161162 return err
162163 }
163164
164- // // Init the token
165- // _, err = c.GetAccessToken()
166- // if err != nil {
167- // return err
168- // }
169-
170165 if c .config .BackgroundTokenRefreshContext != nil {
171166 go continuousRefreshToken (c )
172167 }
@@ -181,8 +176,10 @@ func (c *WorkloadIdentityFederationFlow) validate() error {
181176 if c .config .TokenUrl == "" {
182177 return fmt .Errorf ("token URL cannot be empty" )
183178 }
184- if _ , err := c .readJWTFromFileSystem (c .config .FederatedTokenFilePath ); err != nil {
185- return fmt .Errorf ("error reading federated token file - %w" , err )
179+ if c .config .FederatedToken == "" {
180+ if _ , err := c .readJWTFromFileSystem (c .config .FederatedTokenFilePath ); err != nil {
181+ return fmt .Errorf ("error reading federated token file - %w" , err )
182+ }
186183 }
187184 if c .tokenExpirationLeeway < 0 {
188185 return fmt .Errorf ("token expiration leeway cannot be negative" )
@@ -192,10 +189,14 @@ func (c *WorkloadIdentityFederationFlow) validate() error {
192189}
193190
194191// createAccessToken creates an access token using self signed JWT
195- func (c * WorkloadIdentityFederationFlow ) createAccessToken () (err error ) {
196- clientAssertion , err := c .readJWTFromFileSystem (c .config .FederatedTokenFilePath )
197- if err != nil {
198- return fmt .Errorf ("error reading service account assertion - %w" , err )
192+ func (c * WorkloadIdentityFederationFlow ) createAccessToken () error {
193+ clientAssertion := c .config .FederatedToken
194+ if clientAssertion == "" {
195+ var err error
196+ clientAssertion , err = c .readJWTFromFileSystem (c .config .FederatedTokenFilePath )
197+ if err != nil {
198+ return fmt .Errorf ("error reading service account assertion - %w" , err )
199+ }
199200 }
200201
201202 res , err := c .requestToken (c .config .ClientID , clientAssertion )
0 commit comments