diff --git a/.gitignore b/.gitignore index eb576b19..106e3202 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ athens yarn-error.log cmd/proxy/proxy cmd/olympus/olympus -test-keys.json +test-keys.json +tmp \ No newline at end of file diff --git a/cmd/olympus/.env b/cmd/olympus/.env index 61c4a655..9925e17a 100644 --- a/cmd/olympus/.env +++ b/cmd/olympus/.env @@ -1,2 +1,2 @@ ATHENS_MONGO_STORAGE_URL=mongodb://127.0.0.1:27017 -PORT=3001 +PORT=:3001 diff --git a/cmd/olympus/actions/app.go b/cmd/olympus/actions/app.go index f463d3e0..2ec99da8 100644 --- a/cmd/olympus/actions/app.go +++ b/cmd/olympus/actions/app.go @@ -14,6 +14,7 @@ import ( "github.com/gobuffalo/packr" "github.com/gomods/athens/pkg/cdn/metadata/azurecdn" "github.com/gomods/athens/pkg/config/env" + "github.com/gomods/athens/pkg/download" "github.com/rs/cors" "github.com/unrolled/secure" ) @@ -109,6 +110,13 @@ func App() *buffalo.App { } app.GET("/", homeHandler) + + // Download Protocol + app.GET(download.PathList, download.ListHandler(storage, renderEng)) + app.GET(download.PathVersionInfo, download.VersionInfoHandler(storage, renderEng)) + app.GET(download.PathVersionModule, download.VersionModuleHandler(storage)) + app.GET(download.PathVersionZip, download.VersionZipHandler(storage)) + app.GET("/diff/{lastID}", diffHandler(storage, eventlogReader)) app.GET("/feed/{lastID}", feedHandler(storage)) app.GET("/eventlog/{sequence_id}", eventlogHandler(eventlogReader)) diff --git a/cmd/olympus/tmp/athens-build b/cmd/olympus/tmp/athens-build deleted file mode 100755 index d580718e..00000000 Binary files a/cmd/olympus/tmp/athens-build and /dev/null differ diff --git a/cmd/olympus/tmp/olympus-build b/cmd/olympus/tmp/olympus-build deleted file mode 100755 index d580718e..00000000 Binary files a/cmd/olympus/tmp/olympus-build and /dev/null differ diff --git a/cmd/proxy/actions/app_proxy.go b/cmd/proxy/actions/app_proxy.go index 43920106..83f165b6 100644 --- a/cmd/proxy/actions/app_proxy.go +++ b/cmd/proxy/actions/app_proxy.go @@ -2,16 +2,20 @@ package actions import ( "github.com/gobuffalo/buffalo" + "github.com/gomods/athens/pkg/download" "github.com/gomods/athens/pkg/module" "github.com/gomods/athens/pkg/storage" ) func addProxyRoutes(app *buffalo.App, storage storage.Backend, mf *module.Filter) error { app.GET("/", proxyHomeHandler) - app.GET("/{module:.+}/@v/list", listHandler(storage)) - app.GET("/{module:.+}/@v/{version}.info", cacheMissHandler(versionInfoHandler(storage), app.Worker, mf)) - app.GET("/{module:.+}/@v/{version}.mod", cacheMissHandler(versionModuleHandler(storage), app.Worker, mf)) - app.GET("/{module:.+}/@v/{version}.zip", cacheMissHandler(versionZipHandler(storage), app.Worker, mf)) + + // Download Protocol + app.GET(download.PathList, download.ListHandler(storage, proxy)) + app.GET(download.PathVersionInfo, cacheMissHandler(download.VersionInfoHandler(storage, proxy), app.Worker, mf)) + app.GET(download.PathVersionModule, cacheMissHandler(download.VersionModuleHandler(storage), app.Worker, mf)) + app.GET(download.PathVersionZip, cacheMissHandler(download.VersionZipHandler(storage), app.Worker, mf)) + app.POST("/admin/fetch/{module:[a-zA-Z./]+}/{owner}/{repo}/{ref}/{version}", fetchHandler(storage)) return nil } diff --git a/pkg/download/doc.go b/pkg/download/doc.go new file mode 100644 index 00000000..7d19c615 --- /dev/null +++ b/pkg/download/doc.go @@ -0,0 +1,6 @@ +// Package download provides buffalo handlers +// that implement vgo's Download Protocol. +// This is so that both Zeus and Olympus +// can share the same download protocol +// implementation. +package download diff --git a/cmd/proxy/actions/list.go b/pkg/download/list.go similarity index 62% rename from cmd/proxy/actions/list.go rename to pkg/download/list.go index 99232327..352e5980 100644 --- a/cmd/proxy/actions/list.go +++ b/pkg/download/list.go @@ -1,4 +1,4 @@ -package actions +package download import ( "net/http" @@ -6,12 +6,17 @@ import ( "github.com/bketelsen/buffet" "github.com/gobuffalo/buffalo" + "github.com/gobuffalo/buffalo/render" "github.com/gomods/athens/pkg/paths" "github.com/gomods/athens/pkg/storage" errs "github.com/pkg/errors" ) -func listHandler(lister storage.Lister) func(c buffalo.Context) error { +// PathList URL. +const PathList = "/{module:.+}/@v/list" + +// ListHandler implements GET baseURL/module/@v/list +func ListHandler(lister storage.Lister, eng *render.Engine) func(c buffalo.Context) error { return func(c buffalo.Context) error { sp := buffet.SpanFromContext(c) sp.SetOperationName("listHandler") @@ -25,6 +30,6 @@ func listHandler(lister storage.Lister) func(c buffalo.Context) error { } else if err != nil { return errs.WithStack(err) } - return c.Render(http.StatusOK, proxy.String(strings.Join(versions, "\n"))) + return c.Render(http.StatusOK, eng.String(strings.Join(versions, "\n"))) } } diff --git a/cmd/proxy/actions/version_info.go b/pkg/download/version_info.go similarity index 67% rename from cmd/proxy/actions/version_info.go rename to pkg/download/version_info.go index a29e9ccd..194c1c5a 100644 --- a/cmd/proxy/actions/version_info.go +++ b/pkg/download/version_info.go @@ -1,4 +1,4 @@ -package actions +package download import ( "encoding/json" @@ -7,11 +7,16 @@ import ( "github.com/bketelsen/buffet" "github.com/gobuffalo/buffalo" + "github.com/gobuffalo/buffalo/render" "github.com/gomods/athens/pkg/paths" "github.com/gomods/athens/pkg/storage" ) -func versionInfoHandler(getter storage.Getter) func(c buffalo.Context) error { +// PathVersionInfo URL. +const PathVersionInfo = "/{module:.+}/@v/{version}.info" + +// VersionInfoHandler implements GET baseURL/module/@v/version.info +func VersionInfoHandler(getter storage.Getter, eng *render.Engine) func(c buffalo.Context) error { return func(c buffalo.Context) error { sp := buffet.SpanFromContext(c) sp.SetOperationName("versionInfoHandler") @@ -30,6 +35,6 @@ func versionInfoHandler(getter storage.Getter) func(c buffalo.Context) error { if err != nil { return err } - return c.Render(http.StatusOK, proxy.JSON(revInfo)) + return c.Render(http.StatusOK, eng.JSON(revInfo)) } } diff --git a/cmd/proxy/actions/version_module.go b/pkg/download/version_module.go similarity index 75% rename from cmd/proxy/actions/version_module.go rename to pkg/download/version_module.go index c89d81aa..ffb05f80 100644 --- a/cmd/proxy/actions/version_module.go +++ b/pkg/download/version_module.go @@ -1,4 +1,4 @@ -package actions +package download import ( "fmt" @@ -10,7 +10,11 @@ import ( "github.com/gomods/athens/pkg/storage" ) -func versionModuleHandler(getter storage.Getter) func(c buffalo.Context) error { +// PathVersionModule URL. +const PathVersionModule = "/{module:.+}/@v/{version}.mod" + +// VersionModuleHandler implements GET baseURL/module/@v/version.mod +func VersionModuleHandler(getter storage.Getter) func(c buffalo.Context) error { return func(c buffalo.Context) error { sp := buffet.SpanFromContext(c) sp.SetOperationName("versionModuleHandler") diff --git a/cmd/proxy/actions/version_zip.go b/pkg/download/version_zip.go similarity index 77% rename from cmd/proxy/actions/version_zip.go rename to pkg/download/version_zip.go index 08bcb1c9..2075544a 100644 --- a/cmd/proxy/actions/version_zip.go +++ b/pkg/download/version_zip.go @@ -1,4 +1,4 @@ -package actions +package download import ( "fmt" @@ -11,7 +11,11 @@ import ( "github.com/gomods/athens/pkg/storage" ) -func versionZipHandler(getter storage.Getter) func(c buffalo.Context) error { +// PathVersionZip URL. +const PathVersionZip = "/{module:.+}/@v/{version}.zip" + +// VersionZipHandler implements GET baseURL/module/@v/version.zip +func VersionZipHandler(getter storage.Getter) func(c buffalo.Context) error { return func(c buffalo.Context) error { sp := buffet.SpanFromContext(c) sp.SetOperationName("versionZipHandler")