Skip to content

Commit 6a0ba33

Browse files
authored
Merge pull request #845 from ualbertalib/jefferya/818_config_gem
Add Config Gem as a replacement for deprecated secrets.yml
2 parents f1caf8d + f0358ce commit 6a0ba33

File tree

14 files changed

+148
-51
lines changed

14 files changed

+148
-51
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,11 @@ yarn-debug.log*
5050
.DS_Store
5151
# This is ignored due to Ansible I assume:
5252
config/initializers/comfortable_mexican_sofa.rb
53+
54+
# Config Gem: local dev overrides
55+
config/settings.local.yml
56+
config/settings/*.local.yml
57+
config/environments/*.local.yml
58+
59+
# Added to filesystem by: bundle exec rubocop
60+
.rubocop-https---raw-githubusercontent-com-ualbertalib-library-applications-development-inclusive-language-main-inclusive-language-rubocop-yml

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ gem "sprockets-rails"
2323
gem "turbo-rails"
2424
gem "stimulus-rails"
2525

26+
gem "config"
27+
2628
gem "rollbar"
2729

2830
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder

Gemfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,15 @@ GEM
122122
comfy_bootstrap_form (4.0.9)
123123
rails (>= 5.0.0)
124124
concurrent-ruby (1.3.5)
125+
config (5.6.1)
126+
deep_merge (~> 1.2, >= 1.2.1)
127+
ostruct
125128
connection_pool (2.5.3)
126129
crass (1.0.6)
127130
cssbundling-rails (1.4.3)
128131
railties (>= 6.0.0)
129132
date (3.4.1)
133+
deep_merge (1.2.2)
130134
drb (2.2.3)
131135
erb (5.0.2)
132136
erubi (1.13.1)
@@ -220,6 +224,7 @@ GEM
220224
racc (~> 1.4)
221225
nokogiri (1.18.9-x86_64-linux-musl)
222226
racc (~> 1.4)
227+
ostruct (0.6.3)
223228
parallel (1.27.0)
224229
parser (3.3.9.0)
225230
ast (~> 2.4.1)
@@ -408,6 +413,7 @@ DEPENDENCIES
408413
byebug
409414
capybara (>= 2.15)
410415
comfortable_mexican_sofa!
416+
config
411417
cssbundling-rails
412418
htmlentities
413419
image_processing (~> 1.14)

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ Pagination is handled by either Kaminari or WillPaginate. Make sure you have one
2626
1. `git clone [email protected]:ualbertalib/library-cms.git`
2727
2. `cd library-cms`
2828
3. `bin/setup`
29-
6. `bin/dev`
30-
7. visit [http://localhost:3000](http://localhost:3000) and you will see the library homepage.
31-
8. If you need to visit the admin section ([http://localhost:3000/admin](http://localhost:3000/admin)) - You'll be prompted to enter username and password (use the ones in your `config/secrets.yml`, which by default are 'admin' and 'mysecretpassword')
32-
29+
4. `bin/dev`
30+
5. visit [http://localhost:3000](http://localhost:3000) and you will see the library homepage.
31+
6. If you need to visit the admin section ([http://localhost:3000/admin](http://localhost:3000/admin)) - You'll be prompted to enter username and password (use the ones in your `config/settings/development.yml` (managed by the [Config Gem](https://www.rubydoc.info/gems/config/5.1.0)), which by default are 'admin' and 'mysecretpassword')
3332

3433
## Testing
34+
3535
To run the tests for the library-cms application, you can use the following command once your application has been setup from above:
3636

37-
```
37+
``` bash
3838
bundle exec rails test
3939
```
4040

config/initializers/comfortable_mexican_sofa.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181

8282
# Default credentials for ComfortableMexicanSofa::AccessControl::AdminAuthentication
8383
# YOU REALLY WANT TO CHANGE THIS BEFORE PUTTING YOUR SITE LIVE
84-
ComfortableMexicanSofa::AccessControl::AdminAuthentication.username = Rails.application.secrets.cms_user
85-
ComfortableMexicanSofa::AccessControl::AdminAuthentication.password = Rails.application.secrets.cms_password
84+
ComfortableMexicanSofa::AccessControl::AdminAuthentication.username = Settings.cms_user
85+
ComfortableMexicanSofa::AccessControl::AdminAuthentication.password = Settings.cms_password
8686

8787
# Uncomment this module and `config.admin_auth` above to use custom admin authentication
8888
# module ComfyAdminAuthentication

config/initializers/config.rb

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# frozen_string_literal: true
2+
3+
Config.setup do |config|
4+
# Name of the constant exposing loaded settings
5+
config.const_name = "Settings"
6+
7+
# Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'.
8+
#
9+
# config.knockout_prefix = nil
10+
11+
# Overwrite an existing value when merging a `nil` value.
12+
# When set to `false`, the existing value is retained after merge.
13+
#
14+
# config.merge_nil_values = true
15+
16+
# Overwrite arrays found in previously loaded settings file. When set to `false`, arrays will be merged.
17+
#
18+
# config.overwrite_arrays = true
19+
20+
# Defines current environment, affecting which settings file will be loaded.
21+
# Default: `Rails.env`
22+
#
23+
# config.environment = ENV.fetch('ENVIRONMENT', :development)
24+
25+
# Load environment variables from the `ENV` object and override any settings defined in files.
26+
#
27+
# config.use_env = false
28+
29+
# Define ENV variable prefix deciding which variables to load into config.
30+
#
31+
# Reading variables from ENV is case-sensitive. If you define lowercase value below, ensure your ENV variables are
32+
# prefixed in the same way.
33+
#
34+
# When not set it defaults to `config.const_name`.
35+
#
36+
config.env_prefix = "SETTINGS"
37+
38+
# What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well
39+
# with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where
40+
# using dots in variable names might not be allowed (eg. Bash).
41+
#
42+
# config.env_separator = '.'
43+
44+
# Ability to process variables names:
45+
# * nil - no change
46+
# * :downcase - convert to lower case
47+
#
48+
# config.env_converter = :downcase
49+
50+
# Parse numeric values as integers instead of strings.
51+
#
52+
# config.env_parse_values = true
53+
54+
# Validate presence and type of specific config values. Check https://github.com/dry-rb/dry-validation for details.
55+
#
56+
# config.schema do
57+
# required(:name).filled
58+
# required(:age).maybe(:int?)
59+
# required(:email).filled(format?: EMAIL_REGEX)
60+
# end
61+
62+
# Evaluate ERB in YAML config files at load time.
63+
#
64+
# config.evaluate_erb_in_yaml = true
65+
66+
# Name of directory and file to store config keys
67+
#
68+
# config.file_name = 'settings'
69+
# config.dir_name = 'settings'
70+
71+
# Load extra sources from a path. These can be file paths (strings),
72+
# hashes, or custom source objects that respond to 'load'
73+
#
74+
# config.extra_sources = [
75+
# 'path/to/extra_source.yml', # String: loads extra_source.yml
76+
# { api_key: ENV['API_KEY'] }, # Hash: direct hash source
77+
# MyCustomSource.new, # Custom source object
78+
# ]
79+
end

config/initializers/rollbar.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
if Rails.env.local?
99
config.enabled = false
1010
else
11-
config.access_token = Rails.application.secrets.rollbar_access_token
11+
config.access_token = Settings.rollbar_access_token
1212
end
1313

1414
# By default, Rollbar will try to call the `current_user` controller method
@@ -60,10 +60,10 @@
6060
# are optional.
6161
#
6262
config.proxy = {
63-
host: Rails.application.secrets.rollbar_proxy_host,
64-
port: Rails.application.secrets.rollbar_proxy_port,
65-
user: Rails.application.secrets.rollbar_proxy_user,
66-
password: Rails.application.secrets.rollbar_proxy_password
63+
host: Settings.rollbar_proxy_host,
64+
port: Settings.rollbar_proxy_port,
65+
user: Settings.rollbar_proxy_user,
66+
password: Settings.rollbar_proxy_password
6767
}
6868

6969
# If you run your staging application instance in production environment then

config/secrets.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

config/settings.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Shared settings across all environments: https://www.rubydoc.info/gems/config/5.1.0:
2+
# Overriden by: ./config/settings/#{environment}.yml

config/settings/development.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Development environment settings managed via Config Gem https://www.rubydoc.info/gems/config/5.1.0:
2+
3+
cms_user: 'admin'
4+
cms_password: 'mysecretpassword'

0 commit comments

Comments
 (0)