Skip to content

Commit

Permalink
Merge pull request #102 from talset/master
Browse files Browse the repository at this point in the history
in: fix #95 add an option to not download the s3 file
  • Loading branch information
vito authored Jun 18, 2018
2 parents 4a519d8 + 69c387d commit d191598
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ version numbers.

* `skip_ssl_verification`: *Optional.* Skip SSL verification for S3 endpoint. Useful for S3 compatible providers using self-signed SSL certificates.

* `skip_download`: *Optional.* Skip downloading object from S3. Useful only trigger the pipeline without using the object.

* `server_side_encryption`: *Optional.* An encryption algorithm to use when
storing objects in S3.

Expand Down
40 changes: 21 additions & 19 deletions in/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,32 @@ func (command *Command) Run(destinationDir string, request Request) (Response, e
}
}
} else {
err = command.downloadFile(
request.Source.Bucket,
remotePath,
versionID,
destinationDir,
path.Base(remotePath),
)
if err != nil {
return Response{}, err
}

if request.Params.Unpack {
destinationPath := filepath.Join(destinationDir, path.Base(remotePath))
mime := archiveMimetype(destinationPath)
if mime == "" {
return Response{}, fmt.Errorf("not an archive: %s", destinationPath)
}

err = extractArchive(mime, destinationPath)
if !request.Source.SkipDownload {
err = command.downloadFile(
request.Source.Bucket,
remotePath,
versionID,
destinationDir,
path.Base(remotePath),
)
if err != nil {
return Response{}, err
}
}

if request.Params.Unpack {
destinationPath := filepath.Join(destinationDir, path.Base(remotePath))
mime := archiveMimetype(destinationPath)
if mime == "" {
return Response{}, fmt.Errorf("not an archive: %s", destinationPath)
}

err = extractArchive(mime, destinationPath)
if err != nil {
return Response{}, err
}
}
}
url = command.urlProvider.GetURL(request, remotePath)
if err = command.writeURLFile(destinationDir, url); err != nil {
return Response{}, err
Expand Down
12 changes: 12 additions & 0 deletions in/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ var _ = Describe("In Command", func() {
})
})

Context("when configured to skip download", func() {
BeforeEach(func() {
request.Source.SkipDownload = true
})

It("doesn't download the file", func() {
_, err := command.Run(destDir, request)
Ω(err).ShouldNot(HaveOccurred())
Ω(s3client.DownloadFileCallCount()).Should(Equal(0))
})
})

Context("when there is an existing version in the request", func() {
BeforeEach(func() {
request.Version.Path = "files/a-file-1.3"
Expand Down
1 change: 1 addition & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Source struct {
SSEKMSKeyId string `json:"sse_kms_key_id"`
UseV2Signing bool `json:"use_v2_signing"`
SkipSSLVerification bool `json:"skip_ssl_verification"`
SkipDownload bool `json:"skip_download"`
InitialVersion string `json:"initial_version"`
InitialPath string `json:"initial_path"`
InitialContentText string `json:"initial_content_text"`
Expand Down

0 comments on commit d191598

Please sign in to comment.