Class: Codepipe::Setting

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/codepipe/setting.rb

Instance Method Summary collapse

Constructor Details

#initialize(check_codepipeline_project = true) ⇒ Setting

Returns a new instance of Setting.



7
8
9
# File 'lib/codepipe/setting.rb', line 7

def initialize(check_codepipeline_project=true)
  @check_codepipeline_project = check_codepipeline_project
end

Instance Method Details

#dataObject

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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_envObject

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.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/codepipe/setting.rb', line 36

def pipe_env
  settings = YAML.load_file("#{cb_root}/.codepipeline/settings.yml")
  env = settings.find do |_env, section|
    section ||= {}
    ENV['AWS_PROFILE'] && ENV['AWS_PROFILE'] == section['aws_profile']
  end

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