2
0

metadata.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package config
  2. import (
  3. "github.com/porter-dev/porter/api/server/shared/config/env"
  4. )
  5. type Metadata struct {
  6. Provisioning bool `json:"provisioner"`
  7. Github bool `json:"github"`
  8. BasicLogin bool `json:"basic_login"`
  9. GithubLogin bool `json:"github_login"`
  10. GoogleLogin bool `json:"google_login"`
  11. SlackNotifications bool `json:"slack_notifications"`
  12. Email bool `json:"email"`
  13. Analytics bool `json:"analytics"`
  14. Version string `json:"version"`
  15. Gitlab bool `json:"gitlab"`
  16. DefaultAppHelmRepoURL string `json:"default_app_helm_repo_url"`
  17. DefaultAddonHelmRepoURL string `json:"default_addon_helm_repo_url"`
  18. }
  19. func MetadataFromConf(sc *env.ServerConf, version string) *Metadata {
  20. return &Metadata{
  21. Provisioning: sc.ProvisionerServerURL != "" && sc.ProvisionerToken != "",
  22. Github: hasGithubAppVars(sc),
  23. GithubLogin: sc.GithubClientID != "" && sc.GithubClientSecret != "" && sc.GithubLoginEnabled,
  24. BasicLogin: sc.BasicLoginEnabled,
  25. GoogleLogin: sc.GoogleClientID != "" && sc.GoogleClientSecret != "",
  26. SlackNotifications: sc.SlackClientID != "" && sc.SlackClientSecret != "",
  27. Email: sc.SendgridAPIKey != "",
  28. Analytics: sc.SegmentClientKey != "",
  29. Version: version,
  30. Gitlab: sc.EnableGitlab,
  31. DefaultAppHelmRepoURL: sc.DefaultApplicationHelmRepoURL,
  32. DefaultAddonHelmRepoURL: sc.DefaultAddonHelmRepoURL,
  33. }
  34. }
  35. func hasGithubAppVars(sc *env.ServerConf) bool {
  36. return sc.GithubAppClientID != "" &&
  37. sc.GithubAppClientSecret != "" &&
  38. sc.GithubAppName != "" &&
  39. sc.GithubAppWebhookSecret != "" &&
  40. sc.GithubAppSecretPath != "" &&
  41. sc.GithubAppID != ""
  42. }