Exclude generated time when calculating repo digest (#1254)

Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
This commit is contained in:
Sergio C. Arteaga 2021-04-19 11:17:29 +02:00 committed by GitHub
parent 3a3ce6e277
commit a633b6482a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -50,9 +50,7 @@ func (l *HelmIndexLoader) LoadIndex(r *hub.Repository) (*helmrepo.IndexFile, str
if err != nil {
return nil, "", err
}
hash := sha256.Sum256(indexBytes)
digest := hex.EncodeToString(hash[:])
return indexFile, digest, nil
return indexFile, getDigest(indexBytes), nil
}
// downloadIndexFile downloads a Helm repository's index file.
@ -89,3 +87,14 @@ func loadIndexFile(indexBytes []byte) (*helmrepo.IndexFile, error) {
indexFile.SortEntries()
return indexFile, nil
}
// getDigest returns the digest of a Helm repository's index file.
func getDigest(indexBytes []byte) string {
indexFile := &helmrepo.IndexFile{}
_ = yaml.UnmarshalStrict(indexBytes, indexFile)
indexFile.Generated = time.Time{}
indexBytes, _ = yaml.Marshal(indexFile)
hash := sha256.Sum256(indexBytes)
digest := hex.EncodeToString(hash[:])
return digest
}