diff --git a/cmd/cli/main.go b/cmd/cli/main.go deleted file mode 100644 index bfe9db77..00000000 --- a/cmd/cli/main.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "log" - - "github.com/spf13/cobra" -) - -func main() { - cmd := &cobra.Command{ - Use: "athens", - Short: "The athens dependency manager", - Example: usage, - SilenceUsage: true, - } - - cmd.AddCommand(newUploadCmd()) - - if err := cmd.Execute(); err != nil { - log.Fatal(err) - } - -} diff --git a/cmd/cli/upload.go b/cmd/cli/upload.go deleted file mode 100644 index 87c2bfbb..00000000 --- a/cmd/cli/upload.go +++ /dev/null @@ -1,98 +0,0 @@ -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "net/url" - "path" - "path/filepath" - - parser "github.com/gomods/athens/pkg/gomod/file" - "github.com/gomods/athens/pkg/module" - "github.com/gomods/athens/pkg/payloads" - "github.com/spf13/afero" - "github.com/spf13/cobra" -) - -type uploadCmd struct { - moduleName string - version string - baseURL string -} - -func newUploadCmd() *cobra.Command { - uploadCmd := &uploadCmd{} - cmd := &cobra.Command{ - Use: "upload [directory]", - Short: "package up a directory and upload it to the athens server", - Args: cobra.ExactArgs(1), - RunE: upload(uploadCmd), - } - cmd.Flags().StringVarP(&uploadCmd.version, "version", "v", "v0.0.1", "The version of this module") - cmd.Flags().StringVarP(&uploadCmd.baseURL, "base-url", "u", "http://localhost:3000/admin/upload", "The Athens base url.") - return cmd -} - -func upload(c *uploadCmd) func(*cobra.Command, []string) error { - return func(cmd *cobra.Command, args []string) error { - fs := afero.NewOsFs() - dir := args[0] - - fullDirectory, err := filepath.Abs(dir) - if err != nil { - return fmt.Errorf("couldn't get full directory (%s)", err) - } - cmd.Printf("found directory %s", fullDirectory) - modFilePath := filepath.Join(fullDirectory, "go.mod") - modBytes, err := afero.ReadFile(fs, modFilePath) - if err != nil { - return fmt.Errorf("couldn't find go.mod file (%s)", err) - } - - gomodParser := parser.NewFileParser(fs, modFilePath) - c.moduleName, err = gomodParser.ModuleName() - if err != nil { - return fmt.Errorf("couldn't parse go.mod file (%s)", err) - } - - zipReader := module.MakeZip(fs, fullDirectory, c.moduleName, c.version) - - infoFilePath := filepath.Join(fullDirectory, c.version+".info") - infoBytes, err := afero.ReadFile(fs, infoFilePath) - if err != nil { - return fmt.Errorf("coudln't find .info file (%s)", err) - } - - u, err := url.Parse(c.baseURL) - if err != nil { - return fmt.Errorf("not a valid base url (%s)", err) - } - - u.Path = path.Join(u.Path, c.moduleName, c.version) - zipBytes, err := ioutil.ReadAll(zipReader) - if err != nil { - return err - } - postBody := &payloads.Upload{ - Module: modBytes, - Zip: zipBytes, - Info: infoBytes, - } - buf := new(bytes.Buffer) - if err := json.NewEncoder(buf).Encode(postBody); err != nil { - return fmt.Errorf("error encoding json (%s)", err) - } - cmd.Printf("POSTing to %s", u) - resp, err := http.Post(u.String(), "application/json", buf) - if err != nil { - return fmt.Errorf("error uploading (%s)", err) - } else if resp.StatusCode != 200 { - return fmt.Errorf("upload failed because status code was %d", resp.StatusCode) - } - cmd.Println("Upload successful!") - return nil - } -} diff --git a/cmd/cli/usage.go b/cmd/cli/usage.go deleted file mode 100644 index ae4ac283..00000000 --- a/cmd/cli/usage.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -const usage = `athens --base-url foo.com --module bar --version v1.0.0 - -Details: - -- The directory from which code will be uploaded is -- ... and that directory must have a go.mod file in it -- ... and the go.mod file's 'module' directive must match 'bar' -- ... and if there's a vendor directory under that directory, it won't be ignored right now -- ... and the go.mod file will be uploaded with the source` diff --git a/cmd/proxy/actions/app_proxy.go b/cmd/proxy/actions/app_proxy.go index 0cc6c07f..43920106 100644 --- a/cmd/proxy/actions/app_proxy.go +++ b/cmd/proxy/actions/app_proxy.go @@ -12,7 +12,6 @@ func addProxyRoutes(app *buffalo.App, storage storage.Backend, mf *module.Filter 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)) - app.POST("/admin/upload/{module:[a-zA-Z./]+}/{version}", uploadHandler(storage)) app.POST("/admin/fetch/{module:[a-zA-Z./]+}/{owner}/{repo}/{ref}/{version}", fetchHandler(storage)) return nil } diff --git a/cmd/proxy/actions/upload.go b/cmd/proxy/actions/upload.go deleted file mode 100644 index b0be9fa3..00000000 --- a/cmd/proxy/actions/upload.go +++ /dev/null @@ -1,36 +0,0 @@ -package actions - -import ( - "bytes" - "net/http" - - "github.com/bketelsen/buffet" - "github.com/gobuffalo/buffalo" - "github.com/gomods/athens/pkg/paths" - "github.com/gomods/athens/pkg/payloads" - "github.com/gomods/athens/pkg/storage" - "github.com/pkg/errors" -) - -func uploadHandler(store storage.Saver) func(c buffalo.Context) error { - return func(c buffalo.Context) error { - sp := buffet.SpanFromContext(c) - sp.SetOperationName("uploadHandler") - mod, err := paths.GetModule(c) - if err != nil { - return errors.WithStack(err) - } - version := c.Param("version") - payload := new(payloads.Upload) - if c.Bind(payload); err != nil { - return errors.WithStack(err) - } - saveErr := store.Save(c, mod, version, payload.Module, bytes.NewReader(payload.Zip), payload.Info) - if storage.IsVersionAlreadyExistsErr(saveErr) { - return c.Error(http.StatusConflict, saveErr) - } else if err != nil { - return errors.WithStack(err) - } - return c.Render(http.StatusOK, proxy.JSON(nil)) - } -} diff --git a/pkg/payloads/upload.go b/pkg/payloads/upload.go index 8e344d42..8fed524f 100644 --- a/pkg/payloads/upload.go +++ b/pkg/payloads/upload.go @@ -2,13 +2,6 @@ package payloads import "github.com/gomods/athens/pkg/eventlog" -// Upload is used to send a module (zip and mod file) via POST request to the storage backend and save it there. -type Upload struct { - Module []byte `json:"module"` - Zip []byte `json:"zip"` - Info []byte `json:"info"` -} - // Module is used by proxy to send info about cache miss to Olympus type Module struct { Name string `json:"name"`