|
@@ -1,6 +1,7 @@
|
1
|
1
|
package main
|
2
|
2
|
|
3
|
3
|
import (
|
|
4
|
+ "bytes"
|
4
|
5
|
"context"
|
5
|
6
|
"fmt"
|
6
|
7
|
"github.com/csmith/dotege/model"
|
|
@@ -191,7 +192,8 @@ func main() {
|
191
|
192
|
})
|
192
|
193
|
|
193
|
194
|
for name, container := range updatedContainers {
|
194
|
|
- updated = updated || deployCertForContainer(container)
|
|
195
|
+ certDeployed := deployCertForContainer(container)
|
|
196
|
+ updated = updated || certDeployed
|
195
|
197
|
delete(updatedContainers, name)
|
196
|
198
|
}
|
197
|
199
|
|
|
@@ -291,9 +293,15 @@ func deployCertForContainer(container *model.Container) bool {
|
291
|
293
|
|
292
|
294
|
func deployCert(certificate *SavedCertificate) bool {
|
293
|
295
|
target := path.Join(config.DefaultCertDestination, fmt.Sprintf("%s.pem", certificate.Domains[0]))
|
|
296
|
+ content := append(certificate.Certificate, certificate.PrivateKey...)
|
294
|
297
|
|
295
|
|
- // TODO: Check if the cert is different
|
296
|
|
- err := ioutil.WriteFile(target, append(certificate.Certificate, certificate.PrivateKey...), 0700)
|
|
298
|
+ buf, _ := ioutil.ReadFile(target)
|
|
299
|
+ if bytes.Equal(buf, content) {
|
|
300
|
+ logger.Debugf("Certificate was up to date: %s", target)
|
|
301
|
+ return false
|
|
302
|
+ }
|
|
303
|
+
|
|
304
|
+ err := ioutil.WriteFile(target, content, 0700)
|
297
|
305
|
if err != nil {
|
298
|
306
|
logger.Warnf("Unable to write certificate %s - %s", target, err.Error())
|
299
|
307
|
return false
|