diff --git a/cmd/out/main.go b/cmd/out/main.go index cb025d7b..6101c6aa 100644 --- a/cmd/out/main.go +++ b/cmd/out/main.go @@ -14,7 +14,7 @@ func main() { os.Exit(1) } - var request out.OutRequest + var request out.Request inputRequest(&request) sourceDir := os.Args[1] @@ -35,7 +35,7 @@ func main() { request.Source.UseV2Signing, ) - command := out.NewOutCommand(os.Stderr, client) + command := out.NewCommand(os.Stderr, client) response, err := command.Run(sourceDir, request) if err != nil { s3resource.Fatal("running command", err) @@ -44,13 +44,13 @@ func main() { outputResponse(response) } -func inputRequest(request *out.OutRequest) { +func inputRequest(request *out.Request) { if err := json.NewDecoder(os.Stdin).Decode(request); err != nil { s3resource.Fatal("reading request from stdin", err) } } -func outputResponse(response out.OutResponse) { +func outputResponse(response out.Response) { if err := json.NewEncoder(os.Stdout).Encode(response); err != nil { s3resource.Fatal("writing response to stdout", err) } diff --git a/integration/out_test.go b/integration/out_test.go index 5a1d9d4a..3431f9bb 100644 --- a/integration/out_test.go +++ b/integration/out_test.go @@ -57,10 +57,10 @@ var _ = Describe("out", func() { }) Context("with a versioned_file and a regex", func() { - var outRequest out.OutRequest + var outRequest out.Request BeforeEach(func() { - outRequest = out.OutRequest{ + outRequest = out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -88,7 +88,7 @@ var _ = Describe("out", func() { BeforeEach(func() { ioutil.WriteFile(filepath.Join(sourceDir, "content-typed-file"), []byte("text only"), 0755) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -131,7 +131,7 @@ var _ = Describe("out", func() { BeforeEach(func() { ioutil.WriteFile(filepath.Join(sourceDir, "uncontent-typed-file"), []byte("text only"), 0755) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -172,7 +172,7 @@ var _ = Describe("out", func() { Context("with a file glob and from", func() { BeforeEach(func() { - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -218,7 +218,7 @@ var _ = Describe("out", func() { err := ioutil.WriteFile(filepath.Join(sourceDir, "glob-file-to-upload"), []byte("contents"), 0755) Ω(err).ShouldNot(HaveOccurred()) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -251,11 +251,11 @@ var _ = Describe("out", func() { reader := bytes.NewBuffer(session.Buffer().Contents()) - var response out.OutResponse + var response out.Response err = json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(out.OutResponse{ + Ω(response).Should(Equal(out.Response{ Version: s3resource.Version{ Path: filepath.Join(directoryPrefix, "glob-file-to-upload"), }, @@ -297,7 +297,7 @@ var _ = Describe("out", func() { err := ioutil.WriteFile(filepath.Join(sourceDir, "file-to-upload"), []byte("contents"), 0755) Ω(err).ShouldNot(HaveOccurred()) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -324,11 +324,11 @@ var _ = Describe("out", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response out.OutResponse + var response out.Response err = json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(out.OutResponse{ + Ω(response).Should(Equal(out.Response{ Version: s3resource.Version{ Path: filepath.Join(directoryPrefix, "file-to-upload"), }, @@ -351,7 +351,7 @@ var _ = Describe("out", func() { err := ioutil.WriteFile(filepath.Join(sourceDir, "file-to-upload-local"), []byte("contents"), 0755) Ω(err).ShouldNot(HaveOccurred()) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -401,7 +401,7 @@ var _ = Describe("out", func() { err := ioutil.WriteFile(filepath.Join(sourceDir, "file-to-upload-local"), []byte("contents"), 0755) Ω(err).ShouldNot(HaveOccurred()) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -429,14 +429,14 @@ var _ = Describe("out", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response out.OutResponse + var response out.Response err = json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) versions, err := s3client.BucketFileVersions(versionedBucketName, filepath.Join(directoryPrefix, "file-to-upload")) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(out.OutResponse{ + Ω(response).Should(Equal(out.Response{ Version: s3resource.Version{ VersionID: versions[0], }, @@ -459,7 +459,7 @@ var _ = Describe("out", func() { err := ioutil.WriteFile(filepath.Join(sourceDir, "file-to-upload"), []byte("contents"), 0755) Ω(err).ShouldNot(HaveOccurred()) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -486,14 +486,14 @@ var _ = Describe("out", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response out.OutResponse + var response out.Response err = json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) versions, err := s3client.BucketFileVersions(versionedBucketName, filepath.Join(directoryPrefix, "file-to-upload")) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(out.OutResponse{ + Ω(response).Should(Equal(out.Response{ Version: s3resource.Version{ Path: filepath.Join(directoryPrefix, "file-to-upload"), }, diff --git a/out/models.go b/out/models.go index 72e4a273..29240aca 100644 --- a/out/models.go +++ b/out/models.go @@ -4,7 +4,7 @@ import ( "github.com/concourse/s3-resource" ) -type OutRequest struct { +type Request struct { Source s3resource.Source `json:"source"` Params Params `json:"params"` } @@ -17,7 +17,7 @@ type Params struct { ContentType string `json:"content_type"` } -type OutResponse struct { +type Response struct { Version s3resource.Version `json:"version"` Metadata []s3resource.MetadataPair `json:"metadata"` } diff --git a/out/out_command.go b/out/out_command.go index 5177597f..765b50f0 100644 --- a/out/out_command.go +++ b/out/out_command.go @@ -22,33 +22,33 @@ func init() { ErrorColor.EnableColor() } -type OutCommand struct { +type Command struct { stderr io.Writer s3client s3resource.S3Client } -func NewOutCommand(stderr io.Writer, s3client s3resource.S3Client) *OutCommand { - return &OutCommand{ +func NewCommand(stderr io.Writer, s3client s3resource.S3Client) *Command { + return &Command{ stderr: stderr, s3client: s3client, } } -func (command *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, error) { +func (command *Command) Run(sourceDir string, request Request) (Response, error) { if request.Params.From != "" || request.Params.To != "" { command.printDeprecationWarning() } if ok, message := request.Source.IsValid(); !ok { - return OutResponse{}, errors.New(message) + return Response{}, errors.New(message) } if request.Params.File != "" && request.Params.From != "" { - return OutResponse{}, errors.New("contains both file and from") + return Response{}, errors.New("contains both file and from") } localPath, err := command.match(request.Params, sourceDir) if err != nil { - return OutResponse{}, err + return Response{}, err } remotePath := command.remotePath(request, localPath, sourceDir) @@ -72,14 +72,14 @@ func (command *OutCommand) Run(sourceDir string, request OutRequest) (OutRespons options, ) if err != nil { - return OutResponse{}, err + return Response{}, err } version := s3resource.Version{} if request.Source.VersionedFile != "" { if versionID == "" { - return OutResponse{}, ErrObjectVersioningNotEnabled + return Response{}, ErrObjectVersioningNotEnabled } version.VersionID = versionID @@ -87,13 +87,13 @@ func (command *OutCommand) Run(sourceDir string, request OutRequest) (OutRespons version.Path = remotePath } - return OutResponse{ + return Response{ Version: version, Metadata: command.metadata(bucketName, remotePath, request.Source.Private, versionID), }, nil } -func (command *OutCommand) remotePath(request OutRequest, localPath string, sourceDir string) string { +func (command *Command) remotePath(request Request, localPath string, sourceDir string) string { if request.Source.VersionedFile != "" { return request.Source.VersionedFile } @@ -116,7 +116,7 @@ func parentDir(regexp string) string { return regexp[:strings.LastIndex(regexp, "/")+1] } -func (command *OutCommand) match(params Params, sourceDir string) (string, error) { +func (command *Command) match(params Params, sourceDir string) (string, error) { var matches []string var err error var pattern string @@ -149,7 +149,7 @@ func (command *OutCommand) match(params Params, sourceDir string) (string, error return matches[0], nil } -func (command *OutCommand) metadata(bucketName, remotePath string, private bool, versionID string) []s3resource.MetadataPair { +func (command *Command) metadata(bucketName, remotePath string, private bool, versionID string) []s3resource.MetadataPair { remoteFilename := filepath.Base(remotePath) metadata := []s3resource.MetadataPair{ @@ -169,7 +169,7 @@ func (command *OutCommand) metadata(bucketName, remotePath string, private bool, return metadata } -func (command *OutCommand) printDeprecationWarning() { +func (command *Command) printDeprecationWarning() { errorColor := ErrorColor.SprintFunc() blinkColor := BlinkingErrorColor.SprintFunc() command.stderr.Write([]byte(blinkColor("WARNING:"))) diff --git a/out/out_command_test.go b/out/out_command_test.go index 07561acf..0fdb86db 100644 --- a/out/out_command_test.go +++ b/out/out_command_test.go @@ -19,11 +19,11 @@ var _ = Describe("Out Command", func() { var ( tmpPath string sourceDir string - request out.OutRequest + request out.Request stderr *gbytes.Buffer s3client *fakes.FakeS3Client - command *out.OutCommand + command *out.Command ) BeforeEach(func() { @@ -35,7 +35,7 @@ var _ = Describe("Out Command", func() { err = os.MkdirAll(sourceDir, 0755) Ω(err).ShouldNot(HaveOccurred()) - request = out.OutRequest{ + request = out.Request{ Source: s3resource.Source{ Bucket: "bucket-name", }, @@ -43,7 +43,7 @@ var _ = Describe("Out Command", func() { s3client = &fakes.FakeS3Client{} stderr = gbytes.NewBuffer() - command = out.NewOutCommand(stderr, s3client) + command = out.NewCommand(stderr, s3client) }) AfterEach(func() {