class EnvConfiguration::AwsSsmParameterStoreWriter

Attributes

env_name[RW]

Public Class Methods

new(env_name, options = {}) click to toggle source
# File lib/env_configuration/aws_ssm_parameter_store_writer.rb, line 5
def initialize(env_name, options = {})
  @env_name = env_name
  @options  = options
end

Public Instance Methods

client() click to toggle source
# File lib/env_configuration/aws_ssm_parameter_store_writer.rb, line 10
def client
  @client ||= Aws::SSM::Client.new(@options)
end
put_config(name, value, type='String') click to toggle source
# File lib/env_configuration/aws_ssm_parameter_store_writer.rb, line 25
def put_config(name, value, type='String')
  Rails.logger.info { "preparing: #{name}=#{value}" }

  param_name = "/#{@env_name}/#{name}"

  options = {
    name: param_name, # required
    value: value, # required
    type: type, # required, accepts String, StringList, SecureString
    overwrite: true,
    tier: "Standard", # accepts Standard, Advanced
  }
  response = client.put_parameter(options)

  Rails.logger.info { "setting: #{options}" }
  response
end
put_configs(configs) click to toggle source
# File lib/env_configuration/aws_ssm_parameter_store_writer.rb, line 19
def put_configs(configs)
  configs.each do |key, value|
    put_config(key, value)
  end
end
put_configs_from_yaml_file(config_yml) click to toggle source
# File lib/env_configuration/aws_ssm_parameter_store_writer.rb, line 14
def put_configs_from_yaml_file(config_yml)
  configs = YAML.load_file(config_yml)[@env_name]
  put_configs(configs)
end