Browse Source

Deploy all certs, don't write dupe certs

master
Chris Smith 5 years ago
parent
commit
be27a68171
1 changed files with 11 additions and 3 deletions
  1. 11
    3
      dotege.go

+ 11
- 3
dotege.go View File

1
 package main
1
 package main
2
 
2
 
3
 import (
3
 import (
4
+	"bytes"
4
 	"context"
5
 	"context"
5
 	"fmt"
6
 	"fmt"
6
 	"github.com/csmith/dotege/model"
7
 	"github.com/csmith/dotege/model"
191
 				})
192
 				})
192
 
193
 
193
 				for name, container := range updatedContainers {
194
 				for name, container := range updatedContainers {
194
-					updated = updated || deployCertForContainer(container)
195
+					certDeployed := deployCertForContainer(container)
196
+					updated = updated || certDeployed
195
 					delete(updatedContainers, name)
197
 					delete(updatedContainers, name)
196
 				}
198
 				}
197
 
199
 
291
 
293
 
292
 func deployCert(certificate *SavedCertificate) bool {
294
 func deployCert(certificate *SavedCertificate) bool {
293
 	target := path.Join(config.DefaultCertDestination, fmt.Sprintf("%s.pem", certificate.Domains[0]))
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
 	if err != nil {
305
 	if err != nil {
298
 		logger.Warnf("Unable to write certificate %s - %s", target, err.Error())
306
 		logger.Warnf("Unable to write certificate %s - %s", target, err.Error())
299
 		return false
307
 		return false

Loading…
Cancel
Save