@@ -14,15 +14,14 @@ import (
14
14
15
15
// certificateFile represents a certificate file.
16
16
type certificateFile struct {
17
- CertDir string
18
- ID string
19
- Contents []byte
17
+ certDir string
18
+ id string
20
19
}
21
20
22
- // certificateFileTag generates a certificate file tag/name. This is used to
23
- // index into the map of deleted certificates.
21
+ // Tag generates a certificate file tag/name. This is used to index into the
22
+ // the map of deleted certificates.
24
23
func (cf certificateFile ) Tag () string {
25
- return filepath .Join (cf .CertDir , cf .ID + ".pem" )
24
+ return filepath .Join (cf .certDir , cf .id + ".pem" )
26
25
}
27
26
28
27
// simpleCertificateManager is the default implementation of a certificateManager
@@ -96,7 +95,7 @@ func (cm *simpleCertificateManager) WriteCertificatesForConfig(config *ServiceAl
96
95
buffer .Write ([]byte (caCertObj .Contents ))
97
96
}
98
97
99
- certFile := certificateFile {CertDir : cm .cfg .certDir , ID : certObj .ID }
98
+ certFile := certificateFile {certDir : cm .cfg .certDir , id : certObj .ID }
100
99
delete (cm .deletedCertificates , certFile .Tag ())
101
100
if err := cm .w .WriteCertificate (cm .cfg .certDir , certObj .ID , buffer .Bytes ()); err != nil {
102
101
return err
@@ -109,7 +108,7 @@ func (cm *simpleCertificateManager) WriteCertificatesForConfig(config *ServiceAl
109
108
destCert , ok := config .Certificates [destCertKey ]
110
109
111
110
if ok {
112
- destCertFile := certificateFile {CertDir : cm .cfg .caCertDir , ID : destCert .ID }
111
+ destCertFile := certificateFile {certDir : cm .cfg .caCertDir , id : destCert .ID }
113
112
delete (cm .deletedCertificates , destCertFile .Tag ())
114
113
if err := cm .w .WriteCertificate (cm .cfg .caCertDir , destCert .ID , []byte (destCert .Contents )); err != nil {
115
114
return err
@@ -131,7 +130,7 @@ func (cm *simpleCertificateManager) DeleteCertificatesForConfig(config *ServiceA
131
130
certObj , ok := config .Certificates [certKey ]
132
131
133
132
if ok {
134
- certFile := certificateFile {CertDir : cm .cfg .certDir , ID : certObj .ID }
133
+ certFile := certificateFile {certDir : cm .cfg .certDir , id : certObj .ID }
135
134
cm .deletedCertificates [certFile .Tag ()] = certFile
136
135
}
137
136
}
@@ -141,8 +140,7 @@ func (cm *simpleCertificateManager) DeleteCertificatesForConfig(config *ServiceA
141
140
destCert , ok := config .Certificates [destCertKey ]
142
141
143
142
if ok {
144
-
145
- destCertFile := certificateFile {CertDir : cm .cfg .caCertDir , ID : destCert .ID }
143
+ destCertFile := certificateFile {certDir : cm .cfg .caCertDir , id : destCert .ID }
146
144
cm .deletedCertificates [destCertFile .Tag ()] = destCertFile
147
145
}
148
146
}
@@ -157,21 +155,19 @@ func (cm *simpleCertificateManager) Commit() error {
157
155
// reload because the config is invalid, so we _do_ need to "stage"
158
156
// or commit the removals. Remove all the deleted certificates.
159
157
for _ , certFile := range cm .deletedCertificates {
160
- err := cm .w .DeleteCertificate (certFile .CertDir , certFile .ID )
158
+ err := cm .w .DeleteCertificate (certFile .certDir , certFile .id )
161
159
if err != nil {
162
- // TODO: Do we care if a file deletion failed?
163
- // Otherwise we will keep hitting this error on
164
- // every commit. Should we just ignore errors here?
165
- // Clean this up based on review comments.
166
- // FIXME: return err
160
+ // Log a warning if the delete fails but proceed on.
161
+ glog .Warningf ("Ignoring error deleting certificate file %v: %v" , certFile .Tag (), err )
167
162
}
168
163
}
169
164
170
165
cm .deletedCertificates = make (map [string ]certificateFile , 0 )
171
166
172
167
// If we decide to stage the certificate writes, we can flush the
173
- // write to the disk here. The tradeoff is storing a copy in memory
174
- // until we commit.
168
+ // write to the disk here. Today, the certificate writes are done
169
+ // just before this function is called. The tradeoff is storing a
170
+ // copy in memory until we commit.
175
171
176
172
return nil
177
173
}
0 commit comments