2
0

migrate_ee.go 998 B

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