Skip to content

Commit 2d17ae7

Browse files
authored
Use filename as key in the hashes map (#28)
1 parent c1a255d commit 2d17ae7

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

internal/manifest/manifest.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Manifest struct {
3838
// certs is a map from subject name to CertificateManifest.
3939
certs map[string]*CertificateManifest
4040

41-
// hashes is a map from subject name to hash of CertificateManifest struct.
41+
// hashes is a map from file name (typically subject name) to hash of CertificateManifest struct.
4242
// It is stored and read from certyaml's .state file between consequent executions of certyaml.
4343
hashes map[string]string
4444

@@ -107,7 +107,7 @@ func GenerateCertificates(output io.Writer, manifestFile, stateFile, destDir str
107107
}
108108

109109
// Compare hash from state file to hash of the loaded certificate.
110-
hash, ok := m.hashes[c.Subject]
110+
hash, ok := m.hashes[c.Filename]
111111
if ok && c.GeneratedCert != nil && hash == c.hash() {
112112
fmt.Fprintf(output, "No changes: skipping %s\n", c.Filename)
113113
continue // Continue to next certificate in manifest.
@@ -117,12 +117,12 @@ func GenerateCertificates(output io.Writer, manifestFile, stateFile, destDir str
117117
// "adopt" the existing certificate like we would have generated it.
118118
if !ok && c.GeneratedCert != nil {
119119
fmt.Fprintf(output, "Recognized existing certificate: skipping %s\n", c.Filename)
120-
m.hashes[c.Subject] = c.hash()
120+
m.hashes[c.Filename] = c.hash()
121121
continue // Continue to next certificate in manifest.
122122
}
123123

124124
// Store hash of the current state of the certificate.
125-
m.hashes[c.Subject] = c.hash()
125+
m.hashes[c.Filename] = c.hash()
126126

127127
// Write the certificate and key to data dir.
128128
certFile := path.Join(m.dataDir, c.Filename+".pem")

internal/manifest/manifest_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ func TestManifestHandling(t *testing.T) {
6161
"server-root-ca.pem",
6262
"shortlived-key.pem",
6363
"shortlived.pem",
64+
"shortlived2m-key.pem",
65+
"shortlived2m.pem",
6466
"state.yaml",
6567
}
6668

internal/manifest/testdata/certs-state-1.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ subject: cn=shortlived
2525
issuer: cn=intermediate-ca
2626
expires: 1m
2727
---
28+
subject: cn=shortlived
29+
issuer: cn=intermediate-ca
30+
expires: 2m
31+
filename: shortlived2m
32+
---
2833
subject: cn=client-root-ca
2934
---
3035
subject: CN=John Doe,OU=People,O=Company

internal/manifest/testdata/certs-state-2.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ subject: cn=shortlived
2525
issuer: cn=intermediate-ca
2626
expires: 1m
2727
---
28+
subject: cn=shortlived
29+
issuer: cn=intermediate-ca
30+
expires: 2m
31+
filename: shortlived2m
32+
---
2833
subject: cn=client-root-ca
2934
---
3035
subject: CN=John Doe,OU=People,O=Company

0 commit comments

Comments
 (0)