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)
30 railsProxy: railsProxy,
32 conn.loginController = chooseLoginController(cluster, &conn)
36 // Logout handles the logout of conn giving to the appropriate loginController
37 func (conn *Conn) Logout(ctx context.Context, opts arvados.LogoutOptions) (arvados.LogoutResponse, error) {
38 return conn.loginController.Logout(ctx, opts)
41 // Login handles the login of conn giving to the appropriate loginController
42 func (conn *Conn) Login(ctx context.Context, opts arvados.LoginOptions) (arvados.LoginResponse, error) {
43 return conn.loginController.Login(ctx, opts)
46 // UserAuthenticate handles the User Authentication of conn giving to the appropriate loginController
47 func (conn *Conn) UserAuthenticate(ctx context.Context, opts arvados.UserAuthenticateOptions) (arvados.APIClientAuthorization, error) {
48 return conn.loginController.UserAuthenticate(ctx, opts)
51 func (conn *Conn) GroupContents(ctx context.Context, options arvados.GroupContentsOptions) (arvados.ObjectList, error) {
52 // The requested UUID can be a user (virtual home project), which we just pass on to
54 if strings.Index(options.UUID, "j7d0g") != 6 {
55 return conn.railsProxy.GroupContents(ctx, options)
58 var resp arvados.ObjectList
60 // Get the group object
61 respGroup, err := conn.GroupGet(ctx, arvados.GetOptions{UUID: options.UUID})
66 // If the group has groupClass 'filter', apply the filters before getting the contents.
67 if respGroup.GroupClass == "filter" {
68 if filters, ok := respGroup.Properties["filters"].([]interface{}); ok {
69 for _, f := range filters {
70 // f is supposed to be a []string
71 tmp, ok2 := f.([]interface{})
72 if !ok2 || len(tmp) < 3 {
73 return resp, fmt.Errorf("filter unparsable: %T, %+v, original field: %T, %+v\n", tmp, tmp, f, f)
75 var filter arvados.Filter
76 if attr, ok2 := tmp[0].(string); ok2 {
79 return resp, fmt.Errorf("filter unparsable: attribute must be string: %T, %+v, filter: %T, %+v\n", tmp[0], tmp[0], f, f)
81 if operator, ok2 := tmp[1].(string); ok2 {
82 filter.Operator = operator
84 return resp, fmt.Errorf("filter unparsable: operator must be string: %T, %+v, filter: %T, %+v\n", tmp[1], tmp[1], f, f)
86 filter.Operand = tmp[2]
87 options.Filters = append(options.Filters, filter)
90 // Use the generic /groups/contents endpoint for filter groups
94 return conn.railsProxy.GroupContents(ctx, options)