1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.arvados.org/arvados.git/lib/controller/railsproxy"
13 "git.arvados.org/arvados.git/lib/controller/rpc"
14 "git.arvados.org/arvados.git/sdk/go/arvados"
17 type railsProxy = rpc.Conn
20 cluster *arvados.Cluster
21 *railsProxy // handles API methods that aren't defined on Conn itself
25 func NewConn(cluster *arvados.Cluster) *Conn {
26 railsProxy := railsproxy.NewConn(cluster)
27 railsProxy.RedactHostInErrors = true
31 railsProxy: railsProxy,
33 conn.loginController = chooseLoginController(cluster, &conn)
37 // Logout handles the logout of conn giving to the appropriate loginController
38 func (conn *Conn) Logout(ctx context.Context, opts arvados.LogoutOptions) (arvados.LogoutResponse, error) {
39 return conn.loginController.Logout(ctx, opts)
42 // Login handles the login of conn giving to the appropriate loginController
43 func (conn *Conn) Login(ctx context.Context, opts arvados.LoginOptions) (arvados.LoginResponse, error) {
44 return conn.loginController.Login(ctx, opts)
47 // UserAuthenticate handles the User Authentication of conn giving to the appropriate loginController
48 func (conn *Conn) UserAuthenticate(ctx context.Context, opts arvados.UserAuthenticateOptions) (arvados.APIClientAuthorization, error) {
49 return conn.loginController.UserAuthenticate(ctx, opts)
52 func (conn *Conn) GroupContents(ctx context.Context, options arvados.GroupContentsOptions) (arvados.ObjectList, error) {
53 // The requested UUID can be a user (virtual home project), which we just pass on to
55 if strings.Index(options.UUID, "-j7d0g-") != 5 {
56 return conn.railsProxy.GroupContents(ctx, options)
59 var resp arvados.ObjectList
61 // Get the group object
62 respGroup, err := conn.GroupGet(ctx, arvados.GetOptions{UUID: options.UUID})
67 // If the group has groupClass 'filter', apply the filters before getting the contents.
68 if respGroup.GroupClass == "filter" {
69 if filters, ok := respGroup.Properties["filters"].([]interface{}); ok {
70 for _, f := range filters {
71 // f is supposed to be a []string
72 tmp, ok2 := f.([]interface{})
73 if !ok2 || len(tmp) < 3 {
74 return resp, fmt.Errorf("filter unparsable: %T, %+v, original field: %T, %+v\n", tmp, tmp, f, f)
76 var filter arvados.Filter
77 if attr, ok2 := tmp[0].(string); ok2 {
80 return resp, fmt.Errorf("filter unparsable: attribute must be string: %T, %+v, filter: %T, %+v\n", tmp[0], tmp[0], f, f)
82 if operator, ok2 := tmp[1].(string); ok2 {
83 filter.Operator = operator
85 return resp, fmt.Errorf("filter unparsable: operator must be string: %T, %+v, filter: %T, %+v\n", tmp[1], tmp[1], f, f)
87 filter.Operand = tmp[2]
88 options.Filters = append(options.Filters, filter)
91 return resp, fmt.Errorf("filter unparsable: not an array\n")
93 // Use the generic /groups/contents endpoint for filter groups
97 return conn.railsProxy.GroupContents(ctx, options)