Class: Another::Ldap::Proxy::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/another/ldap/proxy/server.rb

Constant Summary collapse

SERVER_OPTIONS =
%i[port nodelay listen].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf:, logger: nil) ⇒ Server

Returns a new instance of Server.



14
15
16
17
# File 'lib/another/ldap/proxy/server.rb', line 14

def initialize(conf:, logger: nil)
  @conf = conf
  @logger = logger
end

Instance Attribute Details

#confObject (readonly)

Returns the value of attribute conf.



12
13
14
# File 'lib/another/ldap/proxy/server.rb', line 12

def conf
  @conf
end

Class Method Details

.run(conf:) ⇒ Object



68
69
70
# File 'lib/another/ldap/proxy/server.rb', line 68

def self.run(conf:)
  new(conf: conf).run
end

Instance Method Details

#loggerObject



59
60
61
62
63
64
65
66
# File 'lib/another/ldap/proxy/server.rb', line 59

def logger
  return @logger if @logger

  $stdout.sync = true
  @logger ||= Logger.new($stdout)
  @logger.level = conf.debug ? Logger::DEBUG : Logger::INFO
  @logger
end

#logger_paramsObject



46
47
48
# File 'lib/another/ldap/proxy/server.rb', line 46

def logger_params
  { logger: logger }
end

#operation_classObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/another/ldap/proxy/server.rb', line 25

def operation_class
  backend_mode = conf[:backend_mode]
  backends_conf = conf[:backends]
  root_username = conf[:root_username]
  root_password = conf[:root_password]
  logger = self.logger
  Another::Ldap::Proxy::Operation.new_operation do
    set_logger(logger)
    set_root_credentials(root_username,
                         root_password)
    set_backend_mode(backend_mode)
    backends_conf.each do |backend_conf|
      add_backend(Another::Ldap::Proxy::Backend.new_backend(backend_conf, logger: logger))
    end
  end
end

#operation_class_paramsObject



42
43
44
# File 'lib/another/ldap/proxy/server.rb', line 42

def operation_class_params
  { operation_class: operation_class }
end

#runObject



50
51
52
53
54
55
56
57
# File 'lib/another/ldap/proxy/server.rb', line 50

def run
  @s ||= LDAP::Server.new(
    **server_params
  )

  @s.run_tcpserver
  @s.join
end

#server_paramsObject



19
20
21
22
23
# File 'lib/another/ldap/proxy/server.rb', line 19

def server_params
  conf.slice(*SERVER_OPTIONS)
      .update(operation_class_params)
      .update(logger_params)
end