Merge branch '15924-import-path'
[arvados.git] / lib / controller / localdb / conn.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package localdb
6
7 import (
8         "context"
9         "errors"
10
11         "git.arvados.org/arvados.git/lib/controller/railsproxy"
12         "git.arvados.org/arvados.git/lib/controller/rpc"
13         "git.arvados.org/arvados.git/sdk/go/arvados"
14 )
15
16 type railsProxy = rpc.Conn
17
18 type Conn struct {
19         cluster     *arvados.Cluster
20         *railsProxy // handles API methods that aren't defined on Conn itself
21
22         googleLoginController
23 }
24
25 func NewConn(cluster *arvados.Cluster) *Conn {
26         return &Conn{
27                 cluster:    cluster,
28                 railsProxy: railsproxy.NewConn(cluster),
29         }
30 }
31
32 func (conn *Conn) Login(ctx context.Context, opts arvados.LoginOptions) (arvados.LoginResponse, error) {
33         wantGoogle := conn.cluster.Login.GoogleClientID != ""
34         wantSSO := conn.cluster.Login.ProviderAppID != ""
35         if wantGoogle == wantSSO {
36                 return arvados.LoginResponse{}, errors.New("configuration problem: exactly one of Login.GoogleClientID and Login.ProviderAppID must be configured")
37         } else if wantGoogle {
38                 return conn.googleLoginController.Login(ctx, conn.cluster, conn.railsProxy, opts)
39         } else {
40                 // Proxy to RailsAPI, which hands off to sso-provider.
41                 return conn.railsProxy.Login(ctx, opts)
42         }
43 }