migrate_ee.go 1012 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //go:build ee
  2. // +build ee
  3. package main
  4. import (
  5. "log"
  6. "github.com/joeshaw/envdecode"
  7. "github.com/porter-dev/porter/api/server/shared/config/env"
  8. "github.com/porter-dev/porter/ee/migrate"
  9. "gorm.io/gorm"
  10. )
  11. func InstanceMigrate(db *gorm.DB, dbConf *env.DBConf) error {
  12. if shouldRotateInit, shouldRotateFinalize := shouldVaultRotate(); shouldRotateInit {
  13. if err := migrate.MigrateVault(db, dbConf, shouldRotateFinalize); err != nil {
  14. return err
  15. }
  16. }
  17. return nil
  18. }
  19. type VaultMigrateConf struct {
  20. // we add a dummy field to avoid empty struct issue with envdecode
  21. DummyField string `env:"ASDF,default=asdf"`
  22. VaultMigrateInit bool `env:"VAULT_MIGRATE_INIT"`
  23. VaultMigrateFinalize bool `env:"VAULT_MIGRATE_FINALIZE"`
  24. }
  25. func shouldVaultRotate() (bool, bool) {
  26. var c VaultMigrateConf
  27. if err := envdecode.StrictDecode(&c); err != nil {
  28. log.Fatalf("Failed to decode Vault migration conf: %s", err)
  29. return false, false
  30. }
  31. return c.VaultMigrateInit, c.VaultMigrateFinalize
  32. }