Class: Meroku::CLI::Certs

Inherits:
Thor
  • Object
show all
Includes:
Util
Defined in:
lib/meroku/cli/certs.rb

Instance Method Summary collapse

Instance Method Details

#add(cert, key) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/meroku/cli/certs.rb', line 10

def add(cert, key)
  require 'rest-client'
  require 'active_support/all'
  require 'rack'
  require 'action_view'
  server_crt = IO.read(cert)
  server_key = IO.read(key)
  resp = RestClient.put 'https://www.meroku.com/meroku/apps/0.json', { app: { server_crt: server_crt, server_key: server_key }, authentication: { token: cli_token, app_name: app_name } }
  puts "Added. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
rescue RestClient::Exception => e
  abort e.to_s if e.response.code != 200
  out_str = "ERROR"
  if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
    out_str += " "
    out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
  end
end