rhc-rest 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYRIGHT +1 -0
- data/Gemfile +4 -0
- data/LICENSE +11 -0
- data/Rakefile +1 -0
- data/bin/sample-usage.rb +124 -0
- data/doc/Gemfile.html +119 -0
- data/doc/Rakefile.html +117 -0
- data/doc/Rhc/Rest/Application.html +571 -0
- data/doc/Rhc/Rest/BaseException.html +226 -0
- data/doc/Rhc/Rest/Cartridge.html +475 -0
- data/doc/Rhc/Rest/Client.html +609 -0
- data/doc/Rhc/Rest/ClientErrorException.html +167 -0
- data/doc/Rhc/Rest/Domain.html +457 -0
- data/doc/Rhc/Rest/Key.html +378 -0
- data/doc/Rhc/Rest/RequestDeniedException.html +166 -0
- data/doc/Rhc/Rest/ResourceAccessException.html +161 -0
- data/doc/Rhc/Rest/ResourceNotFoundException.html +166 -0
- data/doc/Rhc/Rest/ServerErrorException.html +161 -0
- data/doc/Rhc/Rest/ServiceUnavailableException.html +167 -0
- data/doc/Rhc/Rest/UnAuthorizedException.html +167 -0
- data/doc/Rhc/Rest/User.html +354 -0
- data/doc/Rhc/Rest/ValidationException.html +255 -0
- data/doc/Rhc/Rest.html +410 -0
- data/doc/Rhc.html +329 -0
- data/doc/created.rid +13 -0
- data/doc/doc/created.rid +0 -0
- data/doc/images/add.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +112 -0
- data/doc/js/darkfish.js +153 -0
- data/doc/js/jquery.js +18 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +94 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/rdoc.css +543 -0
- data/doc/table_of_contents.html +198 -0
- data/lib/rhc-rest/application.rb +81 -0
- data/lib/rhc-rest/cartridge.rb +64 -0
- data/lib/rhc-rest/client.rb +122 -0
- data/lib/rhc-rest/domain.rb +56 -0
- data/lib/rhc-rest/exceptions/exceptions.rb +73 -0
- data/lib/rhc-rest/key.rb +34 -0
- data/lib/rhc-rest/user.rb +41 -0
- data/lib/rhc-rest/version.rb +5 -0
- data/lib/rhc-rest.rb +155 -0
- data/rhc-rest.gemspec +26 -0
- data/rhc-rest.spec +79 -0
- metadata +162 -0
@@ -0,0 +1,198 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
6
|
+
|
7
|
+
<title>Table of Contents - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
|
10
|
+
|
11
|
+
<script type="text/javascript">
|
12
|
+
var rdoc_rel_prefix = "./";
|
13
|
+
</script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
|
16
|
+
<script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
|
17
|
+
<script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
|
18
|
+
<script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
|
19
|
+
<script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
|
20
|
+
<script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
|
21
|
+
|
22
|
+
|
23
|
+
<body class="indexpage">
|
24
|
+
<h1>Table of Contents - RDoc Documentation</h1>
|
25
|
+
|
26
|
+
<h2>Pages</h2>
|
27
|
+
<ul>
|
28
|
+
<li class="file">
|
29
|
+
<a href="Gemfile.html">Gemfile</a>
|
30
|
+
</li>
|
31
|
+
<li class="file">
|
32
|
+
<a href="Rakefile.html">Rakefile</a>
|
33
|
+
</li>
|
34
|
+
|
35
|
+
</ul>
|
36
|
+
|
37
|
+
<h2 id="classes">Classes/Modules</h2>
|
38
|
+
<ul>
|
39
|
+
<li class="module">
|
40
|
+
<a href="Rhc.html">Rhc</a>
|
41
|
+
</li>
|
42
|
+
<li class="module">
|
43
|
+
<a href="Rhc/Rest.html">Rhc::Rest</a>
|
44
|
+
</li>
|
45
|
+
<li class="class">
|
46
|
+
<a href="Rhc/Rest/Application.html">Rhc::Rest::Application</a>
|
47
|
+
</li>
|
48
|
+
<li class="class">
|
49
|
+
<a href="Rhc/Rest/BaseException.html">Rhc::Rest::BaseException</a>
|
50
|
+
</li>
|
51
|
+
<li class="class">
|
52
|
+
<a href="Rhc/Rest/Cartridge.html">Rhc::Rest::Cartridge</a>
|
53
|
+
</li>
|
54
|
+
<li class="class">
|
55
|
+
<a href="Rhc/Rest/Client.html">Rhc::Rest::Client</a>
|
56
|
+
</li>
|
57
|
+
<li class="class">
|
58
|
+
<a href="Rhc/Rest/ClientErrorException.html">Rhc::Rest::ClientErrorException</a>
|
59
|
+
</li>
|
60
|
+
<li class="class">
|
61
|
+
<a href="Rhc/Rest/Domain.html">Rhc::Rest::Domain</a>
|
62
|
+
</li>
|
63
|
+
<li class="class">
|
64
|
+
<a href="Rhc/Rest/Key.html">Rhc::Rest::Key</a>
|
65
|
+
</li>
|
66
|
+
<li class="class">
|
67
|
+
<a href="Rhc/Rest/RequestDeniedException.html">Rhc::Rest::RequestDeniedException</a>
|
68
|
+
</li>
|
69
|
+
<li class="class">
|
70
|
+
<a href="Rhc/Rest/ResourceAccessException.html">Rhc::Rest::ResourceAccessException</a>
|
71
|
+
</li>
|
72
|
+
<li class="class">
|
73
|
+
<a href="Rhc/Rest/ResourceNotFoundException.html">Rhc::Rest::ResourceNotFoundException</a>
|
74
|
+
</li>
|
75
|
+
<li class="class">
|
76
|
+
<a href="Rhc/Rest/ServerErrorException.html">Rhc::Rest::ServerErrorException</a>
|
77
|
+
</li>
|
78
|
+
<li class="class">
|
79
|
+
<a href="Rhc/Rest/ServiceUnavailableException.html">Rhc::Rest::ServiceUnavailableException</a>
|
80
|
+
</li>
|
81
|
+
<li class="class">
|
82
|
+
<a href="Rhc/Rest/UnAuthorizedException.html">Rhc::Rest::UnAuthorizedException</a>
|
83
|
+
</li>
|
84
|
+
<li class="class">
|
85
|
+
<a href="Rhc/Rest/User.html">Rhc::Rest::User</a>
|
86
|
+
</li>
|
87
|
+
<li class="class">
|
88
|
+
<a href="Rhc/Rest/ValidationException.html">Rhc::Rest::ValidationException</a>
|
89
|
+
</li>
|
90
|
+
|
91
|
+
</ul>
|
92
|
+
|
93
|
+
<h2 id="methods">Methods</h2>
|
94
|
+
<ul>
|
95
|
+
|
96
|
+
<li class="method"><a href="Rhc/Rest/Key.html#method-c-new">::new — Rhc::Rest::Key</a>
|
97
|
+
|
98
|
+
<li class="method"><a href="Rhc/Rest/ValidationException.html#method-c-new">::new — Rhc::Rest::ValidationException</a>
|
99
|
+
|
100
|
+
<li class="method"><a href="Rhc/Rest/Application.html#method-c-new">::new — Rhc::Rest::Application</a>
|
101
|
+
|
102
|
+
<li class="method"><a href="Rhc/Rest/Cartridge.html#method-c-new">::new — Rhc::Rest::Cartridge</a>
|
103
|
+
|
104
|
+
<li class="method"><a href="Rhc/Rest/Domain.html#method-c-new">::new — Rhc::Rest::Domain</a>
|
105
|
+
|
106
|
+
<li class="method"><a href="Rhc/Rest/Client.html#method-c-new">::new — Rhc::Rest::Client</a>
|
107
|
+
|
108
|
+
<li class="method"><a href="Rhc/Rest/BaseException.html#method-c-new">::new — Rhc::Rest::BaseException</a>
|
109
|
+
|
110
|
+
<li class="method"><a href="Rhc/Rest/User.html#method-c-new">::new — Rhc::Rest::User</a>
|
111
|
+
|
112
|
+
<li class="method"><a href="Rhc/Rest/Domain.html#method-i-add_application">#add_application — Rhc::Rest::Domain</a>
|
113
|
+
|
114
|
+
<li class="method"><a href="Rhc/Rest/Application.html#method-i-add_cartridge">#add_cartridge — Rhc::Rest::Application</a>
|
115
|
+
|
116
|
+
<li class="method"><a href="Rhc/Rest/Client.html#method-i-add_domain">#add_domain — Rhc::Rest::Client</a>
|
117
|
+
|
118
|
+
<li class="method"><a href="Rhc/Rest/User.html#method-i-add_key">#add_key — Rhc::Rest::User</a>
|
119
|
+
|
120
|
+
<li class="method"><a href="Rhc/Rest/Domain.html#method-i-applications">#applications — Rhc::Rest::Domain</a>
|
121
|
+
|
122
|
+
<li class="method"><a href="Rhc/Rest/Client.html#method-i-cartridges">#cartridges — Rhc::Rest::Client</a>
|
123
|
+
|
124
|
+
<li class="method"><a href="Rhc/Rest/Application.html#method-i-cartridges">#cartridges — Rhc::Rest::Application</a>
|
125
|
+
|
126
|
+
<li class="method"><a href="Rhc/Rest/Client.html#method-i-close">#close — Rhc::Rest::Client</a>
|
127
|
+
|
128
|
+
<li class="method"><a href="Rhc/Rest/Key.html#method-i-delete">#delete — Rhc::Rest::Key</a>
|
129
|
+
|
130
|
+
<li class="method"><a href="Rhc/Rest/Domain.html#method-i-delete">#delete — Rhc::Rest::Domain</a>
|
131
|
+
|
132
|
+
<li class="method"><a href="Rhc/Rest/Application.html#method-i-delete">#delete — Rhc::Rest::Application</a>
|
133
|
+
|
134
|
+
<li class="method"><a href="Rhc/Rest/Cartridge.html#method-i-delete">#delete — Rhc::Rest::Cartridge</a>
|
135
|
+
|
136
|
+
<li class="method"><a href="Rhc/Rest/Cartridge.html#method-i-destroy">#destroy — Rhc::Rest::Cartridge</a>
|
137
|
+
|
138
|
+
<li class="method"><a href="Rhc/Rest/Application.html#method-i-destroy">#destroy — Rhc::Rest::Application</a>
|
139
|
+
|
140
|
+
<li class="method"><a href="Rhc/Rest/Domain.html#method-i-destroy">#destroy — Rhc::Rest::Domain</a>
|
141
|
+
|
142
|
+
<li class="method"><a href="Rhc/Rest/Key.html#method-i-destroy">#destroy — Rhc::Rest::Key</a>
|
143
|
+
|
144
|
+
<li class="method"><a href="Rhc/Rest/Client.html#method-i-domains">#domains — Rhc::Rest::Client</a>
|
145
|
+
|
146
|
+
<li class="method"><a href="Rhc/Rest/Client.html#method-i-find_application">#find_application — Rhc::Rest::Client</a>
|
147
|
+
|
148
|
+
<li class="method"><a href="Rhc/Rest/Client.html#method-i-find_cartridge">#find_cartridge — Rhc::Rest::Client</a>
|
149
|
+
|
150
|
+
<li class="method"><a href="Rhc/Rest/Client.html#method-i-find_domain">#find_domain — Rhc::Rest::Client</a>
|
151
|
+
|
152
|
+
<li class="method"><a href="Rhc/Rest/User.html#method-i-find_key">#find_key — Rhc::Rest::User</a>
|
153
|
+
|
154
|
+
<li class="method"><a href="Rhc/Rest/Client.html#method-i-find_key">#find_key — Rhc::Rest::Client</a>
|
155
|
+
|
156
|
+
<li class="method"><a href="Rhc/Rest/User.html#method-i-keys">#keys — Rhc::Rest::User</a>
|
157
|
+
|
158
|
+
<li class="method"><a href="Rhc/Rest.html#method-i-logger">#logger — Rhc::Rest</a>
|
159
|
+
|
160
|
+
<li class="method"><a href="Rhc/Rest/Client.html#method-i-logout">#logout — Rhc::Rest::Client</a>
|
161
|
+
|
162
|
+
<li class="method"><a href="Rhc/Rest.html#method-i-parse_response">#parse_response — Rhc::Rest</a>
|
163
|
+
|
164
|
+
<li class="method"><a href="Rhc/Rest.html#method-i-process_error_response">#process_error_response — Rhc::Rest</a>
|
165
|
+
|
166
|
+
<li class="method"><a href="Rhc/Rest/Cartridge.html#method-i-reload">#reload — Rhc::Rest::Cartridge</a>
|
167
|
+
|
168
|
+
<li class="method"><a href="Rhc/Rest/Cartridge.html#method-i-restart">#restart — Rhc::Rest::Cartridge</a>
|
169
|
+
|
170
|
+
<li class="method"><a href="Rhc/Rest/Application.html#method-i-restart">#restart — Rhc::Rest::Application</a>
|
171
|
+
|
172
|
+
<li class="method"><a href="Rhc/Rest/Domain.html#method-i-save">#save — Rhc::Rest::Domain</a>
|
173
|
+
|
174
|
+
<li class="method"><a href="Rhc/Rest.html#method-i-send">#send — Rhc::Rest</a>
|
175
|
+
|
176
|
+
<li class="method"><a href="Rhc/Rest/Application.html#method-i-start">#start — Rhc::Rest::Application</a>
|
177
|
+
|
178
|
+
<li class="method"><a href="Rhc/Rest/Cartridge.html#method-i-start">#start — Rhc::Rest::Cartridge</a>
|
179
|
+
|
180
|
+
<li class="method"><a href="Rhc/Rest/Cartridge.html#method-i-stop">#stop — Rhc::Rest::Cartridge</a>
|
181
|
+
|
182
|
+
<li class="method"><a href="Rhc/Rest/Application.html#method-i-stop">#stop — Rhc::Rest::Application</a>
|
183
|
+
|
184
|
+
<li class="method"><a href="Rhc/Rest/Domain.html#method-i-update">#update — Rhc::Rest::Domain</a>
|
185
|
+
|
186
|
+
<li class="method"><a href="Rhc/Rest/Key.html#method-i-update">#update — Rhc::Rest::Key</a>
|
187
|
+
|
188
|
+
<li class="method"><a href="Rhc/Rest/Client.html#method-i-user">#user — Rhc::Rest::Client</a>
|
189
|
+
|
190
|
+
</ul>
|
191
|
+
|
192
|
+
|
193
|
+
<footer id="validator-badges">
|
194
|
+
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
195
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
|
196
|
+
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
197
|
+
</footer>
|
198
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
module Rhc
|
3
|
+
module Rest
|
4
|
+
class Application
|
5
|
+
include Rest
|
6
|
+
attr_reader :domain_id, :name, :creation_time, :uuid, :aliases, :server_identity
|
7
|
+
def initialize(args)
|
8
|
+
@domain_id = args[:domain_id] || args["domain_id"]
|
9
|
+
@name = args[:name] || args["name"]
|
10
|
+
@creation_time = args[:creation_time] || args["creation_time"]
|
11
|
+
@uuid = args[:uuid] || args["uuid"]
|
12
|
+
@aliases = args[:aliases] || args["aliases"]
|
13
|
+
@server_identity = args[:server_identity] || args["server_identity"]
|
14
|
+
@links = args[:links] || args["links"]
|
15
|
+
end
|
16
|
+
|
17
|
+
#Add Cartridge
|
18
|
+
def add_cartridge(name)
|
19
|
+
logger.debug "Adding cartridge #{name}"
|
20
|
+
url = @@end_point + @links['ADD_CARTRIDGE']['href']
|
21
|
+
method = @links['ADD_CARTRIDGE']['method']
|
22
|
+
payload = {:name => name}
|
23
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
24
|
+
return send(request)
|
25
|
+
end
|
26
|
+
|
27
|
+
#Get all Cartridge for this applications
|
28
|
+
def cartridges
|
29
|
+
logger.debug "Getting all cartridges for application #{self.name}"
|
30
|
+
url = @@end_point + @links['LIST_CARTRIDGES']['href']
|
31
|
+
method = @links['LIST_CARTRIDGES']['method']
|
32
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers)
|
33
|
+
return send(request)
|
34
|
+
end
|
35
|
+
|
36
|
+
#Start Application
|
37
|
+
def start
|
38
|
+
logger.debug "Starting application #{self.name}"
|
39
|
+
url = @@end_point + @links['START']['href']
|
40
|
+
method = @links['START']['method']
|
41
|
+
payload = {:event=> "start"}
|
42
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
43
|
+
return send(request)
|
44
|
+
end
|
45
|
+
|
46
|
+
#Stop Application
|
47
|
+
def stop(force=false)
|
48
|
+
logger.debug "Stopping application #{self.name} force-#{force}"
|
49
|
+
url = @@end_point + @links['STOP']['href']
|
50
|
+
method = @links['STOP']['method']
|
51
|
+
if force
|
52
|
+
payload = {:event=> "force-stop"}
|
53
|
+
else
|
54
|
+
payload = {:event=> "stop"}
|
55
|
+
end
|
56
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
57
|
+
return send(request)
|
58
|
+
end
|
59
|
+
|
60
|
+
#Restart Application
|
61
|
+
def restart
|
62
|
+
logger.debug "Restarting application #{self.name}"
|
63
|
+
url = @@end_point + @links['RESTART']['href']
|
64
|
+
method = @links['RESTART']['method']
|
65
|
+
payload = {:event=> "restart"}
|
66
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
67
|
+
return send(request)
|
68
|
+
end
|
69
|
+
|
70
|
+
#Delete Application
|
71
|
+
def destroy
|
72
|
+
logger.debug "Deleting application #{self.name}"
|
73
|
+
url = @@end_point + @links['DELETE']['href']
|
74
|
+
method = @links['DELETE']['method']
|
75
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers)
|
76
|
+
return send(request)
|
77
|
+
end
|
78
|
+
alias :delete :destroy
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Rhc
|
2
|
+
module Rest
|
3
|
+
class Cartridge
|
4
|
+
include Rest
|
5
|
+
attr_reader :type, :name
|
6
|
+
def initialize(args)
|
7
|
+
@name = args[:name] || args["name"]
|
8
|
+
@type = args[:type] || args["type"]
|
9
|
+
@links = args[:links] || args["links"]
|
10
|
+
end
|
11
|
+
|
12
|
+
#Start Cartridge
|
13
|
+
def start
|
14
|
+
logger.debug "Starting cartridge #{self.name}"
|
15
|
+
url = @@end_point + @links['START']['href']
|
16
|
+
method = @links['START']['method']
|
17
|
+
payload = {:event=> "start"}
|
18
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
19
|
+
return send(request)
|
20
|
+
end
|
21
|
+
|
22
|
+
#Stop Cartridge
|
23
|
+
def stop()
|
24
|
+
logger.debug "Stopping cartridge #{self.name}"
|
25
|
+
url = @@end_point + @links['STOP']['href']
|
26
|
+
method = @links['STOP']['method']
|
27
|
+
payload = {:event=> "stop"}
|
28
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
29
|
+
return send(request)
|
30
|
+
end
|
31
|
+
|
32
|
+
#Restart Cartridge
|
33
|
+
def restart
|
34
|
+
logger.debug "Restarting cartridge #{self.name}"
|
35
|
+
url = @@end_point + @links['RESTART']['href']
|
36
|
+
method = @links['RESTART']['method']
|
37
|
+
payload = {:event=> "restart"}
|
38
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
39
|
+
return send(request)
|
40
|
+
end
|
41
|
+
|
42
|
+
#Reload Cartridge
|
43
|
+
def reload
|
44
|
+
logger.debug "Reloading cartridge #{self.name}"
|
45
|
+
url = @@end_point + @links['RESTART']['href']
|
46
|
+
method = @links['RESTART']['method']
|
47
|
+
payload = {:event=> "reload"}
|
48
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
49
|
+
return send(request)
|
50
|
+
end
|
51
|
+
|
52
|
+
#Delete Cartridge
|
53
|
+
def destroy
|
54
|
+
logger.debug "Deleting cartridge #{self.name}"
|
55
|
+
url = @@end_point + @links['DELETE']['href']
|
56
|
+
method = @links['DELETE']['method']
|
57
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers)
|
58
|
+
return send(request)
|
59
|
+
end
|
60
|
+
alias :delete :destroy
|
61
|
+
alias :delete :destroy
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module Rhc
|
4
|
+
module Rest
|
5
|
+
class Client
|
6
|
+
include Rest
|
7
|
+
def initialize(end_point, username, password)
|
8
|
+
@@end_point = end_point
|
9
|
+
credentials = Base64.encode64("#{username}:#{password}")
|
10
|
+
@@headers["Authorization"] = "Basic #{credentials}"
|
11
|
+
#first get the API
|
12
|
+
request = RestClient::Request.new(:url => @@end_point + "/api", :method => :get, :headers => @@headers)
|
13
|
+
begin
|
14
|
+
response = request.execute
|
15
|
+
result = JSON.parse(response)
|
16
|
+
@links = send(request)
|
17
|
+
rescue RestClient::ExceptionWithResponse => e
|
18
|
+
logger.error "Failed to get API #{e.response}"
|
19
|
+
rescue Exception => e
|
20
|
+
raise ResourceAccessException.new("Resource could not be accessed:#{e.message}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
#Add Domain
|
25
|
+
def add_domain(namespace)
|
26
|
+
logger.debug "Adding domain #{namespace}"
|
27
|
+
url = @@end_point + @links['ADD_DOMAIN']['href']
|
28
|
+
method = @links['ADD_DOMAIN']['method']
|
29
|
+
payload = {:namespace => namespace}
|
30
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
31
|
+
return send(request)
|
32
|
+
end
|
33
|
+
|
34
|
+
#Get all Domain
|
35
|
+
def domains
|
36
|
+
logger.debug "Getting all domains"
|
37
|
+
url = @@end_point + @links['LIST_DOMAINS']['href']
|
38
|
+
method = @links['LIST_DOMAINS']['method']
|
39
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers)
|
40
|
+
return send(request)
|
41
|
+
end
|
42
|
+
|
43
|
+
#Find Domain by namesapce
|
44
|
+
def find_domain(namespace)
|
45
|
+
logger.debug "Finding domain #{namespace}"
|
46
|
+
filtered = Array.new
|
47
|
+
domains.each do |domain|
|
48
|
+
#TODO do a regex caomparison
|
49
|
+
if domain.namespace == namespace
|
50
|
+
filtered.push(domain)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
return filtered
|
54
|
+
end
|
55
|
+
|
56
|
+
#Find Application by name
|
57
|
+
def find_application(name)
|
58
|
+
logger.debug "Finding application #{name}"
|
59
|
+
filtered = Array.new
|
60
|
+
domains.each do |domain|
|
61
|
+
#TODO do a regex caomparison
|
62
|
+
domain.applications.each do |app|
|
63
|
+
if app.name == name
|
64
|
+
filtered.push(app)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
return filtered
|
69
|
+
end
|
70
|
+
|
71
|
+
#Get all Cartridge
|
72
|
+
def cartridges
|
73
|
+
logger.debug "Getting all cartridges"
|
74
|
+
url = @@end_point + @links['LIST_CARTRIDGES']['href']
|
75
|
+
method = @links['LIST_CARTRIDGES']['method']
|
76
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers)
|
77
|
+
return send(request)
|
78
|
+
end
|
79
|
+
|
80
|
+
#Find Cartridge by name
|
81
|
+
def find_cartridge(name)
|
82
|
+
logger.debug "Finding cartridge #{name}"
|
83
|
+
filtered = Array.new
|
84
|
+
cartridges.each do |cart|
|
85
|
+
#TODO do a regex caomparison
|
86
|
+
if cart.name == name
|
87
|
+
filtered.push(cart)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
return filtered
|
91
|
+
end
|
92
|
+
|
93
|
+
#Get User info
|
94
|
+
def user
|
95
|
+
url = @@end_point + @links['GET_USER']['href']
|
96
|
+
method = @links['GET_USER']['method']
|
97
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers)
|
98
|
+
return send(request)
|
99
|
+
end
|
100
|
+
|
101
|
+
#find Key by name
|
102
|
+
def find_key(name)
|
103
|
+
logger.debug "Finding key #{name}"
|
104
|
+
filtered = Array.new
|
105
|
+
user.keys.each do |key|
|
106
|
+
#TODO do a regex caomparison
|
107
|
+
if key.name == name
|
108
|
+
filtered.push(key)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
return filtered
|
112
|
+
end
|
113
|
+
|
114
|
+
def logout
|
115
|
+
#TODO logout
|
116
|
+
logger.debug "Logout/Close client"
|
117
|
+
end
|
118
|
+
alias :close :logout
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Rhc
|
2
|
+
module Rest
|
3
|
+
class Domain
|
4
|
+
include Rest
|
5
|
+
attr_reader :namespace
|
6
|
+
def initialize(args)
|
7
|
+
@namespace = args[:namespace] || args["namespace"]
|
8
|
+
@links = args[:links] || args["links"]
|
9
|
+
end
|
10
|
+
|
11
|
+
#Add Application to this domain
|
12
|
+
def add_application(name, cartridge, scale=false)
|
13
|
+
logger.debug "Adding application #{name} to domain #{self.namespace}"
|
14
|
+
url = @@end_point + @links['ADD_APPLICATION']['href']
|
15
|
+
method = @links['ADD_APPLICATION']['method']
|
16
|
+
payload = {:name => name, :cartridge => cartridge}
|
17
|
+
if scale
|
18
|
+
payload[:scale] = true
|
19
|
+
end
|
20
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
21
|
+
return send(request)
|
22
|
+
end
|
23
|
+
|
24
|
+
#Get all Application for this domain
|
25
|
+
def applications
|
26
|
+
logger.debug "Getting all applications for domain #{self.namespace}"
|
27
|
+
url = @@end_point + @links['LIST_APPLICATIONS']['href']
|
28
|
+
method = @links['LIST_APPLICATIONS']['method']
|
29
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers)
|
30
|
+
return send(request)
|
31
|
+
end
|
32
|
+
|
33
|
+
#Update Domain
|
34
|
+
def update(new_namespace)
|
35
|
+
logger.debug "Updating domain #{self.namespace} to #{new_namespace}"
|
36
|
+
url = @@end_point + @links['UPDATE']['href']
|
37
|
+
method = @links['UPDATE']['method']
|
38
|
+
payload = {:namespace => new_namespace}
|
39
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
40
|
+
return send(request)
|
41
|
+
end
|
42
|
+
alias :save :update
|
43
|
+
|
44
|
+
#Delete Domain
|
45
|
+
def destroy(force=false)
|
46
|
+
logger.debug "Deleting domain #{self.namespace}"
|
47
|
+
url = @@end_point + @links['DELETE']['href']
|
48
|
+
method = @links['DELETE']['method']
|
49
|
+
payload = {:force => force}
|
50
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
51
|
+
return send(request)
|
52
|
+
end
|
53
|
+
alias :delete :destroy
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Rhc
|
2
|
+
module Rest
|
3
|
+
class BaseException < RuntimeError
|
4
|
+
attr_reader :code
|
5
|
+
def initialize(message=nil, code=nil)
|
6
|
+
super(message)
|
7
|
+
@code = code
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
#Exceptions thrown in case of an HTTP 5xx is received.
|
12
|
+
class ServerErrorException < Rhc::Rest::BaseException; end
|
13
|
+
|
14
|
+
#Exceptions thrown in case of an HTTP 503 is received.
|
15
|
+
#
|
16
|
+
#503 Service Unavailable
|
17
|
+
#
|
18
|
+
#The server is currently unable to handle the request due to a temporary
|
19
|
+
#overloading or maintenance of the server. The implication is that this
|
20
|
+
#is a temporary condition which will be alleviated after some delay.
|
21
|
+
|
22
|
+
class ServiceUnavailableException < Rhc::Rest::ServerErrorException; end
|
23
|
+
|
24
|
+
#Exceptions thrown in case of an HTTP 4xx is received with the exception
|
25
|
+
#of 401, 403, 403 and 422 where a more sepcific exception is thrown
|
26
|
+
#
|
27
|
+
#HTTP Error Codes 4xx
|
28
|
+
#
|
29
|
+
#The 4xx class of status code is intended for cases in which the client
|
30
|
+
#seems to have errored.
|
31
|
+
|
32
|
+
|
33
|
+
class ClientErrorException < Rhc::Rest::BaseException; end
|
34
|
+
|
35
|
+
#Exceptions thrown in case of an HTTP 404 is received.
|
36
|
+
#
|
37
|
+
#404 Not Found
|
38
|
+
#
|
39
|
+
#The server has not found anything matching the Request-URI or the
|
40
|
+
#requested resource does not exist
|
41
|
+
class ResourceNotFoundException < Rhc::Rest::ClientErrorException; end
|
42
|
+
|
43
|
+
#Exceptions thrown in case of an HTTP 422 is received.
|
44
|
+
class ValidationException < Rhc::Rest::ClientErrorException
|
45
|
+
attr_reader :field
|
46
|
+
def initialize(message, field=nil)
|
47
|
+
super(message)
|
48
|
+
@field = field
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#Exceptions thrown in case of an HTTP 403 is received.
|
53
|
+
#
|
54
|
+
#403 Forbidden
|
55
|
+
#
|
56
|
+
#The server understood the request, but is refusing to fulfill it.
|
57
|
+
#Authorization will not help and the request SHOULD NOT be repeated.
|
58
|
+
class RequestDeniedException < Rhc::Rest::ClientErrorException; end
|
59
|
+
|
60
|
+
#Exceptions thrown in case of an HTTP 401 is received.
|
61
|
+
#
|
62
|
+
#401 Unauthorized
|
63
|
+
#
|
64
|
+
#The request requires user authentication. If the request already
|
65
|
+
#included Authorization credentials, then the 401 response indicates
|
66
|
+
#that authorization has been refused for those credentials.
|
67
|
+
class UnAuthorizedException < Rhc::Rest::ClientErrorException; end
|
68
|
+
|
69
|
+
#I/O Exceptions Connection timeouts, Unreachable host, etc
|
70
|
+
class ResourceAccessException < Rhc::Rest::BaseException; end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
data/lib/rhc-rest/key.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Rhc
|
2
|
+
module Rest
|
3
|
+
class Key
|
4
|
+
include Rest
|
5
|
+
attr_reader :name, :type, :content
|
6
|
+
def initialize(args)
|
7
|
+
@name = args[:name] || args["name"]
|
8
|
+
@type = args[:type] || args["type"]
|
9
|
+
@content = args[:content] || args["content"]
|
10
|
+
@links = args[:links] || args["links"]
|
11
|
+
end
|
12
|
+
|
13
|
+
# Update Key
|
14
|
+
def update(type, content)
|
15
|
+
logger.debug "Updating key #{self.name}"
|
16
|
+
url = @@end_point + @links['UPDATE']['href']
|
17
|
+
method = @links['UPDATE']['method']
|
18
|
+
payload = {:type => type, :content => content}
|
19
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
20
|
+
return send(request)
|
21
|
+
end
|
22
|
+
|
23
|
+
#Delete Key
|
24
|
+
def destroy
|
25
|
+
logger.debug "Deleting key #{self.name}"
|
26
|
+
url = @@end_point + @links['DELETE']['href']
|
27
|
+
method = @links['DELETE']['method']
|
28
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers)
|
29
|
+
return send(request)
|
30
|
+
end
|
31
|
+
alias :delete :destroy
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Rhc
|
2
|
+
module Rest
|
3
|
+
class User
|
4
|
+
include Rest
|
5
|
+
attr_reader :login
|
6
|
+
def initialize(args)
|
7
|
+
@login = args[:login] || args["login"]
|
8
|
+
@links = args[:links] || args["links"]
|
9
|
+
end
|
10
|
+
|
11
|
+
#Add Key for this user
|
12
|
+
def add_key(name, content, type)
|
13
|
+
url = @@end_point + @links['ADD_KEY']['href']
|
14
|
+
method = @links['ADD_KEY']['method']
|
15
|
+
payload = {:name => name, :type => type, :content => content}
|
16
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
|
17
|
+
return send(request)
|
18
|
+
end
|
19
|
+
|
20
|
+
#Get all Key for this user
|
21
|
+
def keys
|
22
|
+
url = @@end_point + @links['LIST_KEYS']['href']
|
23
|
+
method = @links['LIST_KEYS']['method']
|
24
|
+
request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers)
|
25
|
+
return send(request)
|
26
|
+
end
|
27
|
+
|
28
|
+
#Find Key by name
|
29
|
+
def find_key(name)
|
30
|
+
filtered = Array.new
|
31
|
+
keys.each do |key|
|
32
|
+
#TODO do a regex caomparison
|
33
|
+
if key.name == name
|
34
|
+
filtered.push(key)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
return filtered
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|