diff --git a/README.md b/README.md index 4c8f3967..5bb5f510 100644 --- a/README.md +++ b/README.md @@ -103,11 +103,13 @@ object's filename is the resulting version. Places the following files in the destination: -* `(filename)`: The file fetched from the bucket. +* `(filename)`: The file fetched from the bucket (if `skip_download` is not `true`). * `url`: A file containing the URL of the object. If `private` is true, this URL will be signed. +* `s3_uri`: A file containing the S3 URI of the object (for use with `aws cp`, etc.) + * `version`: The version identified in the file name. * `tags.json`: The object's tags represented as a JSON object. Only written if `download_tags` is set to true. diff --git a/in/command.go b/in/command.go index ba6d21c9..13d6ca45 100644 --- a/in/command.go +++ b/in/command.go @@ -10,7 +10,7 @@ import ( "path/filepath" "strconv" - "github.com/concourse/s3-resource" + s3resource "github.com/concourse/s3-resource" "github.com/concourse/s3-resource/versions" ) @@ -28,6 +28,10 @@ func (up *RequestURLProvider) s3URL(request Request, remotePath string) string { return up.s3Client.URL(request.Source.Bucket, remotePath, request.Source.Private, request.Version.VersionID) } +func GetS3URI(request Request, remotePath string) string { + return "s3://" + request.Source.Bucket + "/" + remotePath +} + type Command struct { s3client s3resource.S3Client urlProvider RequestURLProvider @@ -56,6 +60,7 @@ func (command *Command) Run(destinationDir string, request Request) (Response, e var versionNumber string var versionID string var url string + var s3_uri string var isInitialVersion bool var skipDownload bool @@ -152,9 +157,13 @@ func (command *Command) Run(destinationDir string, request Request) (Response, e if err = command.writeURLFile(destinationDir, url); err != nil { return Response{}, err } + s3_uri = GetS3URI(request, remotePath) + if err = command.writeS3URIFile(destinationDir, s3_uri); err != nil { + return Response{}, err + } } - err = command.writeVersionFile(versionNumber, destinationDir) + err = command.writeVersionFile(destinationDir, versionNumber) if err != nil { return Response{}, err } @@ -182,7 +191,11 @@ func (command *Command) writeURLFile(destDir string, url string) error { return ioutil.WriteFile(filepath.Join(destDir, "url"), []byte(url), 0644) } -func (command *Command) writeVersionFile(versionNumber string, destDir string) error { +func (command *Command) writeS3URIFile(destDir string, s3_uri string) error { + return ioutil.WriteFile(filepath.Join(destDir, "s3_uri"), []byte(s3_uri), 0644) +} + +func (command *Command) writeVersionFile(destDir string, versionNumber string) error { return ioutil.WriteFile(filepath.Join(destDir, "version"), []byte(versionNumber), 0644) }