Class: Aptible::CLI::Agent
- Inherits:
-
Thor
- Object
- Thor
- Aptible::CLI::Agent
- Includes:
- Helpers::Token, Subcommands::Apps, Subcommands::Backup, Subcommands::Config, Subcommands::DB, Subcommands::Domains, Subcommands::Logs, Subcommands::Ps, Subcommands::Rebuild, Subcommands::Restart, Subcommands::SSH, Thor::Actions
- Defined in:
- lib/aptible/cli/agent.rb
Constant Summary
Constants included from Helpers::Token
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
Forward return codes on failures.
Instance Method Summary collapse
Methods included from Subcommands::Backup
Methods included from Subcommands::SSH
Methods included from Subcommands::Restart
Methods included from Subcommands::Rebuild
Methods included from Subcommands::Ps
Methods included from Subcommands::Logs
Methods included from Subcommands::Domains
Methods included from Subcommands::DB
Methods included from Subcommands::Config
Methods included from Subcommands::Apps
Methods included from Helpers::Token
#current_token_hash, #fetch_token, #save_token, #token_file
Class Method Details
.exit_on_failure? ⇒ Boolean
Forward return codes on failures.
43 44 45 |
# File 'lib/aptible/cli/agent.rb', line 43 def self.exit_on_failure? true end |
Instance Method Details
#login ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/aptible/cli/agent.rb', line 58 def login email = [:email] || ask('Email: ') password = [:password] || ask('Password: ', echo: false) puts '' = { email: email, password: password } otp_token = [:otp_token] [:otp_token] = otp_token if otp_token begin lifetime = '1w' lifetime = '12h' if [:otp_token] lifetime = [:lifetime] if [:lifetime] duration = ChronicDuration.parse(lifetime) if duration.nil? fail Thor::Error, "Invalid token lifetime requested: #{lifetime}" end [:expires_in] = duration token = Aptible::Auth::Token.create() rescue OAuth2::Error => e if e.code == 'otp_token_required' [:otp_token] = [:otp_token] || ask('2FA Token: ') retry end raise Thor::Error, 'Could not authenticate with given credentials: ' \ "#{e.code}" end save_token(token.access_token) puts "Token written to #{token_file}" lifetime_format = { units: 2, joiner: ', ' } token_lifetime = (token.expires_at - token.created_at).round expires_in = ChronicDuration.output(token_lifetime, lifetime_format) puts "This token will expire after #{expires_in} " \ '(use --lifetime to customize)' end |
#version ⇒ Object
48 49 50 |
# File 'lib/aptible/cli/agent.rb', line 48 def version puts "aptible-cli v#{Aptible::CLI::VERSION}" end |