Class: Ey::Core::Cli::Login
- Inherits:
-
Subcommand
- Object
- Belafonte::App
- Subcommand
- Ey::Core::Cli::Login
- Defined in:
- lib/ey-core/cli/login.rb
Instance Method Summary collapse
Methods inherited from Subcommand
#handle_core_error, #run_handle, #setup
Methods included from Helpers::Core
#core_account, #core_accounts, #core_application_for, #core_client, #core_environment_for, #core_operator_and_environment_for, #core_server_for, #core_url, #core_yaml, #eyrc_yaml, included, #longest_length_by_name, #operator, #unauthenticated_core_client, #write_core_yaml
Instance Method Details
#handle ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ey-core/cli/login.rb', line 10 def handle email = ENV["EMAIL"] || ask("Email: ") password = ENV["PASSWORD"] || ask("Password: ") { |q| q.echo = false } token = unauthenticated_core_client. get_api_token(email, password). body["api_token"] existing_token = core_yaml[core_url] write_token= if existing_token && existing_token != token puts "New token does not match existing token. Overwriting".yellow true elsif existing_token == token puts "Token already exists".green false else puts "Writing token".green true end write_core_yaml(token) if write_token rescue Ey::Core::Response::Unauthorized abort "Invalid email or password".yellow end |