Skip to content

Commit 1d0d5de

Browse files
committed
Perform certificates migration if needed
1 parent 1dab6b4 commit 1d0d5de

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

certificates.go

+27
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,33 @@ func generateSingleCertificate(isCa bool) (*x509.Certificate, error) {
133133
return &template, nil
134134
}
135135

136+
// migrateCertificatesGeneratedWithOldAgentVersions checks if certificates generated
137+
// with an old version of the Agent needs to be migrated to the current certificates
138+
// directory, and performs the migration if needed.
139+
func migrateCertificatesGeneratedWithOldAgentVersions(certsDir *paths.Path) {
140+
if certsDir.Join("ca.cert.pem").Exist() {
141+
// The new certificates are already set-up, nothing to do
142+
return
143+
}
144+
145+
fileList := []string{
146+
"ca.key.pem",
147+
"ca.cert.pem",
148+
"ca.cert.cer",
149+
"key.pem",
150+
"cert.pem",
151+
"cert.cer",
152+
}
153+
oldCertsDirPath, _ := os.Executable()
154+
oldCertsDir := paths.New(oldCertsDirPath)
155+
for _, fileName := range fileList {
156+
oldCert := oldCertsDir.Join(fileName)
157+
if oldCert.Exist() {
158+
oldCert.CopyTo(certsDir.Join(fileName))
159+
}
160+
}
161+
}
162+
136163
func generateCertificates(certsDir *paths.Path) {
137164
certsDir.Join("ca.cert.pem").Remove()
138165
certsDir.Join("ca.key.pem").Remove()

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ func main() {
131131
generateCertificates(getCertificatesDir())
132132
os.Exit(0)
133133
}
134+
// Check if certificates made with Agent <=1.2.7 needs to be moved over the new location
135+
migrateCertificatesGeneratedWithOldAgentVersions(getCertificatesDir())
134136

135137
// Launch main loop in a goroutine
136138
go loop()

0 commit comments

Comments
 (0)