Sha256: a9393f594bb33d04202473a233bf1b0938d0be1aaac25673f1d6f5350c7ca801

Contents?: true

Size: 805 Bytes

Versions: 3

Compression:

Stored size: 805 Bytes

Contents

require 'yaml'

module ZencoderCLI
  module Auth
    extend ZencoderCLI::Helpers
    class << self

      def require_authentication(env)
        Zencoder.api_key ||= retrieve_api_key(env)
      end

      def retrieve_api_key(env)
        env = "production" if !env || env.blank?
        if File.exist?("#{home_directory}/.zencoder/api-key")
          keys = YAML.load_file("#{home_directory}/.zencoder/api-key")
          if keys[env].present?
            keys[env]
          else
            error "No API found for the #{env} environment. Either set the environment variable ZENCODER_API_KEY or run `zencoder setup`."
          end
        else
          error "No API keys found. Either set the environment variable ZENCODER_API_KEY or run `zencoder setup`."
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zencoder-2.2.2 lib/zencoder/cli/auth.rb
zencoder-2.2.1 lib/zencoder/cli/auth.rb
zencoder-2.2.0 lib/zencoder/cli/auth.rb