Class: Travis::CLI::Login
- Inherits:
-
ApiCommand
- Object
- Command
- ApiCommand
- Travis::CLI::Login
- 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
Instance Attribute Summary collapse
-
#user_login ⇒ Object
Returns the value of attribute user_login.
Attributes inherited from ApiCommand
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, #repo, #repos, #restart, #user
Methods inherited from Command
abstract, abstract?, #check_completion, #check_ruby, #check_version, command_name, #command_name, #debug?, description, #execute, #help, #info, #initialize, #last_check, #on_signal, #parse, #say, #setup, skip, subcommands, #terminal, #time, #usage, #usage_for, #write_to
Methods included from Tools::Assets
Methods included from Parser
Constructor Details
This class inherits a constructor from Travis::CLI::ApiCommand
Instance Attribute Details
#user_login ⇒ Object
Returns the value of attribute user_login.
20 21 22 |
# File 'lib/travis/cli/login.rb', line 20 def user_login @user_login end |
Instance Method Details
#github ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/travis/cli/login.rb', line 43 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.manual_login = no_manual.nil? g.explode = explode? g.github_token = github_token g.auto_token = auto_token g.auto_password = auto_password g.github_login = user_login g.check_token = !skip_token_check? g.drop_token = true g.ask_login = proc { ask("Username: ") } g.ask_password = proc { |user| ask("Password for #{user}: ") { |q| q.echo = "*" } } g.ask_otp = proc { |user| ask("Two-factor authentication code for #{user}: ") } g.login_header = proc { login_header } g.debug = proc { |log| debug(log) } g.after_tokens = proc { g.explode = true and error("no suitable github token found") } end end end |
#list_token ⇒ Object
22 23 24 25 26 27 |
# File 'lib/travis/cli/login.rb', line 22 def list_token github.after_tokens = proc { } github.each_token do |token| say token end end |
#login ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/travis/cli/login.rb', line 29 def login session.access_token = nil github.with_token do |token| endpoint_config['access_token'] = github_auth(token) error("user mismatch: logged in as %p instead of %p" % [user.login, user_login]) if user_login and user.login != user_login error("#{user.login} has not granted Travis CI the required permissions, please log in via #{session.config['host']}") unless user.correct_scopes? success("Successfully logged in as #{user.login}!") end end |
#login_header ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/travis/cli/login.rb', line 66 def login_header say "We need your #{color("GitHub login", :important)} to identify you." say "This information will #{color("not be sent to Travis CI", :important)}, only to #{color(github_endpoint.host, :info)}." say "The password will not be displayed." empty_line say "Try running with #{color("--github-token", :info)} or #{color("--auto", :info)} if you don't want to enter your password anyway." empty_line end |
#run ⇒ Object
39 40 41 |
# File 'lib/travis/cli/login.rb', line 39 def run list_github_token ? list_token : login end |