X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/70459cdae1f4e92789a14c1fecb66f5954a5aa7f..2d9aa62499005abd47b5f2fa604f01d055480722:/sdk/go/auth/auth.go diff --git a/sdk/go/auth/auth.go b/sdk/go/auth/auth.go index 3c266e0d3a..c2f6a0e8f0 100644 --- a/sdk/go/auth/auth.go +++ b/sdk/go/auth/auth.go @@ -5,6 +5,7 @@ package auth import ( + "context" "encoding/base64" "net/http" "net/url" @@ -19,8 +20,17 @@ func NewCredentials() *Credentials { return &Credentials{Tokens: []string{}} } +func NewContext(ctx context.Context, c *Credentials) context.Context { + return context.WithValue(ctx, contextKeyCredentials{}, c) +} + +func FromContext(ctx context.Context) (*Credentials, bool) { + c, ok := ctx.Value(contextKeyCredentials{}).(*Credentials) + return c, ok +} + func CredentialsFromRequest(r *http.Request) *Credentials { - if c, ok := r.Context().Value(contextKeyCredentials).(*Credentials); ok { + if c, ok := FromContext(r.Context()); ok { // preloaded by middleware return c }