Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sr: add support for using bearer tokens in client #808

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/sr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Client struct {
user string
pass string
}
bearerToken string
}

// NewClient returns a new schema registry client.
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions pkg/sr/clientopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading