require "json" module BBC module Cosmos module Config class Cosmos attr_reader :aws_config def initialize(aws_config) @aws_config = aws_config end def stack_name @aws_config.tags["aws:cloudformation:stack-name"] end def app_name @aws_config.tags["AppName"] end def component_name @aws_config.tags["Component"].downcase end def component_config load_config_from_s3? ? @aws_config.s3_config(parse_component_config) : parse_component_config[:configuration] end private def load_config_from_s3? parse_component_config[:configuration].include?(:config_path) && BBC::Cosmos.production? end def parse_component_config @parse_component_config ||= JSON.parse(app_config_string, :symbolize_names => true) end def app_config_string File.open(config_location).read end def config_location BBC::Cosmos.production? ? cosmos_config_location : ENV["DEV_APP_CONF"] end def cosmos_config_location "/etc/#{component_name}/component_configuration.json" end end end end end