rhc-rest 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/lib/rhc-rest.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'logger'
|
4
|
+
require 'json'
|
5
|
+
require File.dirname(__FILE__) + '/rhc-rest/exceptions/exceptions.rb'
|
6
|
+
require File.dirname(__FILE__) + '/rhc-rest/application'
|
7
|
+
require File.dirname(__FILE__) + '/rhc-rest/cartridge'
|
8
|
+
require File.dirname(__FILE__) + '/rhc-rest/client'
|
9
|
+
require File.dirname(__FILE__) + '/rhc-rest/domain'
|
10
|
+
require File.dirname(__FILE__) + '/rhc-rest/key'
|
11
|
+
require File.dirname(__FILE__) + '/rhc-rest/user'
|
12
|
+
|
13
|
+
@@end_point = ""
|
14
|
+
@@headers = {:accept => :json}
|
15
|
+
|
16
|
+
module Rhc
|
17
|
+
module Rest
|
18
|
+
def logger
|
19
|
+
if defined?Rails.logger
|
20
|
+
Rails.logger
|
21
|
+
else
|
22
|
+
Logger.new(STDOUT)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_response(response)
|
27
|
+
result = JSON.parse(response)
|
28
|
+
type = result['type']
|
29
|
+
data = result['data']
|
30
|
+
case type
|
31
|
+
when 'domains'
|
32
|
+
domains = Array.new
|
33
|
+
data.each do |domain_json|
|
34
|
+
domains.push(Domain.new(domain_json))
|
35
|
+
end
|
36
|
+
return domains
|
37
|
+
when 'domain'
|
38
|
+
return Domain.new(data)
|
39
|
+
when 'applications'
|
40
|
+
apps = Array.new
|
41
|
+
data.each do |app_json|
|
42
|
+
apps.push(Application.new(app_json))
|
43
|
+
end
|
44
|
+
return apps
|
45
|
+
when 'application'
|
46
|
+
return Application.new(data)
|
47
|
+
when 'cartridges'
|
48
|
+
carts = Array.new
|
49
|
+
data.each do |cart_json|
|
50
|
+
carts.push(Cartridge.new(cart_json))
|
51
|
+
end
|
52
|
+
return carts
|
53
|
+
when 'cartridge'
|
54
|
+
return Cartridge.new(data)
|
55
|
+
when 'user'
|
56
|
+
return User.new(data)
|
57
|
+
when 'keys'
|
58
|
+
keys = Array.new
|
59
|
+
data.each do |key_json|
|
60
|
+
keys.push(Key.new(key_json))
|
61
|
+
end
|
62
|
+
return keys
|
63
|
+
when 'key'
|
64
|
+
return Key.new(data)
|
65
|
+
else
|
66
|
+
data
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def send(request)
|
71
|
+
begin
|
72
|
+
#puts request.headers
|
73
|
+
response = request.execute
|
74
|
+
#set cookie
|
75
|
+
rh_sso = response.cookies['rh_sso']
|
76
|
+
#puts response.cookies
|
77
|
+
if not rh_sso.nil?
|
78
|
+
@@headers["cookie"] = "rh_sso=#{rh_sso}"
|
79
|
+
end
|
80
|
+
#puts "#{response}"
|
81
|
+
return parse_response(response) unless response.nil? or response.code == 204
|
82
|
+
rescue RestClient::ExceptionWithResponse => e
|
83
|
+
#puts "#{e.response}"
|
84
|
+
process_error_response(e.response)
|
85
|
+
rescue Exception => e
|
86
|
+
raise ResourceAccessException.new("Failed to access resource: #{e.message}")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def process_error_response(response)
|
91
|
+
messages = Array.new
|
92
|
+
begin
|
93
|
+
result = JSON.parse(response)
|
94
|
+
messages = result['messages']
|
95
|
+
rescue Exception => e
|
96
|
+
logger.debug "Response did not include a message from server"
|
97
|
+
#puts response
|
98
|
+
end
|
99
|
+
case response.code
|
100
|
+
when 401
|
101
|
+
raise UnAuthorizedException.new("Not authenticated")
|
102
|
+
when 403
|
103
|
+
messages.each do |message|
|
104
|
+
if message['severity'].upcase == "ERROR"
|
105
|
+
raise RequestDeniedException.new(message['text'])
|
106
|
+
end
|
107
|
+
end
|
108
|
+
when 404
|
109
|
+
messages.each do |message|
|
110
|
+
if message['severity'].upcase == "ERROR"
|
111
|
+
raise ResourceNotFoundException.new(message['text'])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
when 409
|
115
|
+
messages.each do |message|
|
116
|
+
if message['severity'] and message['severity'].upcase == "ERROR"
|
117
|
+
raise ValidationException.new(message['text'])
|
118
|
+
end
|
119
|
+
end
|
120
|
+
when 422
|
121
|
+
#puts response
|
122
|
+
e = nil
|
123
|
+
messages.each do |message|
|
124
|
+
if message["field"]
|
125
|
+
if e and e.field ==message["field"]
|
126
|
+
e.message << " #{message["text"]}"
|
127
|
+
else
|
128
|
+
e = ValidationException.new(message["text"], message["field"])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
raise e
|
133
|
+
when 400
|
134
|
+
messages.each do |message|
|
135
|
+
if message['severity'].upcase == "ERROR"
|
136
|
+
raise ClientErrorException.new(message['text'])
|
137
|
+
end
|
138
|
+
end
|
139
|
+
when 500
|
140
|
+
messages.each do |message|
|
141
|
+
if message['severity'].upcase == "ERROR"
|
142
|
+
raise ServerErrorException.new(message['text'])
|
143
|
+
end
|
144
|
+
end
|
145
|
+
when 503
|
146
|
+
messages.each do |message|
|
147
|
+
if message['severity'].upcase == "ERROR"
|
148
|
+
raise ServiceUnavailableException.new(message['text'])
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
data/rhc-rest.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rhc-rest/version"
|
4
|
+
bin_dir = File.join("bin", "*")
|
5
|
+
lib_dir = File.join(File.join("lib", "**"), "*")
|
6
|
+
doc_dir = File.join(File.join("doc", "**"), "*")
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = "rhc-rest"
|
10
|
+
s.version = /(Version: )(.*)/.match(File.read("rhc-rest.spec"))[2].strip
|
11
|
+
s.authors = ["Red Hat"]
|
12
|
+
s.email = ["openshift@redhat.com"]
|
13
|
+
s.homepage = "http://www.openshift.com"
|
14
|
+
s.summary = %q{Ruby REST client for OpenShift REST API}
|
15
|
+
s.description = %q{Ruby bindings for OpenShift REST API}
|
16
|
+
|
17
|
+
s.rubyforge_project = "rhc-rest"
|
18
|
+
|
19
|
+
s.files = Dir[lib_dir] + Dir[bin_dir] + Dir[doc_dir]
|
20
|
+
s.files += %w(Rakefile rhc-rest.gemspec Gemfile rhc-rest.spec COPYRIGHT LICENSE)
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
# specify any dependencies here; for example:
|
24
|
+
s.add_dependency("json")
|
25
|
+
s.add_dependency("rest-client")
|
26
|
+
end
|
data/rhc-rest.spec
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
%global ruby_sitelib %(ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']")
|
2
|
+
%define gemdir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null)
|
3
|
+
%global gemname rhc-rest
|
4
|
+
%global geminstdir %{gemdir}/gems/%{gemname}-%{version}
|
5
|
+
|
6
|
+
|
7
|
+
Summary: Ruby bindings/client for OpenShift REST API
|
8
|
+
Name: rhc-rest
|
9
|
+
Version: 0.0.7
|
10
|
+
Release: 1%{?dist}
|
11
|
+
Group: Network/Daemons
|
12
|
+
License: ASL 2.0
|
13
|
+
URL: http://openshift.redhat.com
|
14
|
+
Source0: rhc-rest-%{version}.tar.gz
|
15
|
+
|
16
|
+
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
|
17
|
+
BuildRequires: rubygem-rake
|
18
|
+
BuildRequires: rubygem-rspec
|
19
|
+
Requires: ruby >= 1.8.5
|
20
|
+
Requires: rubygem-rest-client
|
21
|
+
Requires: rubygem-json
|
22
|
+
|
23
|
+
BuildArch: noarch
|
24
|
+
|
25
|
+
%description
|
26
|
+
Provides Ruby bindings/client for OpenShift REST API
|
27
|
+
|
28
|
+
%prep
|
29
|
+
%setup -q
|
30
|
+
|
31
|
+
%build
|
32
|
+
for f in lib/*.rb
|
33
|
+
do
|
34
|
+
ruby -c $f
|
35
|
+
done
|
36
|
+
|
37
|
+
%install
|
38
|
+
rm -rf %{buildroot}
|
39
|
+
mkdir -p %{buildroot}%{gemdir}
|
40
|
+
mkdir -p %{buildroot}%{ruby_sitelib}
|
41
|
+
|
42
|
+
# Build and install into the rubygem structure
|
43
|
+
gem build %{gemname}.gemspec
|
44
|
+
gem install --local --install-dir %{buildroot}/%{gemdir} --force %{gemname}-%{version}.gem
|
45
|
+
|
46
|
+
%clean
|
47
|
+
rm -rf %{buildroot}
|
48
|
+
|
49
|
+
%files
|
50
|
+
%defattr(-,root,root,-)
|
51
|
+
%{gemdir}/gems/rhc-rest-%{version}/
|
52
|
+
%{gemdir}/cache/rhc-rest-%{version}.gem
|
53
|
+
%{gemdir}/doc/rhc-rest-%{version}
|
54
|
+
%{gemdir}/specifications/rhc-rest-%{version}.gemspec
|
55
|
+
%doc LICENSE
|
56
|
+
%doc COPYRIGHT
|
57
|
+
|
58
|
+
%changelog
|
59
|
+
* Wed Mar 21 2012 Lili Nader <lnader@redhat.com> 0.0.7-1
|
60
|
+
- Get rhc-rest a building ... (ramr@redhat.com)
|
61
|
+
- Fix to get rhc-rest building. (ramr@redhat.com)
|
62
|
+
|
63
|
+
* Tue Mar 20 2012 Lili Nader <lnader@redhat.com> 0.0.5-1
|
64
|
+
- corrected version in gemspec (lnader@redhat.com)
|
65
|
+
|
66
|
+
* Tue Mar 20 2012 Lili Nader <lnader@redhat.com> 0.0.4-1
|
67
|
+
- corrected build error (lnader@redhat.com)
|
68
|
+
|
69
|
+
* Fri Mar 16 2012 Lili Nader <lnader@redhat.com> 0.0.3-1
|
70
|
+
- new package built with tito
|
71
|
+
|
72
|
+
* Tue Feb 14 2012 Lili Nader <lnader@redhat.com> 0.0.2-1
|
73
|
+
- new package built with tito
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rhc-rest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Red Hat
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-04-04 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: json
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rest-client
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
description: Ruby bindings for OpenShift REST API
|
49
|
+
email:
|
50
|
+
- openshift@redhat.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- lib/rhc-rest/application.rb
|
59
|
+
- lib/rhc-rest/client.rb
|
60
|
+
- lib/rhc-rest/exceptions/exceptions.rb
|
61
|
+
- lib/rhc-rest/user.rb
|
62
|
+
- lib/rhc-rest/key.rb
|
63
|
+
- lib/rhc-rest/domain.rb
|
64
|
+
- lib/rhc-rest/cartridge.rb
|
65
|
+
- lib/rhc-rest/version.rb
|
66
|
+
- lib/rhc-rest.rb
|
67
|
+
- bin/sample-usage.rb
|
68
|
+
- doc/created.rid
|
69
|
+
- doc/Rhc.html
|
70
|
+
- doc/Rakefile.html
|
71
|
+
- doc/rdoc.css
|
72
|
+
- doc/Rhc/Rest.html
|
73
|
+
- doc/Rhc/Rest/Application.html
|
74
|
+
- doc/Rhc/Rest/User.html
|
75
|
+
- doc/Rhc/Rest/ResourceNotFoundException.html
|
76
|
+
- doc/Rhc/Rest/Client.html
|
77
|
+
- doc/Rhc/Rest/Domain.html
|
78
|
+
- doc/Rhc/Rest/ResourceAccessException.html
|
79
|
+
- doc/Rhc/Rest/BaseException.html
|
80
|
+
- doc/Rhc/Rest/ClientErrorException.html
|
81
|
+
- doc/Rhc/Rest/ValidationException.html
|
82
|
+
- doc/Rhc/Rest/ServiceUnavailableException.html
|
83
|
+
- doc/Rhc/Rest/Cartridge.html
|
84
|
+
- doc/Rhc/Rest/ServerErrorException.html
|
85
|
+
- doc/Rhc/Rest/UnAuthorizedException.html
|
86
|
+
- doc/Rhc/Rest/RequestDeniedException.html
|
87
|
+
- doc/Rhc/Rest/Key.html
|
88
|
+
- doc/table_of_contents.html
|
89
|
+
- doc/index.html
|
90
|
+
- doc/images/tag_green.png
|
91
|
+
- doc/images/bug.png
|
92
|
+
- doc/images/page_green.png
|
93
|
+
- doc/images/page_white_text.png
|
94
|
+
- doc/images/tag_blue.png
|
95
|
+
- doc/images/zoom.png
|
96
|
+
- doc/images/page_white_width.png
|
97
|
+
- doc/images/package.png
|
98
|
+
- doc/images/wrench_orange.png
|
99
|
+
- doc/images/transparent.png
|
100
|
+
- doc/images/bullet_toggle_minus.png
|
101
|
+
- doc/images/bullet_black.png
|
102
|
+
- doc/images/date.png
|
103
|
+
- doc/images/brick.png
|
104
|
+
- doc/images/ruby.png
|
105
|
+
- doc/images/wrench.png
|
106
|
+
- doc/images/plugin.png
|
107
|
+
- doc/images/macFFBgHack.png
|
108
|
+
- doc/images/brick_link.png
|
109
|
+
- doc/images/find.png
|
110
|
+
- doc/images/delete.png
|
111
|
+
- doc/images/bullet_toggle_plus.png
|
112
|
+
- doc/images/loadingAnimation.gif
|
113
|
+
- doc/images/add.png
|
114
|
+
- doc/js/darkfish.js
|
115
|
+
- doc/js/navigation.js
|
116
|
+
- doc/js/searcher.js
|
117
|
+
- doc/js/search_index.js
|
118
|
+
- doc/js/search.js
|
119
|
+
- doc/js/jquery.js
|
120
|
+
- doc/doc/created.rid
|
121
|
+
- doc/Gemfile.html
|
122
|
+
- Rakefile
|
123
|
+
- rhc-rest.gemspec
|
124
|
+
- Gemfile
|
125
|
+
- rhc-rest.spec
|
126
|
+
- COPYRIGHT
|
127
|
+
- LICENSE
|
128
|
+
homepage: http://www.openshift.com
|
129
|
+
licenses: []
|
130
|
+
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
hash: 3
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
version: "0"
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
hash: 3
|
151
|
+
segments:
|
152
|
+
- 0
|
153
|
+
version: "0"
|
154
|
+
requirements: []
|
155
|
+
|
156
|
+
rubyforge_project: rhc-rest
|
157
|
+
rubygems_version: 1.8.11
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: Ruby REST client for OpenShift REST API
|
161
|
+
test_files: []
|
162
|
+
|