Skip to content

Cleanup directories handling #765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Perform certificates migration if needed
  • Loading branch information
cmaglie committed Feb 10, 2023
commit 1d0d5de4b7483515155e11a0f6e27facea421eba
27 changes: 27 additions & 0 deletions certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,33 @@ func generateSingleCertificate(isCa bool) (*x509.Certificate, error) {
return &template, nil
}

// migrateCertificatesGeneratedWithOldAgentVersions checks if certificates generated
// with an old version of the Agent needs to be migrated to the current certificates
// directory, and performs the migration if needed.
func migrateCertificatesGeneratedWithOldAgentVersions(certsDir *paths.Path) {
if certsDir.Join("ca.cert.pem").Exist() {
// The new certificates are already set-up, nothing to do
return
}

fileList := []string{
"ca.key.pem",
"ca.cert.pem",
"ca.cert.cer",
"key.pem",
"cert.pem",
"cert.cer",
}
oldCertsDirPath, _ := os.Executable()
oldCertsDir := paths.New(oldCertsDirPath)
for _, fileName := range fileList {
oldCert := oldCertsDir.Join(fileName)
if oldCert.Exist() {
oldCert.CopyTo(certsDir.Join(fileName))
}
}
}

func generateCertificates(certsDir *paths.Path) {
certsDir.Join("ca.cert.pem").Remove()
certsDir.Join("ca.key.pem").Remove()
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ func main() {
generateCertificates(getCertificatesDir())
os.Exit(0)
}
// Check if certificates made with Agent <=1.2.7 needs to be moved over the new location
migrateCertificatesGeneratedWithOldAgentVersions(getCertificatesDir())

// Launch main loop in a goroutine
go loop()
Expand Down