15721: Fix 503 on API.MaxConcurrentRequests==0 and empty response.
[arvados.git] / lib / controller / rpc / conn.go
index e07eaf40affbe3ec0dc0d78422686926eea550c0..1028da829fbdb0361fc5b041e98fba5e30c81c6c 100644 (file)
@@ -8,6 +8,7 @@ import (
        "context"
        "crypto/tls"
        "encoding/json"
+       "errors"
        "fmt"
        "io"
        "net"
@@ -17,10 +18,19 @@ import (
        "time"
 
        "git.curoverse.com/arvados.git/sdk/go/arvados"
+       "git.curoverse.com/arvados.git/sdk/go/auth"
 )
 
 type TokenProvider func(context.Context) ([]string, error)
 
+func PassthroughTokenProvider(ctx context.Context) ([]string, error) {
+       if incoming, ok := auth.FromContext(ctx); !ok {
+               return nil, errors.New("no token provided")
+       } else {
+               return incoming.Tokens, nil
+       }
+}
+
 type Conn struct {
        clusterID     string
        httpClient    http.Client
@@ -111,6 +121,13 @@ func (conn *Conn) requestAndDecode(ctx context.Context, dst interface{}, ep arva
        return aClient.RequestAndDecodeContext(ctx, dst, ep.Method, path, body, params)
 }
 
+func (conn *Conn) ConfigGet(ctx context.Context) (json.RawMessage, error) {
+       ep := arvados.EndpointConfigGet
+       var resp json.RawMessage
+       err := conn.requestAndDecode(ctx, &resp, ep, nil, nil)
+       return resp, err
+}
+
 func (conn *Conn) CollectionCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Collection, error) {
        ep := arvados.EndpointCollectionCreate
        var resp arvados.Collection