Sha256: 4eb7c0f8a81909b48c5614a571dd3542b40287225267d635c8a4a090c61f653b

Contents?: true

Size: 973 Bytes

Versions: 2

Compression:

Stored size: 973 Bytes

Contents

class Ey::Core::Cli::Login < Ey::Core::Cli::Subcommand
  title "login"
  summary "Retrieve API token from Engine Yard Cloud"

  def handle
    email    = ENV["EMAIL"]    || ask("Email:")
    password = ENV["PASSWORD"] || ask("Password:", 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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ey-core-3.1.1 lib/ey-core/cli/login.rb
ey-core-3.1.0 lib/ey-core/cli/login.rb