Skip to content

Commit

Permalink
update --sha256 flag to --shasum
Browse files Browse the repository at this point in the history
* see changelog for more information

[#164716514]

Signed-off-by: Kira Boyle <[email protected]>
  • Loading branch information
jpmcb authored and kcboyle committed Apr 12, 2019
1 parent 25272b1 commit db59270
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ sometimes pushed post-release.
## 0.56.0 - Unreleased

### Breaking Changes
* the `upload-stemcell` flag `--shasum` has been changed to `--sha256`. `upload-product`
used the `--sha256` flag, and this change adds parity between the two
* the `upload-product` flag `--sha256` has been changed to `--shasum`. `upload-stemcell`
used the `--shasum` flag, and this change adds parity between the two. Using
`--shasum` instead of `--sha256` also future-proofs the flag when sha256 is no longer the
de facto way of defining shasums.

### Features
* `download-product` now supports skipping ssl validation when specifying `--pivnet-disable-ssl`
Expand Down
8 changes: 4 additions & 4 deletions commands/upload_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type UploadProduct struct {
ConfigFile string `long:"config" short:"c" description:"path to yml file for configuration (keys must match the following command line flags)"`
Product string `long:"product" short:"p" description:"path to product" required:"true"`
PollingInterval int `long:"polling-interval" short:"pi" description:"interval (in seconds) at which to print status" default:"1"`
Sha256 string `long:"sha256" description:"sha256 of the provided product file to be used for validation"`
Shasum string `long:"shasum" description:"shasum of the provided product file to be used for validation"`
Version string `long:"product-version" description:"version of the provided product file to be used for validation"`
}
metadataExtractor metadataExtractor
Expand Down Expand Up @@ -60,16 +60,16 @@ func (up UploadProduct) Execute(args []string) error {
return fmt.Errorf("could not parse upload-product flags: %s", err)
}

if up.Options.Sha256 != "" {
if up.Options.Shasum != "" {
shaValidator := validator.NewSHA256Calculator()
shasum, err := shaValidator.Checksum(up.Options.Product)

if err != nil {
return err
}

if shasum != up.Options.Sha256 {
return fmt.Errorf("expected shasum %s does not match file shasum %s", up.Options.Sha256, shasum)
if shasum != up.Options.Shasum {
return fmt.Errorf("expected shasum %s does not match file shasum %s", up.Options.Shasum, shasum)
}

up.logger.Printf("expected shasum matches product shasum.")
Expand Down
8 changes: 4 additions & 4 deletions commands/upload_product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var _ = Describe("UploadProduct", func() {
})
})

Context("when the --sha256 flag is defined", func() {
Context("when the --shasum flag is defined", func() {
It("proceeds normally when the sha sums match", func() {
file, err := ioutil.TempFile("", "test-file.yaml")
Expect(err).ToNot(HaveOccurred())
Expand All @@ -134,7 +134,7 @@ var _ = Describe("UploadProduct", func() {

err = command.Execute([]string{
"--product", file.Name(),
"--sha256", "2815ab9694a4a2cfd59424a734833010e143a0b2db20be3741507f177f289f44",
"--shasum", "2815ab9694a4a2cfd59424a734833010e143a0b2db20be3741507f177f289f44",
})
Expect(err).NotTo(HaveOccurred())
Expect(metadataExtractor.ExtractMetadataCallCount()).To(Equal(1))
Expand All @@ -157,7 +157,7 @@ var _ = Describe("UploadProduct", func() {
command := commands.NewUploadProduct(multipart, metadataExtractor, fakeService, logger)
err = command.Execute([]string{
"--product", file.Name(),
"--sha256", "not-the-correct-shasum",
"--shasum", "not-the-correct-shasum",
})
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("expected shasum not-the-correct-shasum does not match file shasum 2815ab9694a4a2cfd59424a734833010e143a0b2db20be3741507f177f289f44"))
Expand All @@ -167,7 +167,7 @@ var _ = Describe("UploadProduct", func() {
command := commands.NewUploadProduct(multipart, metadataExtractor, fakeService, logger)
err := command.Execute([]string{
"--product", "/path/to/testing.tgz",
"--sha256", "not-the-correct-shasum",
"--shasum", "not-the-correct-shasum",
})
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("open /path/to/testing.tgz: no such file or directory"))
Expand Down
8 changes: 4 additions & 4 deletions commands/upload_stemcell.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type UploadStemcell struct {
Stemcell string `long:"stemcell" short:"s" required:"true" description:"path to stemcell"`
Force bool `long:"force" short:"f" description:"upload stemcell even if it already exists on the target Ops Manager"`
Floating bool `long:"floating" default:"true" description:"assigns the stemcell to all compatible products "`
Sha256 string `long:"sha256" description:"sha256 of the provided product file to be used for validation"`
Shasum string `long:"shasum" description:"shasum of the provided product file to be used for validation"`
}
}

Expand Down Expand Up @@ -66,16 +66,16 @@ func (us UploadStemcell) Execute(args []string) error {
}

stemcellFilename := us.Options.Stemcell
if us.Options.Sha256 != "" {
if us.Options.Shasum != "" {
shaValidator := validator.NewSHA256Calculator()
shasum, err := shaValidator.Checksum(stemcellFilename)

if err != nil {
return err
}

if shasum != us.Options.Sha256 {
return fmt.Errorf("expected shasum %s does not match file shasum %s", us.Options.Sha256, shasum)
if shasum != us.Options.Shasum {
return fmt.Errorf("expected shasum %s does not match file shasum %s", us.Options.Shasum, shasum)
}

us.logger.Printf("expected shasum matches stemcell shasum.")
Expand Down
10 changes: 5 additions & 5 deletions commands/upload_stemcell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ var _ = Describe("UploadStemcell", func() {
})
})

Context("when the --sha256 flag is defined", func() {
Context("when the --shasum flag is defined", func() {
It("proceeds normally when the sha sums match", func() {
file, err := ioutil.TempFile("", "test-file.tgz")
Expect(err).ToNot(HaveOccurred())
Expand All @@ -269,7 +269,7 @@ var _ = Describe("UploadStemcell", func() {
command := commands.NewUploadStemcell(multipart, fakeService, logger)
err = command.Execute([]string{
"--stemcell", file.Name(),
"--sha256", "2815ab9694a4a2cfd59424a734833010e143a0b2db20be3741507f177f289f44",
"--shasum", "2815ab9694a4a2cfd59424a734833010e143a0b2db20be3741507f177f289f44",
})
Expect(err).NotTo(HaveOccurred())
format, v := logger.PrintfArgsForCall(0)
Expand All @@ -288,7 +288,7 @@ var _ = Describe("UploadStemcell", func() {
command := commands.NewUploadStemcell(multipart, fakeService, logger)
err = command.Execute([]string{
"--stemcell", file.Name(),
"--sha256", "not-the-correct-shasum",
"--shasum", "not-the-correct-shasum",
})
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("expected shasum not-the-correct-shasum does not match file shasum 2815ab9694a4a2cfd59424a734833010e143a0b2db20be3741507f177f289f44"))
Expand All @@ -297,7 +297,7 @@ var _ = Describe("UploadStemcell", func() {
command := commands.NewUploadStemcell(multipart, fakeService, logger)
err := command.Execute([]string{
"--stemcell", "/path/to/testing.tgz",
"--sha256", "2815ab9694a4a2cfd59424a734833010e143a0b2db20be3741507f177f289f44",
"--shasum", "2815ab9694a4a2cfd59424a734833010e143a0b2db20be3741507f177f289f44",
})
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("open /path/to/testing.tgz: no such file or directory"))
Expand Down Expand Up @@ -356,7 +356,7 @@ var _ = Describe("UploadStemcell", func() {
BeforeEach(func() {
var err error
configContent := `
sha256: 2815ab9694a4a2cfd59424a734833010e143a0b2db20be3741507f177f289f44
shasum: 2815ab9694a4a2cfd59424a734833010e143a0b2db20be3741507f177f289f44
`
configFile, err = ioutil.TempFile("", "")
Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit db59270

Please sign in to comment.