Sha256: 4bf8780e2aed9e1e64285be365db5266fc9039d197ae4171828a9171b1d8016d

Contents?: true

Size: 1.35 KB

Versions: 89

Compression:

Stored size: 1.35 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 unless 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

89 entries across 89 versions & 2 rubygems

Version Path
travis-1.7.3.travis.650.5 lib/travis/client/auto_login.rb
travis-1.7.3.travis.649.5 lib/travis/client/auto_login.rb
travis-1.7.3.travis.647.5 lib/travis/client/auto_login.rb
travis-1.7.3.travis.646.5 lib/travis/client/auto_login.rb
travis-1.7.3.travis.644.5 lib/travis/client/auto_login.rb
travis-1.7.3.travis.641.5 lib/travis/client/auto_login.rb
travis-1.7.3.travis.640.5 lib/travis/client/auto_login.rb
travis-1.7.3.travis.637.5 lib/travis/client/auto_login.rb
travis-1.7.2 lib/travis/client/auto_login.rb
travis-1.7.2.travis.636.5 lib/travis/client/auto_login.rb
travis-1.7.2.travis.635.5 lib/travis/client/auto_login.rb
travis-1.7.2.travis.634.5 lib/travis/client/auto_login.rb
travis-1.7.2.travis.633.5 lib/travis/client/auto_login.rb
travis-1.7.2.travis.632.5 lib/travis/client/auto_login.rb
travis-1.7.2.travis.630.5 lib/travis/client/auto_login.rb
travis-1.7.2.travis.627.5 lib/travis/client/auto_login.rb
travis-1.7.2.travis.626.5 lib/travis/client/auto_login.rb
travis-1.7.2.travis.625.5 lib/travis/client/auto_login.rb
travis-1.7.2.travis.623.5 lib/travis/client/auto_login.rb
travis-1.7.2.travis.621.5 lib/travis/client/auto_login.rb