class BBC::Cosmos::Tools::Config

Attributes

base_path[RW]
env[RW]
project[RW]

Public Class Methods

new(base_path, project, env = "int") click to toggle source
# File lib/bbc/cosmos/tools/config.rb, line 9
def initialize(base_path, project, env = "int")
  @base_path = base_path
  @project   = project
  @env       = env
end

Public Instance Methods

app() click to toggle source
# File lib/bbc/cosmos/tools/config.rb, line 47
def app
  config_path = base_path.join("configs", "app.yaml")
  fail("Invalid application config path: #{config_path}") unless File.exist? config_path
  YAML.load(File.open(config_path).read)["bbc"]["cosmos"]
end
cf_templates(component, stack = "main") click to toggle source
# File lib/bbc/cosmos/tools/config.rb, line 53
def cf_templates(component, stack = "main")
  aws_templates = File.join(base_path, "stacks", component, stack, "/aws/**/*.rb")
  component_template_path = File.join(base_path, "stacks", component, stack, "template.rb")
  component_template = (File.exist? component_template_path) ? File.read(component_template_path) : ""

  Dir
    .glob(aws_templates)
    .reduce(component_template) { |template_string, file| template_string += File.read(file) }
end
components() click to toggle source
# File lib/bbc/cosmos/tools/config.rb, line 28
def components
  path = File.join(base_path, "configs", "#{project}.yaml.erb")
  if File.exist? path
    template = File.open(path).read
    config = resources
    YAML.load(
      ERB.new(template).result(binding)
    )["components"]
  else
    fail("'#{project}' isn't valid project")
  end
end
components_for(tags) click to toggle source
# File lib/bbc/cosmos/tools/config.rb, line 41
def components_for(tags)
  resources["cloudformation"]["components"].select do |_component_id, data|
    data["tags"].any? { |tag| tags.nil? ? true : tags.include?(tag) } if data["tags"]
  end
end
resources() click to toggle source
# File lib/bbc/cosmos/tools/config.rb, line 15
def resources
  if File.directory? File.join(base_path, "resources", env)
    path = File.join(base_path, "resources", env, "#{project}.yaml")
    if File.exist? path
      YAML.load(File.open(path).read)
    else
      fail("Invalid project, please set the $BBC_COSMOS_TOOLS_PROJECT environment variable or use the --project parameter")
    end
  else
    fail("#{env} is an invalid environment")
  end
end