add ability to store/create encrypted vcenter password
Some checks are pending
CI / Lint (push) Waiting to run
CI / Test (push) Waiting to run
CI / End-to-End (push) Waiting to run
CI / Publish Docker (push) Blocked by required conditions
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-09-27 17:02:02 +10:00
parent 5a00f4a8c7
commit 3501967c9e
13 changed files with 235 additions and 772 deletions

26
main.go
View File

@@ -9,9 +9,11 @@ import (
"runtime"
"time"
"vctp/db"
"vctp/internal/secrets"
"vctp/internal/settings"
"vctp/internal/tasks"
utils "vctp/internal/utils"
"vctp/internal/vcenter"
"vctp/log"
"vctp/server"
"vctp/server/router"
@@ -26,6 +28,7 @@ var (
buildTime string // when the executable was built
cronFrequency time.Duration
cronInvFrequency time.Duration
encryptionKey = []byte("5L1l3B5KvwOCzUHMAlCgsgUTRAYMfSpa")
)
func main() {
@@ -112,6 +115,25 @@ func main() {
utils.GenerateCerts(tlsCertFilename, tlsKeyFilename)
}
// Load vcenter credentials from .env
a := secrets.New(logger, encryptionKey)
vcEp := os.Getenv("VCENTER_PASSWORD")
if len(vcEp) == 0 {
logger.Error("No vcenter password configured")
os.Exit(1)
}
vcPass, err := a.Decrypt(vcEp)
if err != nil {
logger.Error("failed to decrypt vcenter credentials", "error", err)
//os.Exit(1)
}
creds := vcenter.VcenterLogin{
//insecureString := os.Getenv("VCENTER_INSECURE")
Username: os.Getenv("VCENTER_USERNAME"),
Password: string(vcPass),
}
// Prepare the task scheduler
c, err := gocron.NewScheduler()
if err != nil {
@@ -124,6 +146,7 @@ func main() {
Logger: logger,
Database: database,
Settings: s,
VcCreds: &creds,
}
cronFrequencyString := os.Getenv("VCENTER_EVENT_POLLING_SECONDS")
@@ -184,12 +207,13 @@ func main() {
c.Start()
// Start server
r := router.New(logger, database, buildTime, sha1ver, runtime.Version(), &creds, a)
svr := server.New(
logger,
c,
cancel,
bindAddress,
server.WithRouter(router.New(logger, database, buildTime, sha1ver, runtime.Version())),
server.WithRouter(r),
server.SetTls(bindDisableTls),
server.SetCertificate(tlsCertFilename),
server.SetPrivateKey(tlsKeyFilename),