class Codepipe::Setting

Public Class Methods

new(check_codepipeline_project=true) click to toggle source
# File lib/codepipe/setting.rb, line 7
def initialize(check_codepipeline_project=true)
  @check_codepipeline_project = check_codepipeline_project
end

Public Instance Methods

data() click to toggle source

data contains the settings.yml config. The order or precedence for settings is the project ufo/settings.yml and then the ~/.codepipeline/settings.yml.

# File lib/codepipe/setting.rb, line 13
def data
  Codepipe.check_codepipeline_project! if @check_codepipeline_project
  return {} unless File.exist?(project_settings_path)

  # project based settings files
  project = load_file(project_settings_path)

  user_file = "#{ENV['HOME']}/.codepipeline/settings.yml"
  user = File.exist?(user_file) ? YAML.load_file(user_file) : {}

  default_file = File.expand_path("default/settings.yml", __dir__)
  default = load_file(default_file)

  all_envs = default.deep_merge(user.deep_merge(project))
  all_envs = merge_base(all_envs)
  data = all_envs[pipe_env] || all_envs["base"] || {}
  data.deep_symbolize_keys
end
pipe_env() click to toggle source

Resolves infinite problem since Codepipe.env can be determined from PIPE_ENV or settings.yml files. When ufo is determined from settings it should not called Codepipe.env since that in turn calls Settings.new.data which can then cause an infinite loop.

# File lib/codepipe/setting.rb, line 36
def pipe_env
  path = "#{cb_root}/.codepipeline/settings.yml"
  if File.exist?(path)
    settings = YAML.load_file(path)
    env = settings.find do |_env, section|
      section ||= {}
      ENV['AWS_PROFILE'] && ENV['AWS_PROFILE'] == section['aws_profile']
    end
  end

  pipe_env = env.first if env
  pipe_env = ENV['PIPE_ENV'] if ENV['PIPE_ENV'] # highest precedence
  pipe_env || 'development'
end

Private Instance Methods

cb_root() click to toggle source
# File lib/codepipe/setting.rb, line 78
def cb_root
  ENV["CODEPIPELINE_ROOT"] || Dir.pwd
end
load_file(path) click to toggle source
# File lib/codepipe/setting.rb, line 52
def load_file(path)
  return Hash.new({}) unless File.exist?(path)

  content = RenderMePretty.result(path)
  data = YAML.load(content)
  # If key is is accidentally set to nil it screws up the merge_base later.
  # So ensure that all keys with nil value are set to {}
  data.each do |env, _setting|
    data[env] ||= {}
  end
  data
end
merge_base(all_envs) click to toggle source

automatically add base settings to the rest of the environments

# File lib/codepipe/setting.rb, line 66
def merge_base(all_envs)
  base = all_envs["base"] || {}
  all_envs.each do |env, settings|
    all_envs[env] = base.merge(settings) unless env == "base"
  end
  all_envs
end
project_settings_path() click to toggle source
# File lib/codepipe/setting.rb, line 74
def project_settings_path
  "#{cb_root}/.codepipeline/settings.yml"
end