Sha256: 10ac19cc3329933cd88e8c7fcbbc592dc942096b0a6330a3d590f08dae09c390

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

require 'ey-core/cli/subcommand'

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

        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
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ey-core-3.6.6 lib/ey-core/cli/login.rb
ey-core-3.4.5 lib/ey-core/cli/login.rb
ey-core-3.6.5 lib/ey-core/cli/login.rb