module BBC module Cosmos module Config class AWS def initialize(ec2, s3) @ec2 = ec2 @s3 = s3 end def tags @tags ||= instance.tags end def region @region ||= ::AWS.config.region end def instance_id @instance_id ||= BBC::Cosmos.production? ? aws_instance_id : "instance_id" end private def s3_config_location tags['AppName'] end def s3_config(config) path = [ config[:configuration][:config_path], config[:environment], 'config', config[:configuration][:commit], "#{s3_config_location}.json" ].join('/') JSON.parse(@s3.buckets[config[:component_resources_bucket]].objects[path].read, :symbolize_names => true) end def instance BBC::Cosmos.production? ? aws_instance : dummy_instance end def dummy_instance Struct.new(:tags).new({ "aws:cloudformation:stack-name" => "stack_name", "Component" => "component_name", "AppName" => "app_name" }) end def aws_instance @ec2.regions[region].instances[instance_id] end def aws_instance_id `curl http://169.254.169.254/latest/meta-data/instance-id` end end end end end