Class: Envoku::Adapters::S3
- Inherits:
-
Object
- Object
- Envoku::Adapters::S3
- Defined in:
- lib/envoku/adapters/s3.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #get(key) ⇒ Object
- #get_all ⇒ Object
-
#initialize(custom_options = {}) ⇒ S3
constructor
A new instance of S3.
- #load ⇒ Object
- #set(key, value) ⇒ Object
Constructor Details
#initialize(custom_options = {}) ⇒ S3
Returns a new instance of S3.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/envoku/adapters/s3.rb', line 15 def initialize( = {}) = { filename: nil, bucket_name: nil, access_key_id: nil, secret_access_key: nil, } @options = OpenStruct.new .merge() @local_file_name = "/tmp/envoku-#{SecureRandom.hex 16}.env" @data = {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/envoku/adapters/s3.rb', line 13 def @options end |
Instance Method Details
#get(key) ⇒ Object
56 57 58 |
# File 'lib/envoku/adapters/s3.rb', line 56 def get(key) @data[key] end |
#get_all ⇒ Object
52 53 54 |
# File 'lib/envoku/adapters/s3.rb', line 52 def get_all @data end |
#load ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/envoku/adapters/s3.rb', line 27 def load Envoku.logger.debug("Loading via S3 Adapter") return unless .bucket_name && .filename && .access_key_id && .secret_access_key Envoku.logger.debug("Downloading \"#{.bucket_name}/#{.filename}\" from S3") FileUtils.rm @local_file_name if File.exists? @local_file_name return unless clone_s3_file @_env_before = ENV.to_h Envoku.logger.debug("Applying ENV vars from S3") @data = Dotenv.load(@local_file_name) || {} @_env_after = ENV.to_h # TODO: Abstract the env diff to adapter base @_env_after.each do |key, value| if !@_env_before.has_key?(key) Envoku.logger.debug("- ADD #{key}") # @data[key] = value elsif @_env_before[key] != value Envoku.logger.debug("- MOD #{key}") # @data[key] = value end end FileUtils.rm @local_file_name ENV['ENVOKU_REFRESHED_AT'] = Time.now.to_s end |
#set(key, value) ⇒ Object
60 61 62 63 |
# File 'lib/envoku/adapters/s3.rb', line 60 def set(key, value) # TODO: Not yet implemented @data[key] = value end |