PageRenderTime 23ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/gitlab/o_auth/provider.rb

https://gitlab.com/pauldibiase/gitlab-ce
Ruby | 38 lines | 33 code | 5 blank | 0 comment | 5 complexity | ac8648f385d7b863700f8b6392e2dec4 MD5 | raw file
  1. module Gitlab
  2. module OAuth
  3. class Provider
  4. LABELS = {
  5. "github" => "GitHub",
  6. "gitlab" => "GitLab.com",
  7. "google_oauth2" => "Google"
  8. }.freeze
  9. def self.providers
  10. Devise.omniauth_providers
  11. end
  12. def self.enabled?(name)
  13. providers.include?(name.to_sym)
  14. end
  15. def self.ldap_provider?(name)
  16. name.to_s.start_with?('ldap')
  17. end
  18. def self.config_for(name)
  19. name = name.to_s
  20. if ldap_provider?(name)
  21. Gitlab::LDAP::Config.new(name).options
  22. else
  23. Gitlab.config.omniauth.providers.find { |provider| provider.name == name }
  24. end
  25. end
  26. def self.label_for(name)
  27. name = name.to_s
  28. config = config_for(name)
  29. (config && config['label']) || LABELS[name] || name.titleize
  30. end
  31. end
  32. end
  33. end