diff --git a/api/api.go b/api/api.go index 6e3d1eec3..6aac57d77 100644 --- a/api/api.go +++ b/api/api.go @@ -292,6 +292,7 @@ func NewServerRoutes(s Server) *http.ServeMux { fsih := NewFSIHandlers(s.Instance, cfg.API.ReadOnly) m.Handle("/status/", s.middleware(fsih.StatusHandler)) m.Handle("/init/", s.middleware(fsih.InitHandler)) + m.Handle("/checkout/", s.middleware(fsih.CheckoutHandler)) renderh := NewRenderHandlers(node.Repo) m.Handle("/render/", s.middleware(renderh.RenderHandler)) diff --git a/api/fsi.go b/api/fsi.go index f20f147d3..5cd21ae72 100644 --- a/api/fsi.go +++ b/api/fsi.go @@ -68,7 +68,7 @@ func (h *FSIHandlers) statusHandler(w http.ResponseWriter, r *http.Request) { // InitHandler creates a new FSI-linked dataset func (h *FSIHandlers) InitHandler(w http.ResponseWriter, r *http.Request) { if h.ReadOnly { - readOnlyResponse(w, "/fsi/init") + readOnlyResponse(w, "/init") return } @@ -97,3 +97,35 @@ func (h *FSIHandlers) initHandler(w http.ResponseWriter, r *http.Request) { util.WriteResponse(w, map[string]string{"ref": name}) } + +// CheckoutHandler invokes checkout via an API call +func (h *FSIHandlers) CheckoutHandler(w http.ResponseWriter, r *http.Request) { + if h.ReadOnly { + readOnlyResponse(w, "/checkout") + return + } + + switch r.Method { + case "OPTIONS": + util.EmptyOkHandler(w, r) + case "POST": + h.checkoutHandler(w, r) + default: + util.NotFoundHandler(w,r) + } +} + +func (h *FSIHandlers) checkoutHandler(w http.ResponseWriter, r *http.Request) { + p := &lib.CheckoutParams{ + Dir: r.FormValue("dir"), + Ref: r.FormValue("ref"), + } + + var res string + if err := h.Checkout(p, &res); err != nil { + util.WriteErrResponse(w, http.StatusInternalServerError, err) + return + } + + util.WriteResponse(w, p) +}