Module: Formatron::S3::Configuration

Defined in:
lib/formatron/s3/configuration.rb

Overview

manage the configuration stored on S3

Constant Summary collapse

FILE_NAME =
'configuration.json'

Class Method Summary collapse

Class Method Details

.deploy(aws:, kms_key:, bucket:, name:, target:, configuration:) ⇒ Object

rubocop:disable Metrics/ParameterLists



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/formatron/s3/configuration.rb', line 11

def self.deploy(aws:, kms_key:, bucket:, name:, target:, configuration:)
  key = self.key name: name, target: target
  Formatron::LOG.info do
    "Upload configuration to #{bucket}/#{key}"
  end
  aws.upload_file(
    kms_key: kms_key,
    bucket: bucket,
    key: key,
    content: "#{JSON.pretty_generate(configuration)}\n"
  )
end

.destroy(aws:, bucket:, name:, target:) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/formatron/s3/configuration.rb', line 38

def self.destroy(aws:, bucket:, name:, target:)
  key = self.key name: name, target: target
  Formatron::LOG.info do
    "Delete configuration from #{bucket}/#{key}"
  end
  aws.delete_file(
    bucket: bucket,
    key: key
  )
end

.get(aws:, bucket:, name:, target:) ⇒ Object

rubocop:enable Metrics/ParameterLists



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/formatron/s3/configuration.rb', line 25

def self.get(aws:, bucket:, name:, target:)
  key = self.key name: name, target: target
  Formatron::LOG.info do
    "Get configuration from #{bucket}/#{key}"
  end
  JSON.parse(
    aws.get_file(
      bucket: bucket,
      key: key
    )
  )
end

.key(name:, target:) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/formatron/s3/configuration.rb', line 49

def self.key(name:, target:)
  Path.key(
    name: name,
    target: target,
    sub_key: FILE_NAME
  )
end