Sha256: a55826948b06ad9389f445f39f27380e39a11a3f804d4d6c30372338d08784a1

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

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
          @component_config ||= @aws_config.config(
            parse_component_config,
            parse_component_config[:configuration][:config_path]
          )
        end

        private

        def 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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bbc-cosmos-config-0.1.2 lib/bbc/cosmos/config/cosmos.rb
bbc-cosmos-config-0.1.1 lib/bbc/cosmos/config/cosmos.rb
bbc-cosmos-config-0.1.0 lib/bbc/cosmos/config/cosmos.rb