Class: Comply::CLI::Agent
- Inherits:
-
Thor
- Object
- Thor
- Comply::CLI::Agent
- Includes:
- Helpers::Program, Helpers::Token, Subcommands::Integrations, Thor::Actions
- Defined in:
- lib/comply/cli/agent.rb
Constant Summary
Constants included from Helpers::Program
Helpers::Program::PROGRAM_ENV_VAR
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::Integrations
Methods included from Helpers::Integration
#env_vars_by_prompt, #prettify_integration, #pretty_print_integration, #prompt_and_create_integration, #prompt_and_update_integration, #prompt_for_env
Methods included from Helpers::Program
#accessible_programs, #current_program_id_hash, #default_program, #fetch_program_id, #pretty_print_program, #program_id_file, #save_program_id, #set_default_program
Methods included from Helpers::Token
#current_token_hash, #current_user_email, #fetch_token, #save_token, #token_file
Constructor Details
#initialize ⇒ Agent
Returns a new instance of Agent.
24 25 26 27 |
# File 'lib/comply/cli/agent.rb', line 24 def initialize(*) Aptible::Resource.configure { |conf| conf.user_agent = version_string } super end |
Class Method Details
.exit_on_failure? ⇒ Boolean
Forward return codes on failures.
20 21 22 |
# File 'lib/comply/cli/agent.rb', line 20 def self.exit_on_failure? true end |
Instance Method Details
#login ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 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 |
# File 'lib/comply/cli/agent.rb', line 40 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)' # Select a default program set_default_program end |
#version ⇒ Object
30 31 32 |
# File 'lib/comply/cli/agent.rb', line 30 def version puts version_string end |