X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2261d1fd9e1b69d0a60f1f7fe9029317aeb4cf52..cb68d4e34688abd308d7adffc288c82a5deb6c85:/lib/controller/router/router.go diff --git a/lib/controller/router/router.go b/lib/controller/router/router.go index 80d5e92985..054bcffaf7 100644 --- a/lib/controller/router/router.go +++ b/lib/controller/router/router.go @@ -86,6 +86,41 @@ func (rtr *router) addRoutes() { return rtr.backend.Logout(ctx, *opts.(*arvados.LogoutOptions)) }, }, + { + arvados.EndpointAuthorizedKeyCreate, + func() interface{} { return &arvados.CreateOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.AuthorizedKeyCreate(ctx, *opts.(*arvados.CreateOptions)) + }, + }, + { + arvados.EndpointAuthorizedKeyUpdate, + func() interface{} { return &arvados.UpdateOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.AuthorizedKeyUpdate(ctx, *opts.(*arvados.UpdateOptions)) + }, + }, + { + arvados.EndpointAuthorizedKeyGet, + func() interface{} { return &arvados.GetOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.AuthorizedKeyGet(ctx, *opts.(*arvados.GetOptions)) + }, + }, + { + arvados.EndpointAuthorizedKeyList, + func() interface{} { return &arvados.ListOptions{Limit: -1} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.AuthorizedKeyList(ctx, *opts.(*arvados.ListOptions)) + }, + }, + { + arvados.EndpointAuthorizedKeyDelete, + func() interface{} { return &arvados.DeleteOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.AuthorizedKeyDelete(ctx, *opts.(*arvados.DeleteOptions)) + }, + }, { arvados.EndpointCollectionCreate, func() interface{} { return &arvados.CreateOptions{} }, @@ -156,6 +191,13 @@ func (rtr *router) addRoutes() { return rtr.backend.ContainerCreate(ctx, *opts.(*arvados.CreateOptions)) }, }, + { + arvados.EndpointContainerPriorityUpdate, + func() interface{} { return &arvados.UpdateOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.ContainerPriorityUpdate(ctx, *opts.(*arvados.UpdateOptions)) + }, + }, { arvados.EndpointContainerUpdate, func() interface{} { return &arvados.UpdateOptions{} }, @@ -184,41 +226,6 @@ func (rtr *router) addRoutes() { return rtr.backend.ContainerDelete(ctx, *opts.(*arvados.DeleteOptions)) }, }, - { - arvados.EndpointContainerRequestCreate, - func() interface{} { return &arvados.CreateOptions{} }, - func(ctx context.Context, opts interface{}) (interface{}, error) { - return rtr.backend.ContainerRequestCreate(ctx, *opts.(*arvados.CreateOptions)) - }, - }, - { - arvados.EndpointContainerRequestUpdate, - func() interface{} { return &arvados.UpdateOptions{} }, - func(ctx context.Context, opts interface{}) (interface{}, error) { - return rtr.backend.ContainerRequestUpdate(ctx, *opts.(*arvados.UpdateOptions)) - }, - }, - { - arvados.EndpointContainerRequestGet, - func() interface{} { return &arvados.GetOptions{} }, - func(ctx context.Context, opts interface{}) (interface{}, error) { - return rtr.backend.ContainerRequestGet(ctx, *opts.(*arvados.GetOptions)) - }, - }, - { - arvados.EndpointContainerRequestList, - func() interface{} { return &arvados.ListOptions{Limit: -1} }, - func(ctx context.Context, opts interface{}) (interface{}, error) { - return rtr.backend.ContainerRequestList(ctx, *opts.(*arvados.ListOptions)) - }, - }, - { - arvados.EndpointContainerRequestDelete, - func() interface{} { return &arvados.DeleteOptions{} }, - func(ctx context.Context, opts interface{}) (interface{}, error) { - return rtr.backend.ContainerRequestDelete(ctx, *opts.(*arvados.DeleteOptions)) - }, - }, { arvados.EndpointContainerLock, func() interface{} { @@ -244,6 +251,13 @@ func (rtr *router) addRoutes() { return rtr.backend.ContainerSSH(ctx, *opts.(*arvados.ContainerSSHOptions)) }, }, + { + arvados.EndpointContainerSSHCompat, + func() interface{} { return &arvados.ContainerSSHOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.ContainerSSH(ctx, *opts.(*arvados.ContainerSSHOptions)) + }, + }, { // arvados-client built before commit // bdc29d3129f6d75aa9ce0a24ffb849a272b06f08 @@ -262,6 +276,62 @@ func (rtr *router) addRoutes() { return rtr.backend.ContainerGatewayTunnel(ctx, *opts.(*arvados.ContainerGatewayTunnelOptions)) }, }, + { + arvados.EndpointContainerGatewayTunnelCompat, + func() interface{} { return &arvados.ContainerGatewayTunnelOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.ContainerGatewayTunnel(ctx, *opts.(*arvados.ContainerGatewayTunnelOptions)) + }, + }, + { + arvados.EndpointContainerRequestCreate, + func() interface{} { return &arvados.CreateOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.ContainerRequestCreate(ctx, *opts.(*arvados.CreateOptions)) + }, + }, + { + arvados.EndpointContainerRequestUpdate, + func() interface{} { return &arvados.UpdateOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.ContainerRequestUpdate(ctx, *opts.(*arvados.UpdateOptions)) + }, + }, + { + arvados.EndpointContainerRequestGet, + func() interface{} { return &arvados.GetOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.ContainerRequestGet(ctx, *opts.(*arvados.GetOptions)) + }, + }, + { + arvados.EndpointContainerRequestList, + func() interface{} { return &arvados.ListOptions{Limit: -1} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.ContainerRequestList(ctx, *opts.(*arvados.ListOptions)) + }, + }, + { + arvados.EndpointContainerRequestDelete, + func() interface{} { return &arvados.DeleteOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.ContainerRequestDelete(ctx, *opts.(*arvados.DeleteOptions)) + }, + }, + { + arvados.EndpointContainerRequestContainerStatus, + func() interface{} { return &arvados.GetOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.ContainerRequestContainerStatus(ctx, *opts.(*arvados.GetOptions)) + }, + }, + { + arvados.EndpointContainerRequestLog, + func() interface{} { return &arvados.ContainerLogOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.ContainerRequestLog(ctx, *opts.(*arvados.ContainerLogOptions)) + }, + }, { arvados.EndpointGroupCreate, func() interface{} { return &arvados.CreateOptions{} }, @@ -367,6 +437,41 @@ func (rtr *router) addRoutes() { return rtr.backend.LinkDelete(ctx, *opts.(*arvados.DeleteOptions)) }, }, + { + arvados.EndpointLogCreate, + func() interface{} { return &arvados.CreateOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.LogCreate(ctx, *opts.(*arvados.CreateOptions)) + }, + }, + { + arvados.EndpointLogUpdate, + func() interface{} { return &arvados.UpdateOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.LogUpdate(ctx, *opts.(*arvados.UpdateOptions)) + }, + }, + { + arvados.EndpointLogList, + func() interface{} { return &arvados.ListOptions{Limit: -1} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.LogList(ctx, *opts.(*arvados.ListOptions)) + }, + }, + { + arvados.EndpointLogGet, + func() interface{} { return &arvados.GetOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.LogGet(ctx, *opts.(*arvados.GetOptions)) + }, + }, + { + arvados.EndpointLogDelete, + func() interface{} { return &arvados.DeleteOptions{} }, + func(ctx context.Context, opts interface{}) (interface{}, error) { + return rtr.backend.LogDelete(ctx, *opts.(*arvados.DeleteOptions)) + }, + }, { arvados.EndpointSpecimenCreate, func() interface{} { return &arvados.CreateOptions{} }, @@ -543,9 +648,23 @@ func (rtr *router) addRoutes() { rtr.addRoute(route.endpoint, route.defaultOpts, exec) } rtr.mux.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + if req.Method == "OPTIONS" { + // For non-webdav endpoints, return an empty + // response with the CORS headers we already + // added in ServeHTTP. + w.WriteHeader(http.StatusOK) + return + } httpserver.Errors(w, []string{"API endpoint not found"}, http.StatusNotFound) }) rtr.mux.MethodNotAllowedHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + if req.Method == "OPTIONS" { + // For non-webdav endpoints, return an empty + // response with the CORS headers we already + // added in ServeHTTP. + w.WriteHeader(http.StatusOK) + return + } httpserver.Errors(w, []string{"API endpoint not found"}, http.StatusMethodNotAllowed) }) } @@ -560,9 +679,14 @@ func (rtr *router) addRoute(endpoint arvados.APIEndpoint, defaultOpts func() int if alt, ok := altMethod[endpoint.Method]; ok { methods = append(methods, alt) } + if strings.HasSuffix(endpoint.Path, ".*}") { + // webdav methods + methods = append(methods, "OPTIONS", "PROPFIND") + } rtr.mux.Methods(methods...).Path("/" + endpoint.Path).HandlerFunc(func(w http.ResponseWriter, req *http.Request) { logger := ctxlog.FromContext(req.Context()) - params, err := rtr.loadRequestParams(req, endpoint.AttrsKey) + opts := defaultOpts() + params, err := rtr.loadRequestParams(req, endpoint.AttrsKey, opts) if err != nil { logger.WithFields(logrus.Fields{ "req": req, @@ -572,13 +696,6 @@ func (rtr *router) addRoute(endpoint arvados.APIEndpoint, defaultOpts func() int rtr.sendError(w, err) return } - opts := defaultOpts() - err = rtr.transcode(params, opts) - if err != nil { - logger.WithField("params", params).WithError(err).Debugf("error transcoding params to %T", opts) - rtr.sendError(w, err) - return - } respOpts, err := rtr.responseOptions(opts) if err != nil { logger.WithField("opts", opts).WithError(err).Debugf("error getting response options from %T", opts) @@ -601,11 +718,8 @@ func (rtr *router) addRoute(endpoint arvados.APIEndpoint, defaultOpts func() int } ctx := auth.NewContext(req.Context(), creds) ctx = arvados.ContextWithRequestID(ctx, req.Header.Get("X-Request-Id")) - logger.WithFields(logrus.Fields{ - "apiEndpoint": endpoint, - "apiOptsType": fmt.Sprintf("%T", opts), - "apiOpts": opts, - }).Debug("exec") + req = req.WithContext(ctx) + // Extract the token UUIDs (or a placeholder for v1 tokens) var tokenUUIDs []string for _, t := range creds.Tokens { @@ -622,7 +736,13 @@ func (rtr *router) addRoute(endpoint arvados.APIEndpoint, defaultOpts func() int tokenUUIDs = append(tokenUUIDs, "v1 token ending in "+end) } } - httpserver.SetResponseLogFields(req.Context(), logrus.Fields{"tokenUUIDs": tokenUUIDs}) + httpserver.SetResponseLogFields(ctx, logrus.Fields{"tokenUUIDs": tokenUUIDs}) + + logger.WithFields(logrus.Fields{ + "apiEndpoint": endpoint, + "apiOptsType": fmt.Sprintf("%T", opts), + "apiOpts": opts, + }).Debug("exec") resp, err := exec(ctx, opts) if err != nil { logger.WithError(err).Debugf("returning error type %T", err) @@ -638,13 +758,11 @@ func (rtr *router) ServeHTTP(w http.ResponseWriter, r *http.Request) { case "login", "logout", "auth": default: w.Header().Set("Access-Control-Allow-Origin", "*") - w.Header().Set("Access-Control-Allow-Methods", "GET, HEAD, PUT, POST, PATCH, DELETE") - w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type, X-Http-Method-Override") + w.Header().Set("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS, PROPFIND, PUT, POST, PATCH, DELETE") + w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type, Range, X-Http-Method-Override") + w.Header().Set("Access-Control-Expose-Headers", "Content-Range") w.Header().Set("Access-Control-Max-Age", "86486400") } - if r.Method == "OPTIONS" { - return - } if r.Body != nil { // Wrap r.Body in a http.MaxBytesReader(), otherwise // r.ParseForm() uses a default max request body size