17170: Merge branch 'master'
[arvados.git] / lib / controller / rpc / conn.go
index 7dd89452bec7fbeff1ca0c70cdbd3b8e24eaa914..3a19f4ab5ad50d2ad5ceb5fbdf9981108bf1213f 100644 (file)
@@ -26,6 +26,8 @@ import (
        "git.arvados.org/arvados.git/sdk/go/httpserver"
 )
 
+const rfc3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
+
 type TokenProvider func(context.Context) ([]string, error)
 
 func PassthroughTokenProvider(ctx context.Context) ([]string, error) {
@@ -123,6 +125,20 @@ func (conn *Conn) requestAndDecode(ctx context.Context, dst interface{}, ep arva
                        delete(params, "limit")
                }
        }
+
+       if authinfo, ok := params["auth_info"]; ok {
+               if tmp, ok2 := authinfo.(map[string]interface{}); ok2 {
+                       for k, v := range tmp {
+                               if strings.HasSuffix(k, "_at") {
+                                       // Change zero times values to nil
+                                       if v, ok3 := v.(string); ok3 && (strings.HasPrefix(v, "0001-01-01T00:00:00") || v == "") {
+                                               tmp[k] = nil
+                                       }
+                               }
+                       }
+               }
+       }
+
        if len(tokens) > 1 {
                params["reader_tokens"] = tokens[1:]
        }
@@ -298,8 +314,13 @@ func (conn *Conn) ContainerSSH(ctx context.Context, options arvados.ContainerSSH
                // hostname or ::1 or 1::1
                addr = net.JoinHostPort(addr, "https")
        }
-       netconn, err := tls.Dial("tcp", addr, conn.httpClient.Transport.(*http.Transport).TLSClientConfig)
+       insecure := false
+       if tlsconf := conn.httpClient.Transport.(*http.Transport).TLSClientConfig; tlsconf != nil && tlsconf.InsecureSkipVerify {
+               insecure = true
+       }
+       netconn, err := tls.Dial("tcp", addr, &tls.Config{InsecureSkipVerify: insecure})
        if err != nil {
+               err = fmt.Errorf("tls.Dial: %w", err)
                return
        }
        defer func() {
@@ -312,6 +333,7 @@ func (conn *Conn) ContainerSSH(ctx context.Context, options arvados.ContainerSSH
 
        u, err := conn.baseURL.Parse("/" + strings.Replace(arvados.EndpointContainerSSH.Path, "{uuid}", options.UUID, -1))
        if err != nil {
+               err = fmt.Errorf("tls.Dial: %w", err)
                return
        }
        u.RawQuery = url.Values{
@@ -333,12 +355,20 @@ func (conn *Conn) ContainerSSH(ctx context.Context, options arvados.ContainerSSH
        bufw.Flush()
        resp, err := http.ReadResponse(bufr, &http.Request{Method: "GET"})
        if err != nil {
+               err = fmt.Errorf("http.ReadResponse: %w", err)
                return
        }
        if resp.StatusCode != http.StatusSwitchingProtocols {
                defer resp.Body.Close()
                body, _ := ioutil.ReadAll(resp.Body)
-               err = fmt.Errorf("server did not provide a tunnel: %d %q", resp.StatusCode, body)
+               var message string
+               var errDoc httpserver.ErrorResponse
+               if err := json.Unmarshal(body, &errDoc); err == nil {
+                       message = strings.Join(errDoc.Errors, "; ")
+               } else {
+                       message = fmt.Sprintf("%q", body)
+               }
+               err = fmt.Errorf("server did not provide a tunnel: %s (HTTP %d)", message, resp.StatusCode)
                return
        }
        if strings.ToLower(resp.Header.Get("Upgrade")) != "ssh" ||
@@ -351,6 +381,41 @@ func (conn *Conn) ContainerSSH(ctx context.Context, options arvados.ContainerSSH
        return
 }
 
+func (conn *Conn) ContainerRequestCreate(ctx context.Context, options arvados.CreateOptions) (arvados.ContainerRequest, error) {
+       ep := arvados.EndpointContainerRequestCreate
+       var resp arvados.ContainerRequest
+       err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
+       return resp, err
+}
+
+func (conn *Conn) ContainerRequestUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.ContainerRequest, error) {
+       ep := arvados.EndpointContainerRequestUpdate
+       var resp arvados.ContainerRequest
+       err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
+       return resp, err
+}
+
+func (conn *Conn) ContainerRequestGet(ctx context.Context, options arvados.GetOptions) (arvados.ContainerRequest, error) {
+       ep := arvados.EndpointContainerRequestGet
+       var resp arvados.ContainerRequest
+       err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
+       return resp, err
+}
+
+func (conn *Conn) ContainerRequestList(ctx context.Context, options arvados.ListOptions) (arvados.ContainerRequestList, error) {
+       ep := arvados.EndpointContainerRequestList
+       var resp arvados.ContainerRequestList
+       err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
+       return resp, err
+}
+
+func (conn *Conn) ContainerRequestDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.ContainerRequest, error) {
+       ep := arvados.EndpointContainerRequestDelete
+       var resp arvados.ContainerRequest
+       err := conn.requestAndDecode(ctx, &resp, ep, nil, options)
+       return resp, err
+}
+
 func (conn *Conn) SpecimenCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Specimen, error) {
        ep := arvados.EndpointSpecimenCreate
        var resp arvados.Specimen
@@ -467,11 +532,13 @@ func (conn *Conn) APIClientAuthorizationCurrent(ctx context.Context, options arv
 }
 
 type UserSessionAuthInfo struct {
-       Email           string   `json:"email"`
-       AlternateEmails []string `json:"alternate_emails"`
-       FirstName       string   `json:"first_name"`
-       LastName        string   `json:"last_name"`
-       Username        string   `json:"username"`
+       UserUUID        string    `json:"user_uuid"`
+       Email           string    `json:"email"`
+       AlternateEmails []string  `json:"alternate_emails"`
+       FirstName       string    `json:"first_name"`
+       LastName        string    `json:"last_name"`
+       Username        string    `json:"username"`
+       ExpiresAt       time.Time `json:"expires_at"`
 }
 
 type UserSessionCreateOptions struct {