Sha256: 7bb634e785cc162e76c99b66aac514a46ca815cdf227b046735dd87ac4e99bf2

Contents?: true

Size: 1.34 KB

Versions: 127

Compression:

Stored size: 1.34 KB

Contents

require 'travis/client'
require 'travis/tools/github'
require 'yaml'

module Travis
  module Client
    class AutoLogin
      NoTokenError = Class.new(RuntimeError)
      attr_reader :session

      def initialize(session, options = {})
        @session     = session.session
        config_path  = ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', Dir.home) }
        @config_file = options.fetch(:config_file) { File.expand_path('config.yml', config_path) }
        @auto_token  = options.fetch(:auto_token) { true }
        @raise       = options.fetch(:raise) { true }
      end

      def authenticate
        return if session.access_token = cli_token
        github.with_token { |t| session.github_auth(t) }
      end

      def github
        @github         ||= Tools::Github.new(session.config['github']) do |g|
          g.explode       = true
          g.manual_login  = false
          g.auto_token    = @auto_token
          g.after_tokens  = proc { raise NoTokenError, "no suitable github token found" } if @raise
        end
      end

      def cli_token
        result   = cli_config
        result &&= result['endpoints']
        result &&= result[session.uri]
        result &&  result['access_token']
      end

      def cli_config
        @cli_config ||= YAML.load_file(@config_file) if File.exist? @config_file
      end
    end
  end
end

Version data entries

127 entries across 127 versions & 2 rubygems

Version Path
travis-1.10.1.travis.1341.9 lib/travis/client/auto_login.rb
travis-1.10.1.travis.1321.9 lib/travis/client/auto_login.rb
travis-1.10.1.travis.1312.9 lib/travis/client/auto_login.rb
travis-1.10.1.travis.1311.9 lib/travis/client/auto_login.rb
travis-1.10.1.travis.1305.9 lib/travis/client/auto_login.rb
travis-1.10.0 lib/travis/client/auto_login.rb
travis-1.9.2.travis.1304.9 lib/travis/client/auto_login.rb
travis-1.9.2.travis.1303.9 lib/travis/client/auto_login.rb
travis-1.10.0.pre.rc4 lib/travis/client/auto_login.rb
travis-1.10.0.pre.rc3 lib/travis/client/auto_login.rb
travis-1.10.0.pre.rc2 lib/travis/client/auto_login.rb
travis-1.9.2.travis.1288.9 lib/travis/client/auto_login.rb
travis-1.9.2.travis.1285.9 lib/travis/client/auto_login.rb
travis-1.9.2.travis.1279.9 lib/travis/client/auto_login.rb
travis-1.10.0.pre.rc1 lib/travis/client/auto_login.rb
travis-1.9.2.travis.1254.9 lib/travis/client/auto_login.rb
travis-1.9.2.travis.1236.9 lib/travis/client/auto_login.rb
travis-1.9.2.travis.1224.9 lib/travis/client/auto_login.rb
travis-1.9.1 lib/travis/client/auto_login.rb
travis-1.9.1.travis.1223.9 lib/travis/client/auto_login.rb