metadata.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package config
  2. import "github.com/porter-dev/porter/api/server/shared/config/env"
  3. type Metadata struct {
  4. Provisioning bool `json:"provisioner"`
  5. Github bool `json:"github"`
  6. BasicLogin bool `json:"basic_login"`
  7. GithubLogin bool `json:"github_login"`
  8. GoogleLogin bool `json:"google_login"`
  9. SlackNotifications bool `json:"slack_notifications"`
  10. Email bool `json:"email"`
  11. Analytics bool `json:"analytics"`
  12. Version string `json:"version"`
  13. }
  14. func MetadataFromConf(sc *env.ServerConf, version string) *Metadata {
  15. return &Metadata{
  16. // note: provisioning is set in the metadata after the loader is called
  17. Provisioning: false,
  18. Github: hasGithubAppVars(sc),
  19. GithubLogin: sc.GithubClientID != "" && sc.GithubClientSecret != "" && sc.GithubLoginEnabled,
  20. BasicLogin: sc.BasicLoginEnabled,
  21. GoogleLogin: sc.GoogleClientID != "" && sc.GoogleClientSecret != "",
  22. SlackNotifications: sc.SlackClientID != "" && sc.SlackClientSecret != "",
  23. Email: sc.SendgridAPIKey != "",
  24. Analytics: sc.SegmentClientKey != "",
  25. Version: version,
  26. }
  27. }
  28. func hasGithubAppVars(sc *env.ServerConf) bool {
  29. return sc.GithubAppClientID != "" &&
  30. sc.GithubAppClientSecret != "" &&
  31. sc.GithubAppName != "" &&
  32. sc.GithubAppWebhookSecret != "" &&
  33. sc.GithubAppSecretPath != "" &&
  34. sc.GithubAppID != ""
  35. }