Add dotenv

This commit is contained in:
Basti 2020-11-09 09:54:26 +01:00
parent 259856a033
commit 6d59938e0d
Signed by untrusted user: basti
GPG Key ID: 9F88009D31D99C72
5 changed files with 20 additions and 3 deletions

8
.env.example Normal file
View File

@ -0,0 +1,8 @@
LDAP_HOST=192.168.33.10
LDAP_PORT=389
#
# Production LDAP server:
#
# LDAP_HOST=ldap.kosmos.org
# LDAP_PORT=636
# LDAP_USE_TLS=true

3
.gitignore vendored
View File

@ -36,3 +36,6 @@
/yarn-error.log
yarn-debug.log*
.yarn-integrity
# Ignore local dotenv config file
.env

View File

@ -25,6 +25,8 @@ gem 'jbuilder', '~> 2.7'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
gem 'dotenv-rails', groups: [:development, :test]
gem 'net-ldap'
group :development, :test do

View File

@ -75,6 +75,10 @@ GEM
crass (1.0.6)
database_cleaner (1.8.5)
diff-lcs (1.4.4)
dotenv (2.7.2)
dotenv-rails (2.7.2)
dotenv (= 2.7.2)
railties (>= 3.2, < 6.1)
erubi (1.9.0)
ffi (1.13.1)
globalid (0.4.2)

View File

@ -24,9 +24,9 @@ class LdapUsersController < ApplicationController
private
def ldap_client
ldap_client ||= Net::LDAP.new host: "ldap.kosmos.org",
port: 636,
encryption: :simple_tls,
ldap_client ||= Net::LDAP.new host: ENV['LDAP_HOST'],
port: ENV['LDAP_PORT'],
encryption: ENV['LDAP_USE_TLS'] ? :simple_tls : nil,
auth: {
method: :simple,
username: Rails.application.credentials.ldap[:username],