Skip to content
Open
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
5 changes: 4 additions & 1 deletion goblet-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/google/uuid"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"

logpb "google.golang.org/genproto/googleapis/logging/v2"
Expand Down Expand Up @@ -230,7 +231,9 @@ func main() {
LocalDiskCacheRoot: *cacheRoot,
URLCanonializer: googlehook.CanonicalizeURL,
RequestAuthorizer: authorizer,
TokenSource: ts,
TokenSource: func(upstreamURL *url.URL) (*oauth2.Token, error) {
return ts.Token()
},
ErrorReporter: er,
RequestLogger: rl,
LongRunningOperationLogger: lrol,
Expand Down
2 changes: 1 addition & 1 deletion goblet.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type ServerConfig struct {

RequestAuthorizer func(*http.Request) error

TokenSource oauth2.TokenSource
TokenSource func(upstreamURL *url.URL) (*oauth2.Token, error)

ErrorReporter func(*http.Request, error)

Expand Down
6 changes: 3 additions & 3 deletions managed_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (r *managedRepository) lsRefsUpstream(command []*gitprotocolio.ProtocolV2Re
if err != nil {
return nil, status.Errorf(codes.Internal, "cannot construct a request object: %v", err)
}
t, err := r.config.TokenSource.Token()
t, err := r.config.TokenSource(r.upstreamURL)
if err != nil {
return nil, status.Errorf(codes.Internal, "cannot obtain an OAuth2 access token for the server: %v", err)
}
Expand Down Expand Up @@ -195,15 +195,15 @@ func (r *managedRepository) fetchUpstream() (err error) {
defer r.mu.Unlock()
if splitGitFetch {
// Fetch heads and changes first.
t, err = r.config.TokenSource.Token()
t, err = r.config.TokenSource(r.upstreamURL)
if err != nil {
err = status.Errorf(codes.Internal, "cannot obtain an OAuth2 access token for the server: %v", err)
return err
}
err = runGit(op, r.localDiskPath, "-c", "http.extraHeader=Authorization: Bearer "+t.AccessToken, "fetch", "--progress", "-f", "-n", "origin", "refs/heads/*:refs/heads/*", "refs/changes/*:refs/changes/*")
}
if err == nil {
t, err = r.config.TokenSource.Token()
t, err = r.config.TokenSource(r.upstreamURL)
if err != nil {
err = status.Errorf(codes.Internal, "cannot obtain an OAuth2 access token for the server: %v", err)
return err
Expand Down