Skip to content

Commit

Permalink
Enable optional headers to be passed into the authentication parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-kearney committed Oct 17, 2024
1 parent e151f76 commit f387461
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@ func (c *Client) V0() *client.TurnkeyAPI {
type Authenticator struct {
// Key optionally overrides the globally-parsed APIKeypair with a custom key.
Key *apikey.Key

// Optionally add headers to each request
Headers map[string]string
}

// AuthenticateRequest implements runtime.ClientAuthInfoWriter.
// It adds the X-Stamp header to the request based by generating the Stamp with the request body and API key.
func (auth *Authenticator) AuthenticateRequest(req runtime.ClientRequest, reg strfmt.Registry) (err error) { //nolint: revive
for k, v := range auth.Headers {
req.SetHeaderParam(k, v)

Check failure on line 74 in client.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `req.SetHeaderParam` is not checked (errcheck)
}

stamp, err := apikey.Stamp(req.GetBody(), auth.Key)
if err != nil {
return errors.Wrap(err, "failed to generate API stamp")
Expand Down

0 comments on commit f387461

Please sign in to comment.