meroku 0.1.36 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.example +2 -0
- data/.gitignore +10 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Guardfile +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +16 -0
- data/Rakefile +10 -0
- data/bin/meroku +6 -0
- data/exe/meroku +6 -2
- data/lib/meroku.rb +24 -15
- data/lib/meroku/infrastructure.rb +24 -0
- data/lib/meroku/version.rb +1 -1
- data/meroku.gemspec +40 -0
- metadata +111 -81
- data/lib/meroku/app.rb +0 -12
- data/lib/meroku/app/collaborator.rb +0 -18
- data/lib/meroku/application_record.rb +0 -8
- data/lib/meroku/apps_controller.rb +0 -112
- data/lib/meroku/cli.rb +0 -8
- data/lib/meroku/cli/certs.rb +0 -30
- data/lib/meroku/cli/certs.rb~ +0 -14
- data/lib/meroku/cli/cli.rb +0 -97
- data/lib/meroku/cli/config.rb +0 -111
- data/lib/meroku/cli/domains.rb +0 -69
- data/lib/meroku/cli/keys.rb +0 -38
- data/lib/meroku/cli/remote.rb +0 -13
- data/lib/meroku/cli/remote.rb~ +0 -12
- data/lib/meroku/cli/server.rb +0 -163
- data/lib/meroku/cli/server.rb~ +0 -4
- data/lib/meroku/config.rb +0 -6
- data/lib/meroku/configs_controller.rb +0 -62
- data/lib/meroku/core_ext.rb +0 -30
- data/lib/meroku/domain.rb +0 -6
- data/lib/meroku/domains_controller.rb +0 -83
- data/lib/meroku/error.rb +0 -6
- data/lib/meroku/key.rb +0 -11
- data/lib/meroku/keys_controller.rb +0 -82
- data/lib/meroku/sanitychecks.rb +0 -19
- data/lib/meroku/user.rb +0 -23
- data/lib/meroku/util.rb +0 -434
data/lib/meroku/app.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
class Meroku::App::Collaborator < Meroku::ApplicationRecord
|
2
|
-
include Meroku::Util
|
3
|
-
self.table_name = "meroku_app_collaborators"
|
4
|
-
|
5
|
-
validates :user_id, presence: true, allow_nil: false
|
6
|
-
validates :app_id, presence: true, allow_nil: false
|
7
|
-
validates_uniqueness_of :user_id, :scope => "app_id"
|
8
|
-
|
9
|
-
after_create :setup_repo
|
10
|
-
after_create :add_mysql_user
|
11
|
-
after_create :create_empty_mysql_db
|
12
|
-
after_create :add_mysql_grants
|
13
|
-
after_create :add_pg_user
|
14
|
-
after_create :create_empty_pg_db
|
15
|
-
after_create :add_pg_grants
|
16
|
-
end
|
17
|
-
|
18
|
-
|
@@ -1,112 +0,0 @@
|
|
1
|
-
module Meroku
|
2
|
-
|
3
|
-
class AppsController < ApplicationController
|
4
|
-
#before_action :set_app, only: [:show, :edit, :update, :destroy]
|
5
|
-
skip_before_action :verify_authenticity_token, only: [:create, :update, :additional_env_vars]
|
6
|
-
before_action :authenticate, only: [:create, :update, :additional_env_vars]
|
7
|
-
|
8
|
-
## GET /apps
|
9
|
-
## GET /apps.json
|
10
|
-
#def index
|
11
|
-
# @apps = App.all
|
12
|
-
#end
|
13
|
-
#
|
14
|
-
## GET /apps/1
|
15
|
-
## GET /apps/1.json
|
16
|
-
#def show
|
17
|
-
#end
|
18
|
-
#
|
19
|
-
## GET /apps/new
|
20
|
-
#def new
|
21
|
-
# @app = App.new
|
22
|
-
#end
|
23
|
-
#
|
24
|
-
## GET /apps/1/edit
|
25
|
-
#def edit
|
26
|
-
#end
|
27
|
-
#
|
28
|
-
# POST /apps
|
29
|
-
# POST /apps.json
|
30
|
-
def create
|
31
|
-
@app = Meroku::App.new(app_params)
|
32
|
-
app_saved = @app.save
|
33
|
-
collaborator_saved = nil
|
34
|
-
if app_saved
|
35
|
-
@collaborator = Meroku::App::Collaborator.new(
|
36
|
-
app_id: @app.id,
|
37
|
-
user_id: @user.id
|
38
|
-
)
|
39
|
-
collaborator_saved = @collaborator.save
|
40
|
-
Meroku::Util.nginx_rebuild()
|
41
|
-
end
|
42
|
-
|
43
|
-
respond_to do |format|
|
44
|
-
if app_saved && collaborator_saved
|
45
|
-
format.json { render json: @app }
|
46
|
-
else
|
47
|
-
format.json {
|
48
|
-
if @app.errors
|
49
|
-
render json: { :errors => @app.errors }, :status => :unprocessable_entity
|
50
|
-
elsif @collaborator.errors
|
51
|
-
render json: { :errors => @collaborator.errors }, :status => :unprocessable_entity
|
52
|
-
end
|
53
|
-
}
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
#
|
58
|
-
# PATCH/PUT /apps/1
|
59
|
-
# PATCH/PUT /apps/1.json
|
60
|
-
def update
|
61
|
-
respond_to do |format|
|
62
|
-
if @app_.update(app_params)
|
63
|
-
format.json {
|
64
|
-
Meroku::Util.nginx_rebuild()
|
65
|
-
render json: @app_
|
66
|
-
}
|
67
|
-
else
|
68
|
-
format.json { render json: @app_.errors, status: :unprocessable_entity }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
#
|
73
|
-
## DELETE /apps/1
|
74
|
-
## DELETE /apps/1.json
|
75
|
-
#def destroy
|
76
|
-
# @app.destroy
|
77
|
-
# respond_to do |format|
|
78
|
-
# format.html { redirect_to apps_url, notice: 'App was successfully destroyed.' }
|
79
|
-
# format.json { head :no_content }
|
80
|
-
# end
|
81
|
-
#end
|
82
|
-
|
83
|
-
|
84
|
-
# POST /?
|
85
|
-
def additional_env_vars
|
86
|
-
if params[:dbtype] == "mysql"
|
87
|
-
database_url = %Q[export DATABASE_URL=mysql2://u#{@user.id}:#{@user.database_password}@localhost/#{@app_.name}?socket=/opt/bitnami/mysql/tmp/mysql.sock]
|
88
|
-
else
|
89
|
-
database_url = %Q[export DATABASE_URL=postgres://u#{@user.id}:#{@user.database_password}@localhost/#{@app_.name}]
|
90
|
-
end
|
91
|
-
|
92
|
-
respond_to do |format|
|
93
|
-
Rails.logger.debug "DB8 #{"export RAILS_ENV=production export PORT=#{3000+@app_.id} #{database_url}"}"
|
94
|
-
format.json { render json: { :data => "export RAILS_ENV=production export PORT=#{3000+@app_.id} #{database_url} "} }
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
private
|
99
|
-
# Use callbacks to share common setup or constraints between actions.
|
100
|
-
#def set_app
|
101
|
-
# @app = App.find(params[:id])
|
102
|
-
#end
|
103
|
-
|
104
|
-
# Never trust parameters from the scary internet, only allow the white list through.
|
105
|
-
def app_params
|
106
|
-
params.fetch(:app, {}).permit(:name, :server_crt, :server_key)
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
data/lib/meroku/cli.rb
DELETED
data/lib/meroku/cli/certs.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
module Meroku
|
2
|
-
module CLI
|
3
|
-
require 'action_view'
|
4
|
-
include ActionView::Helpers::TextHelper
|
5
|
-
|
6
|
-
class Certs < Thor
|
7
|
-
include Meroku::Util
|
8
|
-
|
9
|
-
desc "add server.crt server.key", "Upload domain certificate and key"
|
10
|
-
def add(cert, key)
|
11
|
-
require 'rest-client'
|
12
|
-
require 'active_support/all'
|
13
|
-
require 'rack'
|
14
|
-
require 'action_view'
|
15
|
-
server_crt = IO.read(cert)
|
16
|
-
server_key = IO.read(key)
|
17
|
-
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 } }
|
18
|
-
puts "Added. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
|
19
|
-
rescue RestClient::Exception => e
|
20
|
-
abort e.to_s if e.response.code != 200
|
21
|
-
out_str = "ERROR"
|
22
|
-
if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
|
23
|
-
out_str += " "
|
24
|
-
out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
data/lib/meroku/cli/certs.rb~
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module Meroku
|
2
|
-
module CLI
|
3
|
-
require 'action_view'
|
4
|
-
include ActionView::Helpers::TextHelper
|
5
|
-
|
6
|
-
class Certs < Thor
|
7
|
-
include Meroku::Util
|
8
|
-
|
9
|
-
desc "add 'DOMAIN'", "Remove DOMAIN"
|
10
|
-
def remove(domain)
|
11
|
-
require 'rest-client'
|
12
|
-
require 'active_support/all'
|
13
|
-
require 'rack'
|
14
|
-
require 'action_view'
|
data/lib/meroku/cli/cli.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
module Meroku
|
2
|
-
module CLI
|
3
|
-
require 'action_view'
|
4
|
-
include ActionView::Helpers::TextHelper
|
5
|
-
|
6
|
-
class Cli < Thor
|
7
|
-
include Meroku::Util
|
8
|
-
register(Meroku::CLI::Server, 'server', 'server <command>', 'Administer infrastructure')
|
9
|
-
register(Remote, 'remote', 'remote <command>', '')
|
10
|
-
register(Keys, 'keys', 'keys <command>', '')
|
11
|
-
register(Domains,'domains','domains <command>', '')
|
12
|
-
register(Certs ,'certs','certs <command>', '')
|
13
|
-
register(Config ,'config','config <command>', '')
|
14
|
-
|
15
|
-
desc "_run 'COMMAND'", "Run a command on the server"
|
16
|
-
def _run(command)
|
17
|
-
user_id = `cat /tmp/meroku.id`.chomp
|
18
|
-
server = "u#{user_id}@www.meroku.com"
|
19
|
-
name = app_name
|
20
|
-
if IO.read("Gemfile") =~ /^[^\#]*gem ["']mysql/
|
21
|
-
dbtype="mysql"
|
22
|
-
else
|
23
|
-
dbtype="postgres"
|
24
|
-
end
|
25
|
-
|
26
|
-
_additional_env_vars = additional_env_vars(name,dbtype)
|
27
|
-
if command == "bash"
|
28
|
-
exec "ssh -t -o StrictHostKeyChecking=no #{server} '#{_additional_env_vars} ;echo INFO: Type exit quit this remote shell; cd #{name}; bash --login'"
|
29
|
-
end
|
30
|
-
abort "ERROR: Unexpected output for \"git remote -v\"" if name.blank?
|
31
|
-
require 'open3'
|
32
|
-
stdout, stderr, exit_status = Open3.capture3(%Q[ssh -o 'StrictHostKeyChecking=no' #{server} 'export PATH=$PATH:/opt/bitnami/nodejs/bin; source ~/.rvm/scripts/rvm; cd #{name}; #{_additional_env_vars} ; #{command}'])
|
33
|
-
puts stdout if !stdout.empty?
|
34
|
-
puts stderr if !stderr.empty?
|
35
|
-
puts "meroku run finished with exit code #{exit_status.exitstatus}" if exit_status.exitstatus != 0
|
36
|
-
end
|
37
|
-
|
38
|
-
desc "create NAME", "Create an app named NAME on meroku"
|
39
|
-
def create(name)
|
40
|
-
require 'rest-client'
|
41
|
-
require 'rack'
|
42
|
-
|
43
|
-
return if !cli_logged_in?
|
44
|
-
resp = RestClient.post 'https://www.meroku.com/meroku/apps.json', { :"app[name]" => name, authentication: { app: name, token: cli_token} }
|
45
|
-
puts "Created #{JSON.parse(resp)["name"]}! (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
|
46
|
-
`git remote remove meroku 2>&1 >/dev/null`
|
47
|
-
`git remote add meroku u#{cli_user_id}@www.meroku.com:#{name}.git 2>&1 >/dev/null`
|
48
|
-
puts "Added git remote meroku ( u#{cli_user_id}@www.meroku.com:#{name}.git )"
|
49
|
-
rescue RestClient::Exception => e
|
50
|
-
abort e.to_s if e == RestClient::ServerBrokeConnection
|
51
|
-
out_str = "ERROR"
|
52
|
-
if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
|
53
|
-
out_str += " "
|
54
|
-
out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
|
55
|
-
end
|
56
|
-
out_str += " (#{e.to_s}) "
|
57
|
-
puts out_str
|
58
|
-
end
|
59
|
-
|
60
|
-
option :email, :required => true
|
61
|
-
option :password, :required => true
|
62
|
-
desc "login", "Login to meroku"
|
63
|
-
def login()
|
64
|
-
require 'rest-client'
|
65
|
-
require 'rack'
|
66
|
-
resp = RestClient.post 'https://www.meroku.com/users/sign_in.json', {:"user[email]" => options[:email], :"user[password]" => options[:password] }
|
67
|
-
puts "Logged in! (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
|
68
|
-
IO.write("/tmp/meroku.token", JSON.parse(resp)["encrypted_password"])
|
69
|
-
IO.write("/tmp/meroku.id", JSON.parse(resp)["id"])
|
70
|
-
rescue RestClient::Exception => e
|
71
|
-
abort e.to_s if e.response.code == 500 || e.response.code == 404
|
72
|
-
out_str = "ERROR"
|
73
|
-
if JSON.parse(e.response)["errors"].is_a? Array
|
74
|
-
out_str += " "
|
75
|
-
out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
|
76
|
-
end
|
77
|
-
out_str += " (#{e.to_s}) "
|
78
|
-
puts out_str
|
79
|
-
end
|
80
|
-
|
81
|
-
option :email, :required => true
|
82
|
-
option :password, :required => true
|
83
|
-
desc "signup", "Sign up for a free meroku account"
|
84
|
-
def signup()
|
85
|
-
require 'rest-client'
|
86
|
-
require 'rack'
|
87
|
-
resp = RestClient.post 'https://www.meroku.com/users.json', {:"user[email]" => options[:email], :"user[password]" => options[:password], :"user[password_confirmation]" => options[:password] }
|
88
|
-
puts "Signed up #{JSON.parse(resp)["email"]}! (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
|
89
|
-
rescue RestClient::Exception => e
|
90
|
-
abort e.to_s if e.response.code == 500 || e.response.code == 404
|
91
|
-
puts "ERROR " +
|
92
|
-
JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence +
|
93
|
-
" (#{e.to_s})"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
data/lib/meroku/cli/config.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
module Meroku
|
2
|
-
module CLI
|
3
|
-
require 'action_view'
|
4
|
-
include ActionView::Helpers::TextHelper
|
5
|
-
|
6
|
-
class Config < Thor
|
7
|
-
include Meroku::Util
|
8
|
-
|
9
|
-
desc "list", "List environment variables"
|
10
|
-
def list
|
11
|
-
require 'rest-client'
|
12
|
-
#require 'active_support/all'
|
13
|
-
require 'rack'
|
14
|
-
require 'action_view'
|
15
|
-
resp = RestClient.get "https://www.meroku.com/meroku/configs.json?authentication_token=#{cli_token}&authentication_app_name=#{app_name}"
|
16
|
-
puts "#{JSON.parse(resp)["data"]}. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
|
17
|
-
rescue RestClient::Exception => e
|
18
|
-
out_str = "ERROR"
|
19
|
-
if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
|
20
|
-
out_str += " "
|
21
|
-
out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
|
22
|
-
end
|
23
|
-
out_str += " (#{e.to_s}) "
|
24
|
-
puts out_str
|
25
|
-
end
|
26
|
-
|
27
|
-
#desc "remove 'DOMAIN'", "Remove DOMAIN"
|
28
|
-
#def remove(domain)
|
29
|
-
# require 'rest-client'
|
30
|
-
# require 'active_support/all'
|
31
|
-
# require 'rack'
|
32
|
-
# require 'action_view'
|
33
|
-
# resp = RestClient.delete "https://www.meroku.com/meroku/domains/0.json?domain=#{domain}&authentication_token=#{cli_token}&authentication_app_name=#{app_name}"
|
34
|
-
# puts "Removed #{truncate(JSON.parse(resp)["data"]["domain"])}. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
|
35
|
-
#rescue RestClient::Exception => e
|
36
|
-
# abort e.to_s if e.response.code != 200
|
37
|
-
# out_str = "ERROR"
|
38
|
-
# if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
|
39
|
-
# out_str += " "
|
40
|
-
# out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
|
41
|
-
# end
|
42
|
-
# out_str += " (#{e.to_s}) "
|
43
|
-
# puts out_str
|
44
|
-
#end
|
45
|
-
#
|
46
|
-
#desc "list", "List domains associated with your app"
|
47
|
-
#def list
|
48
|
-
# require 'rest-client'
|
49
|
-
# require 'active_support/all'
|
50
|
-
# require 'rack'
|
51
|
-
# require 'action_view'
|
52
|
-
# resp = RestClient.get "https://www.meroku.com/meroku/domains.json?authentication_token=#{cli_token}&authentication_app_name=#{app_name}"
|
53
|
-
# puts "#{JSON.parse(resp)["data"]}. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
|
54
|
-
#rescue RestClient::Exception => e
|
55
|
-
# out_str = "ERROR"
|
56
|
-
# if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
|
57
|
-
# out_str += " "
|
58
|
-
# out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
|
59
|
-
# end
|
60
|
-
# out_str += " (#{e.to_s}) "
|
61
|
-
# puts out_str
|
62
|
-
#end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
desc "unset FOO", "Set environment variable FOO"
|
68
|
-
def unset(name)
|
69
|
-
require 'rest-client'
|
70
|
-
require 'rack'
|
71
|
-
require 'action_view'
|
72
|
-
resp = RestClient.delete "https://www.meroku.com/meroku/configs/0.json?name=#{name}&authentication_token=#{cli_token}&authentication_app_name=#{app_name}"
|
73
|
-
puts "Removed #{truncate(JSON.parse(resp)["data"]["name"])}. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
|
74
|
-
rescue RestClient::Exception => e
|
75
|
-
abort e.to_s if e == RestClient::ServerBrokeConnection
|
76
|
-
out_str = "ERROR"
|
77
|
-
puts e.to_s
|
78
|
-
if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
|
79
|
-
out_str += " "
|
80
|
-
out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
|
81
|
-
end
|
82
|
-
out_str += " (#{e.to_s}) "
|
83
|
-
puts out_str
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
desc "set FOO baa", "Set environment variable FOO to baa"
|
90
|
-
def set(name, value)
|
91
|
-
require 'rest-client'
|
92
|
-
#require 'active_support/all'
|
93
|
-
require 'rack'
|
94
|
-
require 'action_view'
|
95
|
-
|
96
|
-
resp = RestClient.post 'https://www.meroku.com/meroku/configs.json', { name: name, value: value, authentication: { token: cli_token, app_name: app_name } }
|
97
|
-
puts "Added/Updated #{truncate(JSON.parse(resp)["data"]["name"])}. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
|
98
|
-
rescue RestClient::Exception => e
|
99
|
-
abort e.to_s if e == RestClient::ServerBrokeConnection
|
100
|
-
out_str = "ERROR"
|
101
|
-
puts e.to_s
|
102
|
-
if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
|
103
|
-
out_str += " "
|
104
|
-
out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
|
105
|
-
end
|
106
|
-
out_str += " (#{e.to_s}) "
|
107
|
-
puts out_str
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
data/lib/meroku/cli/domains.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
module Meroku
|
2
|
-
module CLI
|
3
|
-
require 'action_view'
|
4
|
-
include ActionView::Helpers::TextHelper
|
5
|
-
|
6
|
-
class Domains < Thor
|
7
|
-
include Meroku::Util
|
8
|
-
|
9
|
-
desc "remove 'DOMAIN'", "Remove DOMAIN"
|
10
|
-
def remove(domain)
|
11
|
-
require 'rest-client'
|
12
|
-
require 'active_support/all'
|
13
|
-
require 'rack'
|
14
|
-
require 'action_view'
|
15
|
-
resp = RestClient.delete "https://www.meroku.com/meroku/domains/0.json?domain=#{domain}&authentication_token=#{cli_token}&authentication_app_name=#{app_name}"
|
16
|
-
puts "Removed #{truncate(JSON.parse(resp)["data"]["domain"])}. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
|
17
|
-
rescue RestClient::Exception => e
|
18
|
-
abort e.to_s if e.response.code != 200
|
19
|
-
out_str = "ERROR"
|
20
|
-
if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
|
21
|
-
out_str += " "
|
22
|
-
out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
|
23
|
-
end
|
24
|
-
out_str += " (#{e.to_s}) "
|
25
|
-
puts out_str
|
26
|
-
end
|
27
|
-
|
28
|
-
desc "list", "List domains associated with your app"
|
29
|
-
def list
|
30
|
-
require 'rest-client'
|
31
|
-
require 'active_support/all'
|
32
|
-
require 'rack'
|
33
|
-
require 'action_view'
|
34
|
-
resp = RestClient.get "https://www.meroku.com/meroku/domains.json?authentication_token=#{cli_token}&authentication_app_name=#{app_name}"
|
35
|
-
puts "#{JSON.parse(resp)["data"]}. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
|
36
|
-
rescue RestClient::Exception => e
|
37
|
-
out_str = "ERROR"
|
38
|
-
if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
|
39
|
-
out_str += " "
|
40
|
-
out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
|
41
|
-
end
|
42
|
-
out_str += " (#{e.to_s}) "
|
43
|
-
puts out_str
|
44
|
-
end
|
45
|
-
|
46
|
-
desc "add 'DOMAIN'", "Associate DOMAIN with your app"
|
47
|
-
def add(domain)
|
48
|
-
require 'rest-client'
|
49
|
-
require 'active_support/all'
|
50
|
-
require 'rack'
|
51
|
-
require 'action_view'
|
52
|
-
|
53
|
-
resp = RestClient.post 'https://www.meroku.com/meroku/domains.json', { domain: domain, authentication: { token: cli_token, app_name: app_name } }
|
54
|
-
puts "Added #{truncate(JSON.parse(resp)["data"]["domain"])}. (#{resp.code} #{Rack::Utils::HTTP_STATUS_CODES[resp.code]})"
|
55
|
-
rescue RestClient::ServerBrokeConnection
|
56
|
-
raise
|
57
|
-
rescue RestClient::Exception => e
|
58
|
-
abort e.to_s if e == RestClient::ServerBrokeConnection
|
59
|
-
out_str = "ERROR"
|
60
|
-
if valid_json?(e.response) && JSON.parse(e.response)["errors"].size >= 1
|
61
|
-
out_str += " "
|
62
|
-
out_str += JSON.parse(e.response)["errors"].map { |e| e.join(' ') }.to_sentence
|
63
|
-
end
|
64
|
-
out_str += " (#{e.to_s}) "
|
65
|
-
puts out_str
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|