Sha256: 7c7ee6e6aa7a0b39101ca8e4981733d0bf228fe1cd92304ed8e77736492005cf

Contents?: true

Size: 1.77 KB

Versions: 17

Compression:

Stored size: 1.77 KB

Contents

require 'json'
require 'yaml'

module Seira
  class Settings
    DEFAULT_CONFIG_PATH = '.seira.yml'.freeze

    attr_reader :config_path

    def initialize(config_path: DEFAULT_CONFIG_PATH)
      @config_path = config_path
    end

    def settings
      return @_settings if defined?(@_settings)
      @_settings = parse_settings
    end

    def organization_id
      settings['seira']['organization_id']
    end

    def applications
      settings['seira']['applications'].map { |app| app['name'] }
    end

    def config_for_app(app_name)
      settings['seira']['applications'].find { |app| app['name'] == app_name }
    end

    def valid_cluster_names
      settings['seira']['clusters'].keys
    end

    def clusters
      settings['seira']['clusters']
    end

    def log_link_format
      settings['seira']['log_link_format']
    end

    def full_cluster_name_for_shorthand(shorthand)
      return shorthand if valid_cluster_names.include?(shorthand)

      # Try iterating through each cluster to find the relevant alias
      clusters.each do |cluster_name, cluster_metadata|
        next if cluster_metadata['aliases'].nil? || cluster_metadata['aliases'].empty?
        return cluster_name if cluster_metadata['aliases'].include?(shorthand)
      end

      nil
    end

    def project_for_cluster(cluster)
      settings['seira']['clusters'][cluster]['project']
    end

    def region_for_cluster(cluster)
      settings['seira']['clusters'][cluster]['region']
    end

    def zone_for_cluster(cluster)
      settings['seira']['clusters'][cluster]['zone']
    end

    def expected_environment_variable_during_deploys
      settings['seira']['expected_environment_variable_during_deploys']
    end

    private

    def parse_settings
      YAML.load_file(config_path)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
seira-0.7.5 lib/seira/settings.rb
seira-0.7.4 lib/seira/settings.rb
seira-0.7.3 lib/seira/settings.rb
seira-0.7.2 lib/seira/settings.rb
seira-0.7.1 lib/seira/settings.rb
seira-0.7.0 lib/seira/settings.rb
seira-0.6.6 lib/seira/settings.rb
seira-0.6.5 lib/seira/settings.rb
seira-0.6.4 lib/seira/settings.rb
seira-0.6.3 lib/seira/settings.rb
seira-0.6.2 lib/seira/settings.rb
seira-0.6.1 lib/seira/settings.rb
seira-0.6.0 lib/seira/settings.rb
seira-0.5.9 lib/seira/settings.rb
seira-0.5.7 lib/seira/settings.rb
seira-0.5.6 lib/seira/settings.rb
seira-0.5.5 lib/seira/settings.rb