Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add s3_uri and file_path support #165

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 16 additions & 3 deletions in/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}

Expand Down