Enable provider based LDAP adapter

parent a6422e27
module Gitlab module Gitlab
module LDAP module LDAP
class Adapter class Adapter
attr_reader :ldap attr_reader :provider, :ldap
def self.open(&block) def self.open(provider, &block)
Net::LDAP.open(adapter_options) do |ldap| Net::LDAP.open(adapter_options(provider)) do |ldap|
block.call(self.new(ldap)) block.call(self.new(provider, ldap))
end end
end end
...@@ -13,7 +13,12 @@ module Gitlab ...@@ -13,7 +13,12 @@ module Gitlab
Gitlab.config.ldap Gitlab.config.ldap
end end
def self.adapter_options def self.config_for(provider)
config.servers.find { |server| server.provider_name == provider }
end
def self.adapter_options(provider)
config = config_for(provider)
encryption = encryption =
case config['method'].to_s case config['method'].to_s
when 'ssl' when 'ssl'
...@@ -45,7 +50,8 @@ module Gitlab ...@@ -45,7 +50,8 @@ module Gitlab
end end
def initialize(ldap=nil) def initialize(provider, ldap=nil)
@provider = provider
@ldap = ldap || Net::LDAP.new(self.class.adapter_options) @ldap = ldap || Net::LDAP.new(self.class.adapter_options)
end end
...@@ -133,7 +139,7 @@ module Gitlab ...@@ -133,7 +139,7 @@ module Gitlab
private private
def config def config
@config ||= self.class.config @config ||= self.class.config_for(provider)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment