init_ee.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //go:build ee
  2. // +build ee
  3. package loader
  4. import (
  5. eeBilling "github.com/porter-dev/porter/ee/billing"
  6. "github.com/porter-dev/porter/ee/integrations/vault"
  7. "github.com/porter-dev/porter/ee/models"
  8. "github.com/porter-dev/porter/internal/billing"
  9. )
  10. func init() {
  11. sharedInit()
  12. InstanceDB.AutoMigrate(
  13. &models.ProjectBilling{},
  14. &models.UserBilling{},
  15. )
  16. var key [32]byte
  17. for i, b := range []byte(InstanceEnvConf.DBConf.EncryptionKey) {
  18. key[i] = b
  19. }
  20. if InstanceEnvConf.ServerConf.BillingPrivateServerURL != "" && InstanceEnvConf.ServerConf.BillingPrivateKey != "" && InstanceEnvConf.ServerConf.BillingPublicServerURL != "" {
  21. serverURL := InstanceEnvConf.ServerConf.BillingPrivateServerURL
  22. publicServerURL := InstanceEnvConf.ServerConf.BillingPublicServerURL
  23. apiKey := InstanceEnvConf.ServerConf.BillingPrivateKey
  24. var err error
  25. InstanceBillingManager, err = eeBilling.NewClient(serverURL, publicServerURL, apiKey)
  26. if err != nil {
  27. panic(err)
  28. }
  29. } else {
  30. InstanceBillingManager = &billing.NoopBillingManager{}
  31. }
  32. if InstanceEnvConf.DBConf.VaultAPIKey != "" && InstanceEnvConf.DBConf.VaultServerURL != "" && InstanceEnvConf.DBConf.VaultPrefix != "" {
  33. InstanceCredentialBackend = vault.NewClient(
  34. InstanceEnvConf.DBConf.VaultServerURL,
  35. InstanceEnvConf.DBConf.VaultAPIKey,
  36. InstanceEnvConf.DBConf.VaultPrefix,
  37. )
  38. }
  39. }