Skip to content

Commit 407c0c9

Browse files
authored
[#140196, #140197] extract secrets from settings.yml (#1453)
Release Notes Secret information such as API keys should exist in secrets.yml rather than in settings.yml or by being overridden in settings.local.yml. Deploy Note Will need to update settings.yml and secrets.yml to match the updated templates on staging and production servers in conjunction with the release.
1 parent 550c9dc commit 407c0c9

File tree

5 files changed

+38
-31
lines changed

5 files changed

+38
-31
lines changed

app/models/concerns/downloadable_file.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ module DownloadableFile
33
extend ActiveSupport::Concern
44

55
included do
6-
has_attached_file :file, Settings.paperclip.to_hash.merge(validate_media_type: false)
6+
has_attached_file :file, PaperclipSettings.config.merge(validate_media_type: false)
77

88
# TODO: Limit attachment types for safe uploads
99
do_not_validate_attachment_file_type :file
1010
end
1111

1212
def download_url
13-
if fog?
13+
if PaperclipSettings.fog?
1414
# This is a workaround due to a bug or limitation in fog to generate a
1515
# private, expiring URL and have it force a download.
1616
#
@@ -31,10 +31,4 @@ def download_url
3131
end
3232
end
3333

34-
private
35-
36-
def fog?
37-
Settings.paperclip.storage == "fog"
38-
end
39-
4034
end

config/initializers/paperclip.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@
1313
Paperclip.options[:content_type_mappings] = {
1414
xls: "CDF V2 Document, No summary info",
1515
}
16+
17+
class PaperclipSettings
18+
19+
def self.config
20+
secrets = Hash(Rails.application.secrets.paperclip).symbolize_keys
21+
Settings.paperclip.to_hash.merge(secrets)
22+
end
23+
24+
def self.fog?
25+
config[:storage] == "fog"
26+
end
27+
28+
end

config/secrets.yml.template

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
development:
22
secret_key_base: ~
33

4+
# You should change this if you want to be able to access the API
5+
api:
6+
basic_auth_name: <%= SecureRandom.hex %>
7+
basic_auth_password: <%= SecureRandom.hex %>
8+
9+
# You should change this if you want to be able to access the SecureRooms API
10+
secure_rooms_api:
11+
basic_auth_name: <%= SecureRandom.hex %>
12+
basic_auth_password: <%= SecureRandom.hex %>
13+
14+
# Uncomment these lines if you wish to use S3 in your application.
15+
# paperclip:
16+
# storage: fog
17+
# fog_credentials:
18+
# provider: AWS
19+
# aws_access_key_id: Your-Key-Here
20+
# aws_secret_access_key: Your-Key-Here
21+
# fog_directory: Your-Bucket-Name-Here
22+
# fog_public: false
23+
# path: ":class/:attachment/:id_partition/:style/:safe_filename"
24+
25+
426
test:
527
secret_key_base: needs_a_value_for_ci
628

config/settings.local.yml.template

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

config/settings.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,6 @@ relays:
8686
admin_enabled: true
8787
reservation_enabled: true
8888

89-
# You should change this if you want to be able to access the API
90-
api:
91-
basic_auth_name: <%= SecureRandom.hex %>
92-
basic_auth_password: <%= SecureRandom.hex %>
93-
94-
# You should change this if you want to be able to access the SecureRooms API
95-
secure_rooms_api:
96-
basic_auth_name: <%= SecureRandom.hex %>
97-
basic_auth_password: <%= SecureRandom.hex %>
98-
9989
#
10090
# For these settings use SettingsHelper#feature_on?
10191
feature:
@@ -135,7 +125,7 @@ split_accounts:
135125
- administrator
136126
# - account_manager
137127

138-
# This may be overridden in settings.local.yml if your fork is using S3, so
128+
# This may be overridden in secrets.yml if your fork is using S3, so
139129
# be sure to check there for configuration
140130
paperclip:
141131
storage: filesystem

0 commit comments

Comments
 (0)