Module: Jets::Cfn::Resource::Codebuild::Project::FormatEnv

Included in:
Env
Defined in:
lib/jets/cfn/resource/codebuild/project/format_env.rb

Instance Method Summary collapse

Instance Method Details

#standardize_env_vars(vars, casing: :camelcase_keys) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jets/cfn/resource/codebuild/project/format_env.rb', line 3

def standardize_env_vars(vars, casing: :camelcase_keys)
  map = {
    PARAMETER_STORE: "PARAMETER_STORE",
    SECRET: "SECRETS_MANAGER",
    SECRETS_MANAGER: "SECRETS_MANAGER",
    SSM: "PARAMETER_STORE"
  }

  vars = vars.reject { |k, v| v.nil? }

  # There's no map! method. So using map and then assigning to vars
  vars = vars.map do |k, v|
    starts_with = v.to_s.split(":").first
    value = if map.key?(starts_with.upcase.to_sym)
      v.to_s.sub("#{starts_with}:", "")
    else
      v
    end
    type = map[starts_with.upcase.to_sym] || "PLAINTEXT"
    {
      Name: k.to_s,
      Value: value,
      Type: type
    }
  end
  vars = vars.sort_by { |h| h[:Name].to_s }
  if casing == :underscore_keys
    vars.map! { |h| h.transform_keys { |k| k.to_s.underscore.to_sym } }
  end
  vars
end