Olympus: implement download protocol (#238)

* Olympus: implement download protocol

* Download: change path names

* Git ignore tmp directories
This commit is contained in:
Marwan Sulaiman
2018-07-10 15:01:09 -04:00
committed by Aaron Schlesinger
parent 4c1694f760
commit e342cefbd9
11 changed files with 53 additions and 16 deletions
+2 -1
View File
@@ -22,4 +22,5 @@ athens
yarn-error.log
cmd/proxy/proxy
cmd/olympus/olympus
test-keys.json
test-keys.json
tmp
+1 -1
View File
@@ -1,2 +1,2 @@
ATHENS_MONGO_STORAGE_URL=mongodb://127.0.0.1:27017
PORT=3001
PORT=:3001
+8
View File
@@ -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))
Binary file not shown.
Binary file not shown.
+8 -4
View File
@@ -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
}
+6
View File
@@ -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
@@ -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")))
}
}
@@ -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))
}
}
@@ -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")
@@ -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")