diff --git a/pkg/sr/client.go b/pkg/sr/client.go index 39e52306..c2e9b2ce 100644 --- a/pkg/sr/client.go +++ b/pkg/sr/client.go @@ -60,6 +60,7 @@ type Client struct { user string pass string } + bearerToken string } // NewClient returns a new schema registry client. @@ -127,6 +128,9 @@ start: if cl.basicAuth != nil { req.SetBasicAuth(cl.basicAuth.user, cl.basicAuth.pass) } + if cl.bearerToken != "" { + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", cl.bearerToken)) + } cl.applyParams(ctx, req) resp, err := cl.httpcl.Do(req) diff --git a/pkg/sr/clientopt.go b/pkg/sr/clientopt.go index b8d04090..f45a94e6 100644 --- a/pkg/sr/clientopt.go +++ b/pkg/sr/clientopt.go @@ -77,6 +77,14 @@ func BasicAuth(user, pass string) ClientOpt { }} } +// BearerToken sets an Authorization header to use for every request. +// The format will be: "Authorization: Bearer $token". +func BearerToken(token string) ClientOpt { + return clientOpt{func(cl *Client) { + cl.bearerToken = token + }} +} + // DefaultParams sets default parameters to apply to every request. func DefaultParams(ps ...Param) ClientOpt { return clientOpt{func(cl *Client) {