mirror of
https://github.com/helm/helm.git
synced 2026-08-04 15:10:47 +00:00
Merge pull request #1202 from philips/use-digest-format
feat(repo): use OCI style digest identifiers
This commit is contained in:
@@ -23,7 +23,7 @@ alpine-0.1.0:
|
||||
name: alpine
|
||||
url: https://storage.googleapis.com/kubernetes-charts/alpine-0.1.0.tgz
|
||||
created: 2016-05-26 11:23:44.086354411 +0000 UTC
|
||||
checksum: a61575c2d3160e5e39abf2a5ec984d6119404b18
|
||||
digest: sha256:78e9a4282295184e8ce1496d23987993673f38e33e203c8bc18bc838a73e5864
|
||||
chartfile:
|
||||
name: alpine
|
||||
description: Deploy a basic Alpine Linux pod
|
||||
@@ -33,7 +33,7 @@ redis-2.0.0:
|
||||
name: redis
|
||||
url: https://storage.googleapis.com/kubernetes-charts/redis-2.0.0.tgz
|
||||
created: 2016-05-26 11:23:44.087939192 +0000 UTC
|
||||
checksum: 2cea3048cf85d588204e1b1cc0674472b4517919
|
||||
digest: sha256:bde9c2949e64d059c18d8f93566a64dafc6d2e8e259a70322fb804831dfd0b5b
|
||||
chartfile:
|
||||
name: redis
|
||||
description: Port of the replicatedservice template from kubernetes/charts
|
||||
|
||||
@@ -39,7 +39,7 @@ type ChartRef struct {
|
||||
URL string `yaml:"url"`
|
||||
Created string `yaml:"created,omitempty"`
|
||||
Removed bool `yaml:"removed,omitempty"`
|
||||
Checksum string `yaml:"checksum,omitempty"`
|
||||
Digest string `yaml:"digest,omitempty"`
|
||||
Chartfile *chart.Metadata `yaml:"chartfile"`
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,10 @@ limitations under the License.
|
||||
package repo // import "k8s.io/helm/pkg/repo"
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -131,7 +132,7 @@ func (r *ChartRepository) Index() error {
|
||||
}
|
||||
|
||||
chartfile := ch.Metadata
|
||||
hash, err := generateChecksum(path)
|
||||
digest, err := generateDigest(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -152,7 +153,7 @@ func (r *ChartRepository) Index() error {
|
||||
url, _ := url.Parse(r.URL)
|
||||
url.Path = filepath.Join(url.Path, key+".tgz")
|
||||
|
||||
entry := &ChartRef{Chartfile: chartfile, Name: chartfile.Name, URL: url.String(), Created: created, Checksum: hash, Removed: false}
|
||||
entry := &ChartRef{Chartfile: chartfile, Name: chartfile.Name, URL: url.String(), Created: created, Digest: digest, Removed: false}
|
||||
|
||||
r.IndexFile.Entries[key] = entry
|
||||
|
||||
@@ -170,18 +171,15 @@ func (r *ChartRepository) Index() error {
|
||||
return r.saveIndexFile()
|
||||
}
|
||||
|
||||
func generateChecksum(path string) (string, error) {
|
||||
func generateDigest(path string) (string, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
h := sha256.New()
|
||||
io.Copy(h, f)
|
||||
|
||||
result := sha1.Sum(b)
|
||||
|
||||
return fmt.Sprintf("%x", result), nil
|
||||
digest := h.Sum([]byte{})
|
||||
return "sha256:" + hex.EncodeToString(digest[:]), nil
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ func TestIndex(t *testing.T) {
|
||||
}
|
||||
timestamps[chartName] = details.Created
|
||||
|
||||
if details.Checksum == "" {
|
||||
t.Errorf("Checksum was not set for %s", chartName)
|
||||
if details.Digest == "" {
|
||||
t.Errorf("Digest was not set for %s", chartName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user