18790: Error out instead of retrying if server is too old.
[arvados.git] / lib / controller / rpc / conn.go
index 5176df59f4814ff27ecd29d6272126768255015e..9856eb5760c0d92e266caaf8ed89b49f53537bb7 100644 (file)
@@ -340,6 +340,12 @@ func (conn *Conn) ContainerUnlock(ctx context.Context, options arvados.GetOption
 }
 
 func (conn *Conn) ContainerLog(ctx context.Context, options arvados.ContainerLogOptions) (resp http.Handler, err error) {
+       tokens, err := conn.tokenProvider(ctx)
+       if err != nil {
+               return nil, err
+       } else if len(tokens) < 1 {
+               return nil, httpserver.ErrorWithStatus(errors.New("unauthorized"), http.StatusUnauthorized)
+       }
        proxy := &httputil.ReverseProxy{
                Transport: conn.httpClient.Transport,
                Director: func(r *http.Request) {
@@ -347,6 +353,7 @@ func (conn *Conn) ContainerLog(ctx context.Context, options arvados.ContainerLog
                        u.Path = r.URL.Path
                        u.RawQuery = fmt.Sprintf("no_forward=%v", options.NoForward)
                        r.URL = &u
+                       r.Header.Set("Authorization", "Bearer "+tokens[0])
                },
        }
        return proxy, nil
@@ -356,7 +363,7 @@ func (conn *Conn) ContainerLog(ctx context.Context, options arvados.ContainerLog
 // a running container. If the returned error is nil, the caller is
 // responsible for closing sshconn.Conn.
 func (conn *Conn) ContainerSSH(ctx context.Context, options arvados.ContainerSSHOptions) (sshconn arvados.ConnectionResponse, err error) {
-       u, err := conn.baseURL.Parse("/" + strings.Replace(arvados.EndpointContainerSSH.Path, "{uuid}", options.UUID, -1))
+       u, err := conn.baseURL.Parse("/" + strings.Replace(arvados.EndpointContainerSSHCompat.Path, "{uuid}", options.UUID, -1))
        if err != nil {
                err = fmt.Errorf("url.Parse: %w", err)
                return
@@ -372,7 +379,7 @@ func (conn *Conn) ContainerSSH(ctx context.Context, options arvados.ContainerSSH
 // the controller. The caller should connect the returned resp.Conn to
 // a client-side yamux session.
 func (conn *Conn) ContainerGatewayTunnel(ctx context.Context, options arvados.ContainerGatewayTunnelOptions) (tunnelconn arvados.ConnectionResponse, err error) {
-       u, err := conn.baseURL.Parse("/" + strings.Replace(arvados.EndpointContainerGatewayTunnel.Path, "{uuid}", options.UUID, -1))
+       u, err := conn.baseURL.Parse("/" + strings.Replace(arvados.EndpointContainerGatewayTunnelCompat.Path, "{uuid}", options.UUID, -1))
        if err != nil {
                err = fmt.Errorf("url.Parse: %w", err)
                return