Permalink
Browse files

put s3 creds in item, use env specific config

  • Loading branch information...
birarda committed Sep 11, 2016
1 parent 0fcffaf commit 5a7fb99971789c6619c4c4c20c026536675426db
View
@@ -44,3 +44,7 @@ bower.json
.byebug_history
.DS_Store
+
+config/settings.local.yml
+config/settings/*.local.yml
+config/environments/*.local.yml
View
@@ -65,6 +65,9 @@ gem 'dalli'
# use inline SVG to inline discord logo
gem 'inline_svg'
+# use config for environment specific settings
+gem 'config'
+
# use paperclip for attachment handling (to upload to S3)
gem 'paperclip'
gem 'aws-sdk', '~> 2.3.0'
View
@@ -97,8 +97,12 @@ GEM
execjs
coffee-script-source (1.10.0)
concurrent-ruby (1.0.2)
+ config (1.2.1)
+ activesupport (>= 3.0)
+ deep_merge (~> 1.0, >= 1.0.1)
dalli (2.7.6)
debug_inspector (0.0.2)
+ deep_merge (1.1.1)
devise (4.2.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
@@ -323,6 +327,7 @@ DEPENDENCIES
capistrano-rails (~> 1.1)
capistrano-rbenv (~> 2.0)
capistrano3-puma
+ config
dalli
devise
dogapi (>= 1.3.0)
View
@@ -24,13 +24,19 @@ class Item < ApplicationRecord
has_attached_file :game_preview,
styles: { original: ["100%", :jpg] },
- path: "/images/:attachment/:id/:item_name:dotextension"
+ path: "/images/:attachment/:id/:item_name:dotextension",
+ s3_credentials: Proc.new { |a| a.instance.s3_credentials }
+
validates_attachment_content_type :game_preview, content_type: /\Aimage\/.*\z/
def self.default_scope
order(name: :asc)
end
+ def s3_credentials
+ { bucket: Settings.s3.bucket_name, access_key_id: ENV['GP_AWS_ACCESS_KEY_ID'], secret_access_key: ENV['GP_AWS_SECRET_KEY_ID'] }
+ end
+
private
Paperclip.interpolates :item_name do |attachment, style|
attachment.instance.name
View
@@ -11,5 +11,7 @@ class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
+
+ Config::Integrations::Rails::Railtie.preload
end
end
@@ -44,14 +44,9 @@
config.paperclip_defaults = {
storage: :s3,
url: ':s3_alias_url',
- s3_host_alias: 'static-dev.greatpass.io',
+ s3_host_alias: Settings.s3.host_alias,
s3_region: 'us-west-1',
s3_host_name: 's3-us-west-1.amazonaws.com',
- s3_credentials: {
- bucket: 'greatpass-dev',
- access_key_id: ENV['GP_AWS_ACCESS_KEY_ID'],
- secret_access_key: ENV['GP_AWS_SECRET_KEY_ID']
- }
}
# Print deprecation notices to the Rails logger.
@@ -1,4 +0,0 @@
-Aws.config.update({
- region: 'us-west-1',
- credentials: Aws::Credentials.new(ENV['GP_AWS_ACCESS_KEY_ID'], ENV['GP_AWS_SECRET_KEY_ID'])
-})
@@ -0,0 +1,32 @@
+Config.setup do |config|
+ # Name of the constant exposing loaded settings
+ config.const_name = 'Settings'
+
+ # Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'.
+ #
+ # config.knockout_prefix = nil
+
+ # Load environment variables from the `ENV` object and override any settings defined in files.
+ #
+ # config.use_env = false
+
+ # Define ENV variable prefix deciding which variables to load into config.
+ #
+ # config.env_prefix = 'Settings'
+
+ # What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well
+ # with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where
+ # using dots in variable names might not be allowed (eg. Bash).
+ #
+ # config.env_separator = '.'
+
+ # Ability to process variables names:
+ # * nil - no change
+ # * :downcase - convert to lower case
+ #
+ # config.env_converter = nil
+
+ # Parse numeric values as integers instead of strings.
+ #
+ # config.env_parse_values = false
+end
View
No changes.
@@ -0,0 +1,3 @@
+s3:
+ bucket_name: greatpass-dev
+ host_alias: static-dev.greatpass.io
@@ -0,0 +1,3 @@
+s3:
+ bucket_name: greatpass
+ host_alias: static.greatpass.io
View
No changes.

0 comments on commit 5a7fb99

Please sign in to comment.