appli 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/appli/command.rb +30 -10
- data/lib/appli.rb +1 -4
- data/lib/commands/apps.rb +3 -5
- data/lib/commands/domains.rb +40 -0
- data/lib/commands/gems.rb +5 -5
- data/lib/commands/keys.rb +14 -0
- data/lib/commands/logs.rb +6 -0
- data/lib/commands/mysql.rb +1 -1
- data/lib/commands/ssh.rb +5 -0
- data/lib/commands/{system.rb → stats.rb} +0 -13
- metadata +7 -3
data/lib/appli/command.rb
CHANGED
@@ -47,16 +47,27 @@ module Appli
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def api_request(url, username, password, data = nil)
|
50
|
+
def api_request(url, username, password, data = nil, method = nil)
|
51
51
|
require 'uri'
|
52
52
|
require 'net/http'
|
53
53
|
require 'net/https'
|
54
54
|
uri = URI.parse(url)
|
55
|
-
|
56
|
-
|
55
|
+
|
56
|
+
if method.nil?
|
57
|
+
method = (data ? :post : :get)
|
58
|
+
end
|
59
|
+
|
60
|
+
req = case method
|
61
|
+
when :post
|
62
|
+
Net::HTTP::Post.new(uri.path)
|
63
|
+
when :delete
|
64
|
+
Net::HTTP::Delete.new(uri.path)
|
65
|
+
when :put
|
66
|
+
Net::HTTP::Put.new(uri.path)
|
57
67
|
else
|
58
|
-
|
68
|
+
Net::HTTP::Get.new(uri.path)
|
59
69
|
end
|
70
|
+
|
60
71
|
req.basic_auth(username, password)
|
61
72
|
req.add_field("Accept", "application/json")
|
62
73
|
req.add_field("Content-type", "application/json")
|
@@ -65,7 +76,7 @@ module Appli
|
|
65
76
|
res.use_ssl = true
|
66
77
|
res.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
67
78
|
end
|
68
|
-
puts "Requesting '#{url}' on as #{
|
79
|
+
puts "Requesting '#{url}' on as #{method.to_s.upcase}" if debug?
|
69
80
|
res = res.request(req, data)
|
70
81
|
case res
|
71
82
|
when Net::HTTPSuccess
|
@@ -93,12 +104,12 @@ module Appli
|
|
93
104
|
JSON.parse(api(path))
|
94
105
|
end
|
95
106
|
|
96
|
-
def api(path, data = nil)
|
97
|
-
api_request("http://#{domain}/#{path}", git_config_variable(:username), git_config_variable(:apikey), data)
|
107
|
+
def api(path, data = nil, method = nil)
|
108
|
+
api_request("http://#{domain}/#{path}", git_config_variable(:username), git_config_variable(:apikey), data, method)
|
98
109
|
end
|
99
110
|
|
100
|
-
def api_on_app(path, data = nil)
|
101
|
-
api("applications/#{@options[:application]}/#{path}", data)
|
111
|
+
def api_on_app(path, data = nil, method = nil)
|
112
|
+
api("applications/#{@options[:application]}/#{path}", data, method)
|
102
113
|
end
|
103
114
|
|
104
115
|
def domain
|
@@ -114,11 +125,20 @@ module Appli
|
|
114
125
|
puts "Executing: #{command}" if debug?
|
115
126
|
`#{command}`
|
116
127
|
end
|
128
|
+
|
129
|
+
def ssh_exec(command)
|
130
|
+
exec("ssh -p #{application['ssh_port']} app@#{host['name']} \"#{command}\"")
|
131
|
+
end
|
117
132
|
|
118
133
|
def error(command, exit_code = 1)
|
119
134
|
$stderr.puts command
|
120
135
|
Process.exit(exit_code)
|
121
136
|
end
|
122
|
-
|
137
|
+
|
138
|
+
def display_errors
|
139
|
+
for key, value in JSON.parse(errors)
|
140
|
+
puts " * #{key.capitalize} #{value}"
|
141
|
+
end
|
142
|
+
end
|
123
143
|
end
|
124
144
|
end
|
data/lib/appli.rb
CHANGED
@@ -14,7 +14,7 @@ module Appli
|
|
14
14
|
class NotConfiguredError < StandardError; end
|
15
15
|
class MustBeInRepositoryError < StandardError; end
|
16
16
|
|
17
|
-
VERSION = "0.0.
|
17
|
+
VERSION = "0.0.7"
|
18
18
|
|
19
19
|
def run(command, args = [])
|
20
20
|
load_commands
|
@@ -173,6 +173,3 @@ Appli.usage "cb version"
|
|
173
173
|
Appli.command "version", :global => true do
|
174
174
|
puts "Appli Gem Version #{Appli::VERSION}"
|
175
175
|
end
|
176
|
-
|
177
|
-
Appli.alias '-v', 'version'
|
178
|
-
Appli.alias '-s', 'ssh'
|
data/lib/commands/apps.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
desc 'Display a list of all applications which you have access to'
|
2
|
-
usage "appli
|
3
|
-
command "
|
2
|
+
usage "appli list"
|
3
|
+
command "list", :global => true do
|
4
4
|
apps = get("applications")
|
5
5
|
|
6
6
|
hash = [[:name, "Name", 30], [:identifier , "Identifier", 30], [:ssh_port, "SSH Port", 12], [:host, "Host", 30]]
|
@@ -34,9 +34,7 @@ command "create", :global => true, :required_args => 1 do |identifier|
|
|
34
34
|
result = api('applications', {:application => {:identifier => identifier, :name => identifier}}.to_json)
|
35
35
|
if errors
|
36
36
|
puts "\nAn error occured while creating your application:"
|
37
|
-
|
38
|
-
puts " * #{e.join(' ')}"
|
39
|
-
end
|
37
|
+
display_errors
|
40
38
|
puts
|
41
39
|
Process.exit(1)
|
42
40
|
else
|
@@ -0,0 +1,40 @@
|
|
1
|
+
desc 'List all domains configured for this application'
|
2
|
+
usage "appli [application] domains:list"
|
3
|
+
command "domains:list" do
|
4
|
+
domains = JSON.parse(api_on_app("domains"))
|
5
|
+
for domain in domains
|
6
|
+
extra = ''
|
7
|
+
extra = '(primary)' if domain['domain']['primary']
|
8
|
+
extra = '(redirect)' if domain['domain']['redirect']
|
9
|
+
puts " * #{domain['domain']['domain']} #{extra}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Add a new domain for this application"
|
14
|
+
usage "appli [application] domains:add {domain} {options}"
|
15
|
+
command "domains:add", :required_args => 1 do |name, options|
|
16
|
+
options = "" if options.nil?
|
17
|
+
if api_on_app("domains", {:domain => {:domain => name, :redirect => options.include?('redirect')}}.to_json)
|
18
|
+
puts "Domain '#{name}' added successfully."
|
19
|
+
else
|
20
|
+
puts "An error occured while adding your domain:"
|
21
|
+
display_errors
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Remove a domain from this application'
|
26
|
+
usage "appli [application] domains:remove {domain}"
|
27
|
+
command "domains:remove", :required_args => 1 do |name|
|
28
|
+
domains = JSON.parse(api_on_app('domains'))
|
29
|
+
domain = domains.select{|d| d['domain']['domain'] == name}.first
|
30
|
+
if domain
|
31
|
+
if api_on_app("domains/#{domain['domain']['id']}", nil, :delete)
|
32
|
+
puts "Domain ('#{name}') removed successfully"
|
33
|
+
else
|
34
|
+
error "Domain could not be removed at this time."
|
35
|
+
end
|
36
|
+
else
|
37
|
+
error "Domain ('#{name}') does not exist within this application"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
data/lib/commands/gems.rb
CHANGED
@@ -15,7 +15,7 @@ class FakeGemfile
|
|
15
15
|
end
|
16
16
|
|
17
17
|
desc "Read in the specified Gemfile and install all the required gems on your application"
|
18
|
-
usage "appli gems:import"
|
18
|
+
usage "appli [application] gems:import {path to file}"
|
19
19
|
command "gems:import" do |file|
|
20
20
|
file_to_import = File.expand_path(file || 'Gemfile')
|
21
21
|
unless File.exist?(file_to_import)
|
@@ -38,9 +38,9 @@ command "gems:import" do |file|
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
desc "Install the
|
42
|
-
usage "appli gems:install
|
43
|
-
command "gems:install" do |name, version|
|
41
|
+
desc "Install the provided gem on your application's container"
|
42
|
+
usage "appli [application] gems:install {gem name} {version]"
|
43
|
+
command "gems:install", :required_args => 1 do |name, version|
|
44
44
|
puts "Installing #{name} (#{version || 'latest'})"
|
45
45
|
data = {:ruby_gem => {:name => name, :version => version || ''}}.to_json
|
46
46
|
if a = api_on_app("ruby_gems", data)
|
@@ -51,7 +51,7 @@ command "gems:install" do |name, version|
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
desc "List all installed gems
|
54
|
+
desc "List all installed gems for your application"
|
55
55
|
usage "appli gems"
|
56
56
|
command "gems" do
|
57
57
|
ssh "gem list"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
desc "Upload your local public key to your appli user account"
|
2
|
+
usage "appli keys:add {key file}"
|
3
|
+
command "keys:add", :global => true do |file|
|
4
|
+
file = "#{ENV['HOME']}/.ssh/id_rsa.pub" if file.nil?
|
5
|
+
error("Key file not found at '#{file}'") unless File.file?(file)
|
6
|
+
key_data = File.read(file).chomp
|
7
|
+
data = {:key => {:key => key_data}}.to_json
|
8
|
+
if api("settings/keys", data)
|
9
|
+
puts "SSH key uploaded successfully from '#{file}'"
|
10
|
+
else
|
11
|
+
puts "Sorry, an error occured while adding your key. Please check the errors below:"
|
12
|
+
display_errors
|
13
|
+
end
|
14
|
+
end
|
data/lib/commands/mysql.rb
CHANGED
data/lib/commands/ssh.rb
ADDED
@@ -24,16 +24,3 @@ command "diskusage" do
|
|
24
24
|
puts "Your system is limited to #{size} however if you need additional"
|
25
25
|
puts "space, please just contact support."
|
26
26
|
end
|
27
|
-
|
28
|
-
desc "Display the current settings"
|
29
|
-
command "settings", :global => true do
|
30
|
-
puts "Username........: #{git_config_variable(:username) || 'unknown'}"
|
31
|
-
puts "API Key.........: #{git_config_variable(:apikey) || 'unknown'}"
|
32
|
-
puts "Domain..........: #{git_config_variable(:domain) || 'unknown'}"
|
33
|
-
end
|
34
|
-
|
35
|
-
desc 'SSH to the named server'
|
36
|
-
usage "appli [application] ssh"
|
37
|
-
command "ssh" do
|
38
|
-
exec "ssh -p #{application['ssh_port']} app@#{host['name']}"
|
39
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-19 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -36,9 +36,13 @@ files:
|
|
36
36
|
- lib/appli.rb
|
37
37
|
- lib/commands/apps.rb
|
38
38
|
- lib/commands/cap.rb
|
39
|
+
- lib/commands/domains.rb
|
39
40
|
- lib/commands/gems.rb
|
41
|
+
- lib/commands/keys.rb
|
42
|
+
- lib/commands/logs.rb
|
40
43
|
- lib/commands/mysql.rb
|
41
|
-
- lib/commands/
|
44
|
+
- lib/commands/ssh.rb
|
45
|
+
- lib/commands/stats.rb
|
42
46
|
has_rdoc: true
|
43
47
|
homepage: http://www.atechmedia.com
|
44
48
|
licenses: []
|