17119: add second test, simplify code by switching to the generic
[arvados.git] / lib / controller / rpc / conn.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package rpc
6
7 import (
8         "bufio"
9         "bytes"
10         "context"
11         "crypto/tls"
12         "encoding/json"
13         "errors"
14         "fmt"
15         "io"
16         "io/ioutil"
17         "net"
18         "net/http"
19         "net/url"
20         "strconv"
21         "strings"
22         "time"
23
24         "git.arvados.org/arvados.git/sdk/go/arvados"
25         "git.arvados.org/arvados.git/sdk/go/auth"
26         "git.arvados.org/arvados.git/sdk/go/ctxlog"
27         "git.arvados.org/arvados.git/sdk/go/httpserver"
28 )
29
30 const rfc3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
31
32 type TokenProvider func(context.Context) ([]string, error)
33
34 func PassthroughTokenProvider(ctx context.Context) ([]string, error) {
35         incoming, ok := auth.FromContext(ctx)
36         if !ok {
37                 return nil, errors.New("no token provided")
38         }
39         return incoming.Tokens, nil
40 }
41
42 type Conn struct {
43         SendHeader    http.Header
44         clusterID     string
45         httpClient    http.Client
46         baseURL       url.URL
47         tokenProvider TokenProvider
48 }
49
50 func NewConn(clusterID string, url *url.URL, insecure bool, tp TokenProvider) *Conn {
51         transport := http.DefaultTransport
52         if insecure {
53                 // It's not safe to copy *http.DefaultTransport
54                 // because it has a mutex (which might be locked)
55                 // protecting a private map (which might not be nil).
56                 // So we build our own, using the Go 1.12 default
57                 // values, ignoring any changes the application has
58                 // made to http.DefaultTransport.
59                 transport = &http.Transport{
60                         DialContext: (&net.Dialer{
61                                 Timeout:   30 * time.Second,
62                                 KeepAlive: 30 * time.Second,
63                                 DualStack: true,
64                         }).DialContext,
65                         MaxIdleConns:          100,
66                         IdleConnTimeout:       90 * time.Second,
67                         TLSHandshakeTimeout:   10 * time.Second,
68                         ExpectContinueTimeout: 1 * time.Second,
69                         TLSClientConfig:       &tls.Config{InsecureSkipVerify: true},
70                 }
71         }
72         return &Conn{
73                 clusterID: clusterID,
74                 httpClient: http.Client{
75                         CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse },
76                         Transport:     transport,
77                 },
78                 baseURL:       *url,
79                 tokenProvider: tp,
80         }
81 }
82
83 func (conn *Conn) requestAndDecode(ctx context.Context, dst interface{}, ep arvados.APIEndpoint, body io.Reader, opts interface{}) error {
84         aClient := arvados.Client{
85                 Client:     &conn.httpClient,
86                 Scheme:     conn.baseURL.Scheme,
87                 APIHost:    conn.baseURL.Host,
88                 SendHeader: conn.SendHeader,
89         }
90         tokens, err := conn.tokenProvider(ctx)
91         if err != nil {
92                 return err
93         } else if len(tokens) > 0 {
94                 ctx = arvados.ContextWithAuthorization(ctx, "Bearer "+tokens[0])
95         } else {
96                 // Use a non-empty auth string to ensure we override
97                 // any default token set on aClient -- and to avoid
98                 // having the remote prompt us to send a token by
99                 // responding 401.
100                 ctx = arvados.ContextWithAuthorization(ctx, "Bearer -")
101         }
102
103         // Encode opts to JSON and decode from there to a
104         // map[string]interface{}, so we can munge the query params
105         // using the JSON key names specified by opts' struct tags.
106         j, err := json.Marshal(opts)
107         if err != nil {
108                 return fmt.Errorf("%T: requestAndDecode: Marshal opts: %s", conn, err)
109         }
110         var params map[string]interface{}
111         dec := json.NewDecoder(bytes.NewBuffer(j))
112         dec.UseNumber()
113         err = dec.Decode(&params)
114         if err != nil {
115                 return fmt.Errorf("%T: requestAndDecode: Decode opts: %s", conn, err)
116         }
117         if attrs, ok := params["attrs"]; ok && ep.AttrsKey != "" {
118                 params[ep.AttrsKey] = attrs
119                 delete(params, "attrs")
120         }
121         if limitStr, ok := params["limit"]; ok {
122                 if limit, err := strconv.ParseInt(string(limitStr.(json.Number)), 10, 64); err == nil && limit < 0 {
123                         // Negative limit means "not specified" here, but some
124                         // servers/versions do not accept that, so we need to
125                         // remove it entirely.
126                         delete(params, "limit")
127                 }
128         }
129
130         if authinfo, ok := params["auth_info"]; ok {
131                 if tmp, ok2 := authinfo.(map[string]interface{}); ok2 {
132                         for k, v := range tmp {
133                                 if strings.HasSuffix(k, "_at") {
134                                         // Change zero times values to nil
135                                         if v, ok3 := v.(string); ok3 && (strings.HasPrefix(v, "0001-01-01T00:00:00") || v == "") {
136                                                 tmp[k] = nil
137                                         }
138                                 }
139                         }
140                 }
141         }
142
143         if len(tokens) > 1 {
144                 params["reader_tokens"] = tokens[1:]
145         }
146         path := ep.Path
147         if strings.Contains(ep.Path, "/{uuid}") {
148                 uuid, _ := params["uuid"].(string)
149                 path = strings.Replace(path, "/{uuid}", "/"+uuid, 1)
150                 delete(params, "uuid")
151         }
152         return aClient.RequestAndDecodeContext(ctx, dst, ep.Method, path, body, params)
153 }
154
155 func (conn *Conn) BaseURL() url.URL {
156         return conn.baseURL
157 }
158
159 func (conn *Conn) ConfigGet(ctx context.Context) (json.RawMessage, error) {
160         ep := arvados.EndpointConfigGet
161         var resp json.RawMessage
162         err := conn.requestAndDecode(ctx, &resp, ep, nil, nil)
163         return resp, err
164 }
165
166 func (conn *Conn) Login(ctx context.Context, options arvados.LoginOptions) (arvados.LoginResponse, error) {
167         ep := arvados.EndpointLogin
168         var resp arvados.LoginResponse
169         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
170         resp.RedirectLocation = conn.relativeToBaseURL(resp.RedirectLocation)
171         return resp, err
172 }
173
174 func (conn *Conn) Logout(ctx context.Context, options arvados.LogoutOptions) (arvados.LogoutResponse, error) {
175         ep := arvados.EndpointLogout
176         var resp arvados.LogoutResponse
177         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
178         resp.RedirectLocation = conn.relativeToBaseURL(resp.RedirectLocation)
179         return resp, err
180 }
181
182 // If the given location is a valid URL and its origin is the same as
183 // conn.baseURL, return it as a relative URL. Otherwise, return it
184 // unmodified.
185 func (conn *Conn) relativeToBaseURL(location string) string {
186         u, err := url.Parse(location)
187         if err == nil && u.Scheme == conn.baseURL.Scheme && strings.ToLower(u.Host) == strings.ToLower(conn.baseURL.Host) {
188                 u.Opaque = ""
189                 u.Scheme = ""
190                 u.User = nil
191                 u.Host = ""
192                 return u.String()
193         }
194         return location
195 }
196
197 func (conn *Conn) CollectionCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Collection, error) {
198         ep := arvados.EndpointCollectionCreate
199         var resp arvados.Collection
200         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
201         return resp, err
202 }
203
204 func (conn *Conn) CollectionUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Collection, error) {
205         ep := arvados.EndpointCollectionUpdate
206         var resp arvados.Collection
207         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
208         return resp, err
209 }
210
211 func (conn *Conn) CollectionGet(ctx context.Context, options arvados.GetOptions) (arvados.Collection, error) {
212         ep := arvados.EndpointCollectionGet
213         var resp arvados.Collection
214         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
215         return resp, err
216 }
217
218 func (conn *Conn) CollectionList(ctx context.Context, options arvados.ListOptions) (arvados.CollectionList, error) {
219         ep := arvados.EndpointCollectionList
220         var resp arvados.CollectionList
221         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
222         return resp, err
223 }
224
225 func (conn *Conn) CollectionProvenance(ctx context.Context, options arvados.GetOptions) (map[string]interface{}, error) {
226         ep := arvados.EndpointCollectionProvenance
227         var resp map[string]interface{}
228         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
229         return resp, err
230 }
231
232 func (conn *Conn) CollectionUsedBy(ctx context.Context, options arvados.GetOptions) (map[string]interface{}, error) {
233         ep := arvados.EndpointCollectionUsedBy
234         var resp map[string]interface{}
235         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
236         return resp, err
237 }
238
239 func (conn *Conn) CollectionDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Collection, error) {
240         ep := arvados.EndpointCollectionDelete
241         var resp arvados.Collection
242         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
243         return resp, err
244 }
245
246 func (conn *Conn) CollectionTrash(ctx context.Context, options arvados.DeleteOptions) (arvados.Collection, error) {
247         ep := arvados.EndpointCollectionTrash
248         var resp arvados.Collection
249         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
250         return resp, err
251 }
252
253 func (conn *Conn) CollectionUntrash(ctx context.Context, options arvados.UntrashOptions) (arvados.Collection, error) {
254         ep := arvados.EndpointCollectionUntrash
255         var resp arvados.Collection
256         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
257         return resp, err
258 }
259
260 func (conn *Conn) ContainerCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Container, error) {
261         ep := arvados.EndpointContainerCreate
262         var resp arvados.Container
263         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
264         return resp, err
265 }
266
267 func (conn *Conn) ContainerUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Container, error) {
268         ep := arvados.EndpointContainerUpdate
269         var resp arvados.Container
270         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
271         return resp, err
272 }
273
274 func (conn *Conn) ContainerGet(ctx context.Context, options arvados.GetOptions) (arvados.Container, error) {
275         ep := arvados.EndpointContainerGet
276         var resp arvados.Container
277         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
278         return resp, err
279 }
280
281 func (conn *Conn) ContainerList(ctx context.Context, options arvados.ListOptions) (arvados.ContainerList, error) {
282         ep := arvados.EndpointContainerList
283         var resp arvados.ContainerList
284         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
285         return resp, err
286 }
287
288 func (conn *Conn) ContainerDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Container, error) {
289         ep := arvados.EndpointContainerDelete
290         var resp arvados.Container
291         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
292         return resp, err
293 }
294
295 func (conn *Conn) ContainerLock(ctx context.Context, options arvados.GetOptions) (arvados.Container, error) {
296         ep := arvados.EndpointContainerLock
297         var resp arvados.Container
298         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
299         return resp, err
300 }
301
302 func (conn *Conn) ContainerUnlock(ctx context.Context, options arvados.GetOptions) (arvados.Container, error) {
303         ep := arvados.EndpointContainerUnlock
304         var resp arvados.Container
305         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
306         return resp, err
307 }
308
309 // ContainerSSH returns a connection to the out-of-band SSH server for
310 // a running container. If the returned error is nil, the caller is
311 // responsible for closing sshconn.Conn.
312 func (conn *Conn) ContainerSSH(ctx context.Context, options arvados.ContainerSSHOptions) (sshconn arvados.ContainerSSHConnection, err error) {
313         addr := conn.baseURL.Host
314         if strings.Index(addr, ":") < 1 || (strings.Contains(addr, "::") && addr[0] != '[') {
315                 // hostname or ::1 or 1::1
316                 addr = net.JoinHostPort(addr, "https")
317         }
318         insecure := false
319         if tlsconf := conn.httpClient.Transport.(*http.Transport).TLSClientConfig; tlsconf != nil && tlsconf.InsecureSkipVerify {
320                 insecure = true
321         }
322         netconn, err := tls.Dial("tcp", addr, &tls.Config{InsecureSkipVerify: insecure})
323         if err != nil {
324                 err = fmt.Errorf("tls.Dial: %w", err)
325                 return
326         }
327         defer func() {
328                 if err != nil {
329                         netconn.Close()
330                 }
331         }()
332         bufr := bufio.NewReader(netconn)
333         bufw := bufio.NewWriter(netconn)
334
335         u, err := conn.baseURL.Parse("/" + strings.Replace(arvados.EndpointContainerSSH.Path, "{uuid}", options.UUID, -1))
336         if err != nil {
337                 err = fmt.Errorf("tls.Dial: %w", err)
338                 return
339         }
340         u.RawQuery = url.Values{
341                 "detach_keys":    {options.DetachKeys},
342                 "login_username": {options.LoginUsername},
343         }.Encode()
344         tokens, err := conn.tokenProvider(ctx)
345         if err != nil {
346                 return
347         } else if len(tokens) < 1 {
348                 err = httpserver.ErrorWithStatus(errors.New("unauthorized"), http.StatusUnauthorized)
349                 return
350         }
351         bufw.WriteString("GET " + u.String() + " HTTP/1.1\r\n")
352         bufw.WriteString("Authorization: Bearer " + tokens[0] + "\r\n")
353         bufw.WriteString("Host: " + u.Host + "\r\n")
354         bufw.WriteString("Upgrade: ssh\r\n")
355         bufw.WriteString("\r\n")
356         bufw.Flush()
357         resp, err := http.ReadResponse(bufr, &http.Request{Method: "GET"})
358         if err != nil {
359                 err = fmt.Errorf("http.ReadResponse: %w", err)
360                 return
361         }
362         if resp.StatusCode != http.StatusSwitchingProtocols {
363                 defer resp.Body.Close()
364                 body, _ := ioutil.ReadAll(resp.Body)
365                 var message string
366                 var errDoc httpserver.ErrorResponse
367                 if err := json.Unmarshal(body, &errDoc); err == nil {
368                         message = strings.Join(errDoc.Errors, "; ")
369                 } else {
370                         message = fmt.Sprintf("%q", body)
371                 }
372                 err = fmt.Errorf("server did not provide a tunnel: %s (HTTP %d)", message, resp.StatusCode)
373                 return
374         }
375         if strings.ToLower(resp.Header.Get("Upgrade")) != "ssh" ||
376                 strings.ToLower(resp.Header.Get("Connection")) != "upgrade" {
377                 err = fmt.Errorf("bad response from server: Upgrade %q Connection %q", resp.Header.Get("Upgrade"), resp.Header.Get("Connection"))
378                 return
379         }
380         sshconn.Conn = netconn
381         sshconn.Bufrw = &bufio.ReadWriter{Reader: bufr, Writer: bufw}
382         return
383 }
384
385 func (conn *Conn) ContainerRequestCreate(ctx context.Context, options arvados.CreateOptions) (arvados.ContainerRequest, error) {
386         ep := arvados.EndpointContainerRequestCreate
387         var resp arvados.ContainerRequest
388         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
389         return resp, err
390 }
391
392 func (conn *Conn) ContainerRequestUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.ContainerRequest, error) {
393         ep := arvados.EndpointContainerRequestUpdate
394         var resp arvados.ContainerRequest
395         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
396         return resp, err
397 }
398
399 func (conn *Conn) ContainerRequestGet(ctx context.Context, options arvados.GetOptions) (arvados.ContainerRequest, error) {
400         ep := arvados.EndpointContainerRequestGet
401         var resp arvados.ContainerRequest
402         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
403         return resp, err
404 }
405
406 func (conn *Conn) ContainerRequestList(ctx context.Context, options arvados.ListOptions) (arvados.ContainerRequestList, error) {
407         ep := arvados.EndpointContainerRequestList
408         var resp arvados.ContainerRequestList
409         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
410         return resp, err
411 }
412
413 func (conn *Conn) ContainerRequestDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.ContainerRequest, error) {
414         ep := arvados.EndpointContainerRequestDelete
415         var resp arvados.ContainerRequest
416         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
417         return resp, err
418 }
419
420 func (conn *Conn) GroupCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Group, error) {
421         ep := arvados.EndpointGroupCreate
422         var resp arvados.Group
423         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
424         return resp, err
425 }
426
427 func (conn *Conn) GroupUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Group, error) {
428         ep := arvados.EndpointGroupUpdate
429         var resp arvados.Group
430         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
431         return resp, err
432 }
433
434 func (conn *Conn) GroupGet(ctx context.Context, options arvados.GetOptions) (arvados.Group, error) {
435         ep := arvados.EndpointGroupGet
436         var resp arvados.Group
437         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
438         return resp, err
439 }
440
441 func (conn *Conn) GroupList(ctx context.Context, options arvados.ListOptions) (arvados.GroupList, error) {
442         ep := arvados.EndpointGroupList
443         var resp arvados.GroupList
444         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
445         return resp, err
446 }
447
448 func (conn *Conn) GroupContents(ctx context.Context, options arvados.GroupContentsOptions) (arvados.ObjectList, error) {
449         // The requested UUID can be a user (virtual home project), which we just pass on to
450         // the API server.
451         if strings.Index(options.UUID, "j7d0g") != 6 {
452                 ep := arvados.EndpointGroupContents
453                 var resp arvados.ObjectList
454                 err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
455                 return resp, err
456         }
457
458         log := ctxlog.FromContext(ctx)
459         var resp arvados.ObjectList
460
461         // Get the group object
462         epGet := arvados.EndpointGroupGet
463         var respGroup arvados.Group
464         err := conn.requestAndDecode(ctx, &respGroup, epGet, nil, options)
465         if err != nil {
466                 return resp, err
467         }
468
469         // If the group has groupClass 'filter', apply the filters before getting the contents.
470         if respGroup.GroupClass == "filter" {
471                 if filters, ok := respGroup.Properties["filters"]; ok {
472                         for _, f := range filters.([]interface{}) {
473                                 // f is supposed to be a []string
474                                 tmp, ok2 := f.([]interface{})
475                                 if !ok2 || len(tmp) < 3 {
476                                         log.Warnf("filter unparsable: %T, %+v, original field: %T, %+v\n", tmp, tmp, f, f)
477                                         continue
478                                 }
479                                 var filter arvados.Filter
480                                 filter.Attr = tmp[0].(string)
481                                 filter.Operator = tmp[1].(string)
482                                 filter.Operand = tmp[2]
483                                 options.Filters = append(options.Filters, filter)
484                         }
485                 }
486                 // Use the generic /groups/contents endpoint for filter groups
487                 options.UUID = ""
488         }
489
490         ep := arvados.EndpointGroupContents
491         err = conn.requestAndDecode(ctx, &resp, ep, nil, options)
492         return resp, err
493 }
494
495 func (conn *Conn) GroupShared(ctx context.Context, options arvados.ListOptions) (arvados.GroupList, error) {
496         ep := arvados.EndpointGroupShared
497         var resp arvados.GroupList
498         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
499         return resp, err
500 }
501
502 func (conn *Conn) GroupDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Group, error) {
503         ep := arvados.EndpointGroupDelete
504         var resp arvados.Group
505         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
506         return resp, err
507 }
508
509 func (conn *Conn) GroupUntrash(ctx context.Context, options arvados.UntrashOptions) (arvados.Group, error) {
510         ep := arvados.EndpointGroupUntrash
511         var resp arvados.Group
512         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
513         return resp, err
514 }
515
516 func (conn *Conn) SpecimenCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Specimen, error) {
517         ep := arvados.EndpointSpecimenCreate
518         var resp arvados.Specimen
519         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
520         return resp, err
521 }
522
523 func (conn *Conn) SpecimenUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Specimen, error) {
524         ep := arvados.EndpointSpecimenUpdate
525         var resp arvados.Specimen
526         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
527         return resp, err
528 }
529
530 func (conn *Conn) SpecimenGet(ctx context.Context, options arvados.GetOptions) (arvados.Specimen, error) {
531         ep := arvados.EndpointSpecimenGet
532         var resp arvados.Specimen
533         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
534         return resp, err
535 }
536
537 func (conn *Conn) SpecimenList(ctx context.Context, options arvados.ListOptions) (arvados.SpecimenList, error) {
538         ep := arvados.EndpointSpecimenList
539         var resp arvados.SpecimenList
540         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
541         return resp, err
542 }
543
544 func (conn *Conn) SpecimenDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Specimen, error) {
545         ep := arvados.EndpointSpecimenDelete
546         var resp arvados.Specimen
547         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
548         return resp, err
549 }
550
551 func (conn *Conn) UserCreate(ctx context.Context, options arvados.CreateOptions) (arvados.User, error) {
552         ep := arvados.EndpointUserCreate
553         var resp arvados.User
554         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
555         return resp, err
556 }
557 func (conn *Conn) UserUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.User, error) {
558         ep := arvados.EndpointUserUpdate
559         var resp arvados.User
560         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
561         return resp, err
562 }
563 func (conn *Conn) UserUpdateUUID(ctx context.Context, options arvados.UpdateUUIDOptions) (arvados.User, error) {
564         ep := arvados.EndpointUserUpdateUUID
565         var resp arvados.User
566         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
567         return resp, err
568 }
569 func (conn *Conn) UserMerge(ctx context.Context, options arvados.UserMergeOptions) (arvados.User, error) {
570         ep := arvados.EndpointUserMerge
571         var resp arvados.User
572         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
573         return resp, err
574 }
575 func (conn *Conn) UserActivate(ctx context.Context, options arvados.UserActivateOptions) (arvados.User, error) {
576         ep := arvados.EndpointUserActivate
577         var resp arvados.User
578         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
579         return resp, err
580 }
581 func (conn *Conn) UserSetup(ctx context.Context, options arvados.UserSetupOptions) (map[string]interface{}, error) {
582         ep := arvados.EndpointUserSetup
583         var resp map[string]interface{}
584         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
585         return resp, err
586 }
587 func (conn *Conn) UserUnsetup(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
588         ep := arvados.EndpointUserUnsetup
589         var resp arvados.User
590         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
591         return resp, err
592 }
593 func (conn *Conn) UserGet(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
594         ep := arvados.EndpointUserGet
595         var resp arvados.User
596         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
597         return resp, err
598 }
599 func (conn *Conn) UserGetCurrent(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
600         ep := arvados.EndpointUserGetCurrent
601         var resp arvados.User
602         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
603         return resp, err
604 }
605 func (conn *Conn) UserGetSystem(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
606         ep := arvados.EndpointUserGetSystem
607         var resp arvados.User
608         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
609         return resp, err
610 }
611 func (conn *Conn) UserList(ctx context.Context, options arvados.ListOptions) (arvados.UserList, error) {
612         ep := arvados.EndpointUserList
613         var resp arvados.UserList
614         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
615         return resp, err
616 }
617 func (conn *Conn) UserDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.User, error) {
618         ep := arvados.EndpointUserDelete
619         var resp arvados.User
620         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
621         return resp, err
622 }
623
624 func (conn *Conn) APIClientAuthorizationCurrent(ctx context.Context, options arvados.GetOptions) (arvados.APIClientAuthorization, error) {
625         ep := arvados.EndpointAPIClientAuthorizationCurrent
626         var resp arvados.APIClientAuthorization
627         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
628         return resp, err
629 }
630
631 type UserSessionAuthInfo struct {
632         UserUUID        string    `json:"user_uuid"`
633         Email           string    `json:"email"`
634         AlternateEmails []string  `json:"alternate_emails"`
635         FirstName       string    `json:"first_name"`
636         LastName        string    `json:"last_name"`
637         Username        string    `json:"username"`
638         ExpiresAt       time.Time `json:"expires_at"`
639 }
640
641 type UserSessionCreateOptions struct {
642         AuthInfo UserSessionAuthInfo `json:"auth_info"`
643         ReturnTo string              `json:"return_to"`
644 }
645
646 func (conn *Conn) UserSessionCreate(ctx context.Context, options UserSessionCreateOptions) (arvados.LoginResponse, error) {
647         ep := arvados.APIEndpoint{Method: "POST", Path: "auth/controller/callback"}
648         var resp arvados.LoginResponse
649         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
650         return resp, err
651 }
652
653 func (conn *Conn) UserBatchUpdate(ctx context.Context, options arvados.UserBatchUpdateOptions) (arvados.UserList, error) {
654         ep := arvados.EndpointUserBatchUpdate
655         var resp arvados.UserList
656         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
657         return resp, err
658 }
659
660 func (conn *Conn) UserAuthenticate(ctx context.Context, options arvados.UserAuthenticateOptions) (arvados.APIClientAuthorization, error) {
661         ep := arvados.EndpointUserAuthenticate
662         var resp arvados.APIClientAuthorization
663         err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
664         return resp, err
665 }