Class: Travis::CLI::Login

Inherits:
ApiCommand show all
Defined in:
lib/travis/cli/login.rb

Constant Summary

Constants inherited from Command

Command::DAY, Command::HOUR, Command::MINUTE, Command::WEEK

Constants included from Tools::Assets

Tools::Assets::BASE

Instance Attribute Summary collapse

Attributes inherited from ApiCommand

#enterprise_name, #session

Attributes inherited from Command

#arguments, #config, #debug, #force_interactive, #formatter, #input, #output

Instance Method Summary collapse

Methods inherited from ApiCommand

#authenticate, #detected_endpoint?, #endpoint_config, #enterprise?, #initialize, #org?, #pro?, #setup, #sync

Methods included from Travis::Client::Methods

#access_token, #access_token=, #account, #accounts, #api_endpoint, #api_endpoint=, #artifact, #broadcasts, #build, #cancel, #explicit_api_endpoint?, #github_auth, #hooks, #job, #lint, #listen, #logout, #regenerate_token, #remove_token, #repo, #repos, #restart, #user

Methods inherited from Command

abstract, abstract?, #check_completion, #check_ruby, #check_version, command_name, #command_name, #debug?, description, #error, #execute, #help, #info, #initialize, #last_check, #on_signal, #parse, #say, #setup, skip, subcommands, #terminal, #time, #usage, #usage_for, #warn, #write_to

Methods included from Tools::Assets

asset, asset_path

Methods included from Parser

#new, #on, #on_initialize

Constructor Details

This class inherits a constructor from Travis::CLI::ApiCommand

Instance Attribute Details

#user_loginObject

Returns the value of attribute user_login.



19
20
21
# File 'lib/travis/cli/login.rb', line 19

def 
  @user_login
end

Instance Method Details

#githubObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/travis/cli/login.rb', line 55

def github
  @github ||= begin
    load_gh
    Tools::Github.new(session.config['github']) do |g|
      g.note          = "temporary token to identify with the travis command line client against #{api_endpoint}"
      g.explode       = explode?
      g.github_token  = github_token
      g.auto_token    = auto_token
      g.check_token   = !skip_token_check?
      g.drop_token    = !list_github_token
      g.  = proc {  }
      g.debug         = proc { |log| debug(log) }
      g.after_tokens  = proc { g.explode = true and error('no suitable github token found') }
    end
  end
end

#list_tokenObject



21
22
23
24
25
26
# File 'lib/travis/cli/login.rb', line 21

def list_token
  github.after_tokens = proc {}
  github.each_token do |token|
    say token
  end
end

#loginObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/travis/cli/login.rb', line 28

def 
  session.access_token = nil
  github.with_token do |token|
    endpoint_config['access_token'] = github_auth(token)
    if  && (user. != )
      error(format('user mismatch: logged in as %p instead of %p', user.,
                   ))
    end
    unless user.correct_scopes?
      error(
        "#{user.} has not granted Travis CI the required permissions. " \
        "Please try re-syncing your user data at https://#{session.config['host']}/account/preferences " \
        "and try logging in via #{session.config['host']}"
      )
    end
    success("Successfully logged in as #{user.}!")
  end

  return if session.access_token

  raise Travis::Client::GitHubLoginFailed, 'all GitHub tokens given were invalid'
end

#login_headerObject



72
73
74
75
76
# File 'lib/travis/cli/login.rb', line 72

def 
  say 'GitHub deprecated its Authorizations API exchanging a password for a token.'
  say 'Please visit https://github.blog/2020-07-30-token-authentication-requirements-for-api-and-git-operations for more information.'
  say "Try running with #{color('--github-token', :info)} or #{color('--auto-token', :info)} ."
end

#runObject



51
52
53
# File 'lib/travis/cli/login.rb', line 51

def run
  list_github_token ? list_token : 
end