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

Simpler sha256 tagger code #847

Merged
merged 1 commit into from
Jul 23, 2018
Merged
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
16 changes: 9 additions & 7 deletions pkg/skaffold/build/tag/sha256.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
)

// ChecksumTagger tags an image by the sha256 of the image tarball
type ChecksumTagger struct {
}
type ChecksumTagger struct{}

// Labels are labels specific to the sha256 tagger.
func (c *ChecksumTagger) Labels() map[string]string {
return map[string]string{
constants.Labels.TagPolicy: "sha256",
Expand All @@ -38,10 +38,12 @@ func (c *ChecksumTagger) GenerateFullyQualifiedImageName(workingDir string, opts
if opts == nil {
return "", fmt.Errorf("Tag options not provided")
}
digestSplit := strings.Split(opts.Digest, ":")
if len(digestSplit) != 2 {
return "", fmt.Errorf("Digest wrong format: %s, expected sha256:<checksum>", digestSplit)

digest := opts.Digest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't need this var

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used but I forgot to use it the line just after. Should be good now

sha256 := strings.TrimPrefix(opts.Digest, "sha256:")
if sha256 == digest {
return "", fmt.Errorf("Digest wrong format: %s, expected sha256:<checksum>", digest)
}
checksum := digestSplit[1]
return fmt.Sprintf("%s:%s", opts.ImageName, checksum), nil

return fmt.Sprintf("%s:%s", opts.ImageName, sha256), nil
}