From 6d59938e0d8d85f925016164f4b01e9d454ae38e Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 9 Nov 2020 09:54:26 +0100 Subject: [PATCH] Add dotenv --- .env.example | 8 ++++++++ .gitignore | 3 +++ Gemfile | 2 ++ Gemfile.lock | 4 ++++ app/controllers/ldap_users_controller.rb | 6 +++--- 5 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c09dba1 --- /dev/null +++ b/.env.example @@ -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 diff --git a/.gitignore b/.gitignore index df1cca4..e02bc74 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,6 @@ /yarn-error.log yarn-debug.log* .yarn-integrity + +# Ignore local dotenv config file +.env diff --git a/Gemfile b/Gemfile index 035f806..f4a6cfc 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 8a5f3e2..7d405d4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/controllers/ldap_users_controller.rb b/app/controllers/ldap_users_controller.rb index 1c0d7cc..b7f4f6d 100644 --- a/app/controllers/ldap_users_controller.rb +++ b/app/controllers/ldap_users_controller.rb @@ -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],