Sha256: ef02d26abc9a9ccfe0b3e4bfa55340dba15201f835da3fb2d56d6b8e3fa230bd

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 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
          load_config_from_s3? ? @aws_config.s3_config(config) : config[:configuration]
        end

        def config
          @config ||= JSON.parse(app_config_string, :symbolize_names => true)
        end

        def environment
          BBC::Cosmos.production? ? config[:environment] : ENV.fetch('APP_ENV', 'development')
        end

        def version
          BBC::Cosmos.production? ? config[:release] : "#{environment}-version"
        end

        private

        def load_config_from_s3?
          config[:configuration].include?(:config_path) && BBC::Cosmos.production?
        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

2 entries across 2 versions & 1 rubygems

Version Path
bbc-cosmos-config-0.3.3 lib/bbc/cosmos/config/cosmos.rb
bbc-cosmos-config-0.3.2 lib/bbc/cosmos/config/cosmos.rb