capabilities.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package shared
  2. type Capabilities struct {
  3. Provisioning bool `json:"provisioner"`
  4. Github bool `json:"github"`
  5. BasicLogin bool `json:"basic_login"`
  6. GithubLogin bool `json:"github_login"`
  7. GoogleLogin bool `json:"google_login"`
  8. SlackNotifications bool `json:"slack_notifications"`
  9. Email bool `json:"email"`
  10. Analytics bool `json:"analytics"`
  11. }
  12. func CapabilitiesFromConf(sc *ServerConf) *Capabilities {
  13. return &Capabilities{
  14. // TODO: case provisioning on env variables
  15. Provisioning: false,
  16. Github: hasGithubAppVars(sc),
  17. GithubLogin: sc.GithubClientID != "" && sc.GithubClientSecret != "" && sc.GithubLoginEnabled,
  18. BasicLogin: sc.BasicLoginEnabled,
  19. GoogleLogin: sc.GoogleClientID != "" && sc.GoogleClientSecret != "",
  20. SlackNotifications: sc.SlackClientID != "" && sc.SlackClientSecret != "",
  21. Email: sc.SendgridAPIKey != "",
  22. Analytics: sc.SegmentClientKey != "",
  23. }
  24. }
  25. func hasGithubAppVars(sc *ServerConf) bool {
  26. return sc.GithubAppClientID != "" &&
  27. sc.GithubAppClientSecret != "" &&
  28. sc.GithubAppName != "" &&
  29. sc.GithubAppWebhookSecret != "" &&
  30. sc.GithubAppSecretPath != "" &&
  31. sc.GithubAppID != ""
  32. }