Skip to content

Commit 650bc2a

Browse files
committed
add services object
1 parent 78ce2cf commit 650bc2a

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

lib/process_ldap.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require "byebug"
66
require "csv"
77

8+
require_relative "services"
89
require_relative "patron"
910
require_relative "patron_mapper"
1011
require_relative "current_schedule"
@@ -57,16 +58,17 @@ def self.roles_filter
5758
end
5859
end
5960

60-
DISTINGUISHED_NAME = ENV.fetch("LDAP_DN")
61-
PASSWORD = ENV.fetch("LDAP_PASSWORD")
62-
HOST = ENV.fetch("LDAP_HOST")
61+
# DISTINGUISHED_NAME = ENV.fetch("LDAP_DN")
62+
# PASSWORD = ENV.fetch("LDAP_PASSWORD")
63+
# HOST = ENV.fetch("LDAP_HOST")
6364

6465
def initialize(output: $stdout)
6566
@output = output
6667
end
6768

6869
def ldap
69-
@ldap ||= Net::LDAP.new(host: HOST, auth: {method: :simple, dn: DISTINGUISHED_NAME, password: PASSWORD}, port: 636, encryption: {method: :simple_tls})
70+
S.ldap
71+
# @ldap ||= Net::LDAP.new(host: HOST, auth: {method: :simple, dn: DISTINGUISHED_NAME, password: PASSWORD}, port: 636, encryption: {method: :simple_tls})
7072
end
7173

7274
def filter

lib/services.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require "net/ldap"
2+
module Services
3+
class << self
4+
def ldap
5+
@@ldap ||= init_ldap
6+
end
7+
8+
def app_env
9+
ENV["APP_ENV"] || "development"
10+
end
11+
12+
def ldap_host
13+
ENV["LDAP_HOST"]
14+
end
15+
16+
def ldap_dn
17+
ENV["LDAP_DN"]
18+
end
19+
20+
def ldap_username
21+
ENV["LDAP_USERNAME"]
22+
end
23+
24+
def ldap_password
25+
ENV["LDAP_PASSWORD"]
26+
end
27+
28+
private
29+
30+
def init_ldap
31+
if app_env == "production"
32+
Net::LDAP.new(host: ldap_host, auth: {method: :simple, dn: ldap_dn, password: ldap_password}, port: 636, encryption: {method: :simple_tls})
33+
else
34+
Net::LDAP.new(host: ldap_host, auth: {method: :simple, username: ldap_username, password: ldap_password}, port: 636, encryption: {method: :simple_tls})
35+
end
36+
end
37+
end
38+
end
39+
40+
S = Services

0 commit comments

Comments
 (0)