Class: Aptible::CLI::Agent
- Inherits:
-
Thor
- Object
- Thor
- Aptible::CLI::Agent
- Includes:
- Helpers::Ssh, Helpers::Token, Subcommands::Apps, Subcommands::Backup, Subcommands::Config, Subcommands::DB, Subcommands::Deploy, Subcommands::Domains, Subcommands::Inspect, Subcommands::Logs, Subcommands::Operation, Subcommands::Ps, Subcommands::Rebuild, Subcommands::Restart, Subcommands::SSH, Thor::Actions
- Defined in:
- lib/aptible/cli/agent.rb
Constant Summary
Constants included from Subcommands::Deploy
Subcommands::Deploy::DOCKER_IMAGE_DEPLOY_ARGS, Subcommands::Deploy::NULL_SHA1
Constants included from Helpers::Token
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
Forward return codes on failures.
Instance Method Summary collapse
-
#initialize ⇒ Agent
constructor
A new instance of Agent.
- #login ⇒ Object
- #version ⇒ Object
Methods included from Subcommands::Inspect
Methods included from Subcommands::Operation
Methods included from Subcommands::Backup
Methods included from Subcommands::SSH
Methods included from Subcommands::Restart
Methods included from Subcommands::Deploy
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::Ssh
#connect_to_ssh_portal, #exit_with_ssh_portal, #with_ssh_cmd
Methods included from Helpers::Token
#current_token_hash, #fetch_token, #save_token, #token_file
Constructor Details
Class Method Details
.exit_on_failure? ⇒ Boolean
Forward return codes on failures.
52 53 54 |
# File 'lib/aptible/cli/agent.rb', line 52 def self.exit_on_failure? true end |
Instance Method Details
#login ⇒ Object
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/aptible/cli/agent.rb', line 73 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? raise 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
63 64 65 |
# File 'lib/aptible/cli/agent.rb', line 63 def version puts version_string end |