Skip to content

Commit

Permalink
Merge pull request #103 from talset/master
Browse files Browse the repository at this point in the history
in: add skip_download override param by get
  • Loading branch information
vito authored Jul 30, 2018
2 parents d191598 + ae60db1 commit a71c092
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ Places the following files in the destination:

#### Parameters

* `unpack`: *Optional.* If true and the file is an archive (tar, gzipped tar, other gzipped file, or zip), unpack the file. Gzipped tarballs will be both ungzipped and untarred. It is ignored when `get` is running on the initial version.
* `skip_download`: *Optional.* Skip downloading object from S3. Same parameter as source configuration but used to define/override by get. Value need to be a true/false string.

* `unpack`: *Optional.* If true and the file is an archive (tar, gzipped tar, other gzipped file, or zip), unpack the file. Gzipped tarballs will be both ungzipped and untarred. It is ignored when `get` is running on the initial version.

### `out`: Upload an object to the bucket.

Expand Down
13 changes: 12 additions & 1 deletion in/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path"
"path/filepath"
"strconv"

"github.com/concourse/s3-resource"
"github.com/concourse/s3-resource/versions"
Expand Down Expand Up @@ -56,6 +57,7 @@ func (command *Command) Run(destinationDir string, request Request) (Response, e
var versionID string
var url string
var isInitialVersion bool
var skipDownload bool

if request.Source.Regexp != "" {
if request.Version.Path == "" {
Expand Down Expand Up @@ -99,7 +101,16 @@ func (command *Command) Run(destinationDir string, request Request) (Response, e
}
} else {

if !request.Source.SkipDownload {
if request.Params.SkipDownload != "" {
skipDownload, err = strconv.ParseBool(request.Params.SkipDownload)
if err != nil {
return Response{}, fmt.Errorf("skip_download defined but invalid value: %s", request.Params.SkipDownload)
}
} else {
skipDownload = request.Source.SkipDownload
}

if !skipDownload {
err = command.downloadFile(
request.Source.Bucket,
remotePath,
Expand Down
39 changes: 38 additions & 1 deletion in/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var _ = Describe("In Command", func() {
})
})

Context("when configured to skip download", func() {
Context("when configured globaly to skip download", func() {
BeforeEach(func() {
request.Source.SkipDownload = true
})
Expand All @@ -91,6 +91,43 @@ var _ = Describe("In Command", func() {
})
})

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

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

Context("when override localy to not skip download", func() {
BeforeEach(func() {
request.Source.SkipDownload = true
request.Params.SkipDownload = "false"
})

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

Context("when override using a wrong value for local skipdownload", func() {
BeforeEach(func() {
request.Params.SkipDownload = "foo"
})

It("doesn't download the file", func() {
_, err := command.Run(destDir, request)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("skip_download defined but invalid value"))
})
})

Context("when there is an existing version in the request", func() {
BeforeEach(func() {
request.Version.Path = "files/a-file-1.3"
Expand Down
3 changes: 2 additions & 1 deletion in/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ type Request struct {
}

type Params struct {
Unpack bool `json:"unpack"`
Unpack bool `json:"unpack"`
SkipDownload string `json:"skip_download"`
}

type Response struct {
Expand Down

0 comments on commit a71c092

Please sign in to comment.