Class: Riemann::Dash::BrowserConfig::S3

Inherits:
Object
  • Object
show all
Defined in:
lib/riemann/dash/browser_config/s3.rb

Instance Method Summary collapse

Constructor Details

#initialize(bucket, path, config = {}) ⇒ S3

Returns a new instance of S3.



5
6
7
8
9
10
11
# File 'lib/riemann/dash/browser_config/s3.rb', line 5

def initialize(bucket, path, config = {})
  @bucket = bucket
  @path   = path
  @config = config

  @storage = Fog::Storage::AWS.new(config)
end

Instance Method Details

#readObject



13
14
15
16
17
18
19
# File 'lib/riemann/dash/browser_config/s3.rb', line 13

def read
  begin
    @storage.get_object(@bucket, @path).body
  rescue Excon::Errors::NotFound
    MultiJson.encode({})
  end
end

#update(update) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/riemann/dash/browser_config/s3.rb', line 21

def update(update)
  update = MultiJson.decode update

  # Read old config
  old = MultiJson.decode read

  new = Riemann::Dash::BrowserConfig.merge_configs update, old
  @storage.put_object @bucket, @path, MultiJson.encode(new, :pretty => true)
end