Sha256: 0904ba13263ff21416819a7454cc7ab34b5c1fc9166ac6a0f02e94954a77a1cf

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

class Role
  ADMIN_ROLE = 'admin'.freeze

  class << self
    USERNAME_POSTFIX = '_REDSHIFT_USERNAME'.freeze
    PASSWORD_POSTFIX = '_REDSHIFT_PASSWORD'.freeze

    def name_to_username_key(name)
      "#{name.upcase}#{USERNAME_POSTFIX}"
    end

    def name_to_password_key(name)
      "#{name.upcase}#{PASSWORD_POSTFIX}"
    end

    def password_key_to_name(key)
      key.sub(PASSWORD_POSTFIX, '').downcase
    end

    def username_key_to_name(key)
      key.sub(USERNAME_POSTFIX, '').downcase
    end

    def configured_connections
      @configured_connections ||= determine_configured_connections
    end

    private

    def determine_configured_connections
      role_username_keys = ENV.keys.select { |env_key| env_key.include?(USERNAME_POSTFIX) }
      role_password_keys = ENV.keys.select { |env_key| env_key.include?(PASSWORD_POSTFIX) }
      username_configured_roles = role_username_keys.map { |key| username_key_to_name(key) }
      password_configured_roles = role_password_keys.map { |key| password_key_to_name(key) }
      password_configured_roles.select do |role|
        username_configured_roles.include?(role)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aleph_analytics-0.0.1.alpha lib/role.rb
aleph_analytics-0.0.0.alpha lib/role.rb