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

Support bearer tokens for talking to GCP projects #139

Merged
merged 1 commit into from
May 20, 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
10 changes: 9 additions & 1 deletion hammer/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,15 @@ func (w *LogWriter) Run(ctx context.Context) {
}
newLeaf := w.gen()

resp, err := w.hc.Post(w.u.String(), "application/octet-stream", bytes.NewReader(newLeaf))
req, err := http.NewRequest(http.MethodPost, w.u.String(), bytes.NewReader(newLeaf))
if err != nil {
w.errchan <- fmt.Errorf("failed to create request: %v", err)
continue
}
if len(*bearerToken) > 0 {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", *bearerToken))
}
resp, err := hc.Do(req.WithContext(ctx))
if err != nil {
w.errchan <- fmt.Errorf("failed to write leaf: %v", err)
continue
Expand Down
4 changes: 4 additions & 0 deletions hammer/hammer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (

var (
logURL = flag.String("log_url", "", "Log storage root URL, e.g. https://log.server/and/path/")
bearerToken = flag.String("bearer_token", "", "The bearer token for auth. For GCP this is the result of `gcloud auth print-identity-token`")
logPubKeyFile = flag.String("log_public_key", "", "Location of log public key file. If unset, uses the contents of the SERVERLESS_LOG_PUBLIC_KEY environment variable")
origin = flag.String("origin", "", "Expected first line of checkpoints from log")

Expand Down Expand Up @@ -403,6 +404,9 @@ func readHTTP(ctx context.Context, u *url.URL) ([]byte, error) {
if err != nil {
return nil, err
}
if len(*bearerToken) > 0 {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", *bearerToken))
}
resp, err := hc.Do(req.WithContext(ctx))
if err != nil {
return nil, err
Expand Down
Loading