Class: EyProCli

Inherits:
Thor
  • Object
show all
Defined in:
lib/ey_pro_cli.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.core_fileObject

Returns the value of attribute core_file.



16
17
18
# File 'lib/ey_pro_cli.rb', line 16

def core_file
  @core_file
end

Instance Method Details

#accountsObject



25
26
27
28
29
30
31
# File 'lib/ey_pro_cli.rb', line 25

def accounts
  accounts = core_client.users.current.accounts
  width = (accounts)

  table_data = TablePrint::Printer.new(accounts, [{id: {width: 36}}, :name])
  puts table_data.table_print
end

#deployObject



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
115
# File 'lib/ey_pro_cli.rb', line 79

def deploy
  check_for_updates unless options["no-update-check"]
  operator, environment = core_operator_and_environment_for(options)
  unless operator.is_a?(Ey::Core::Client)
    abort <<-EOF
Found account #{operator.name} but requested account #{options[:]}.
Use the ID of the account instead of the name.
This can be retrieved by running "ey-pro accounts".
    EOF
    .red unless operator.name == options[:account] || operator.id == options[:account]
  end

  unless environment
    abort "Unable to locate environment #{options[:environment]} in #{operator.name}".red
  end
  app = core_application_for(options)

  deploy_options = {}
  deploy_options.merge!(ref: options[:ref]) if options[:ref]
  deploy_options.merge!(migrate_command: options[:migrate]) if options[:migrate]
  deploy_options.merge!(migrate_command: '') if options["no-migrate"]
  request = environment.deploy(app, deploy_options)

  puts "Deploy started to environment: #{environment.name} with application: #{app.name}"
  if options[:stream]
    request.subscribe { |m| print m["message"] if m.is_a?(Hash) }
    puts "" # fix console output from stream
  else
    request.ready!
  end

  if request.successful
    puts "Deploy successful!"
  else
    abort "Deploy failed!"
  end
end

#loginObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ey_pro_cli.rb', line 35

def 
  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

#logoutObject



59
60
61
62
63
64
65
66
67
# File 'lib/ey_pro_cli.rb', line 59

def logout
  if core_yaml[core_url]
    core_yaml.delete(core_url)
    write_core_yaml
    puts "Successfully removed API token from credentials file".green
  else
    puts "No API token found".yellow
  end
end