secured_cloud_api_client 0.0.5 → 0.0.6
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.
- checksums.yaml +4 -4
- data/lib/secured_cloud_api_client/http_client.rb +128 -82
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d6449ab212d358c4e72f0346eb3c134ea47f639
|
4
|
+
data.tar.gz: eccea57c73d0dd52f9c3da66dacb2e0a92faadac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 460772ad66e9ddac1159bccb90c7d0a8c9759e1da25802f9f7831f53a339285c379f177bd12ec7524d35342c8ea4af4e47cc4bdc8cae7efcd6a006dd62f19dcd
|
7
|
+
data.tar.gz: 734c5168f05e8a228478ac653c62fc81c7a13de850346417689e4e33584bb4c836e624c4b596cb185849fcc0238381c883d8a96632f4d883725494f1fa4b2215
|
@@ -19,6 +19,16 @@ class HttpClient
|
|
19
19
|
|
20
20
|
APP_CONTENT_TYPE = "application/vnd.securedcloud.v7.0+json"
|
21
21
|
AUTH_SCHEME = "SC "
|
22
|
+
PEM_FILE_PATH = Dir.pwd + "/cert/sc.pem"
|
23
|
+
|
24
|
+
|
25
|
+
#Run checks before issuing request.
|
26
|
+
def self.runChecks
|
27
|
+
if !(File.exists?(PEM_FILE_PATH)) then
|
28
|
+
raise "A valid pem file named sc.pem is required for SSL validation. This file must be placed in the cert directory of your vagrant workspace."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
22
32
|
|
23
33
|
|
24
34
|
#Raise error if response is not successful.
|
@@ -49,24 +59,33 @@ class HttpClient
|
|
49
59
|
#Sends an HTTP GET request and returns response.
|
50
60
|
def self.sendGETRequest(authInfo, url)
|
51
61
|
|
52
|
-
|
53
|
-
|
62
|
+
self.runChecks
|
63
|
+
|
64
|
+
begin
|
65
|
+
|
66
|
+
@applicationKey = authInfo.getApplicationKey()
|
67
|
+
@sharedSecret = authInfo.getSharedSecret()
|
54
68
|
|
55
|
-
|
69
|
+
@url = URI.parse(url)
|
56
70
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
71
|
+
#Setup SSL validation.
|
72
|
+
http = Net::HTTP.new(@url.host, @url.port)
|
73
|
+
http.use_ssl = true
|
74
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
75
|
+
http.cert_store = OpenSSL::X509::Store.new
|
76
|
+
http.cert_store.set_default_paths
|
77
|
+
http.cert_store.add_file(PEM_FILE_PATH)
|
64
78
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
79
|
+
#Create and execute request
|
80
|
+
request = Net::HTTP::Get.new(@url.request_uri)
|
81
|
+
request['Accept'] = APP_CONTENT_TYPE
|
82
|
+
request['Authorization'] = AUTH_SCHEME + createAuthorization("GET", url)
|
83
|
+
response = http.request(request)
|
84
|
+
|
85
|
+
rescue Exception => e
|
86
|
+
raise "Error creating API request: " + e.message
|
87
|
+
|
88
|
+
end
|
70
89
|
|
71
90
|
#Raise error if response is not successful.
|
72
91
|
self.handleResponseError(response)
|
@@ -81,26 +100,35 @@ class HttpClient
|
|
81
100
|
#Sends an HTTP POST request and returns response.
|
82
101
|
def self.sendPOSTRequest(authInfo, url, body)
|
83
102
|
|
84
|
-
|
85
|
-
|
103
|
+
self.runChecks
|
104
|
+
|
105
|
+
begin
|
106
|
+
|
107
|
+
@applicationKey = authInfo.getApplicationKey()
|
108
|
+
@sharedSecret = authInfo.getSharedSecret()
|
86
109
|
|
87
|
-
|
110
|
+
@url = URI.parse(url)
|
88
111
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
112
|
+
#Setup SSL validation.
|
113
|
+
http = Net::HTTP.new(@url.host, @url.port)
|
114
|
+
http.use_ssl = true
|
115
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
116
|
+
http.cert_store = OpenSSL::X509::Store.new
|
117
|
+
http.cert_store.set_default_paths
|
118
|
+
http.cert_store.add_file(PEM_FILE_PATH)
|
96
119
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
120
|
+
#Create and execute request
|
121
|
+
request = Net::HTTP::Post.new(@url.request_uri)
|
122
|
+
request['Accept'] = APP_CONTENT_TYPE
|
123
|
+
request['Content-Type'] = APP_CONTENT_TYPE
|
124
|
+
request['Authorization'] = AUTH_SCHEME + createAuthorization("POST", url)
|
125
|
+
request.body = body
|
126
|
+
response = http.request(request)
|
127
|
+
|
128
|
+
rescue Exception => e
|
129
|
+
raise "Error creating API request: " + e.message
|
130
|
+
|
131
|
+
end
|
104
132
|
|
105
133
|
#Raise error if response is not successful.
|
106
134
|
self.handleResponseError(response)
|
@@ -113,36 +141,45 @@ class HttpClient
|
|
113
141
|
#Sends an HTTP DELETE request and returns response.
|
114
142
|
def self.sendDELETERequest(authInfo, url, params = nil)
|
115
143
|
|
116
|
-
|
117
|
-
@sharedSecret = authInfo.getSharedSecret()
|
144
|
+
self.runChecks
|
118
145
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
146
|
+
begin
|
147
|
+
|
148
|
+
@applicationKey = authInfo.getApplicationKey()
|
149
|
+
@sharedSecret = authInfo.getSharedSecret()
|
150
|
+
|
151
|
+
#Add parameters if present
|
152
|
+
if (params != nil) then
|
153
|
+
url += "?"
|
154
|
+
params.each do |param|
|
155
|
+
url += param[0] + "=" + param[1] + "&"
|
156
|
+
end
|
125
157
|
|
126
|
-
|
127
|
-
|
128
|
-
|
158
|
+
#Remove last ampersand
|
159
|
+
url = url[0...-1]
|
160
|
+
end
|
129
161
|
|
130
|
-
|
162
|
+
@url = URI.parse(url)
|
131
163
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
164
|
+
#Setup SSL validation.
|
165
|
+
http = Net::HTTP.new(@url.host, @url.port)
|
166
|
+
http.use_ssl = true
|
167
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
168
|
+
http.cert_store = OpenSSL::X509::Store.new
|
169
|
+
http.cert_store.set_default_paths
|
170
|
+
http.cert_store.add_file(PEM_FILE_PATH)
|
139
171
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
172
|
+
#Create and execute request
|
173
|
+
request = Net::HTTP::Delete.new(@url.request_uri)
|
174
|
+
request['Accept'] = APP_CONTENT_TYPE
|
175
|
+
request['Content-Type'] = APP_CONTENT_TYPE
|
176
|
+
request['Authorization'] = AUTH_SCHEME + createAuthorization("DELETE", url)
|
177
|
+
response = http.request(request)
|
178
|
+
|
179
|
+
rescue Exception => e
|
180
|
+
raise "Error creating API request: " + e.message
|
181
|
+
|
182
|
+
end
|
146
183
|
|
147
184
|
#Raise error if response is not successful.
|
148
185
|
self.handleResponseError(response)
|
@@ -156,36 +193,45 @@ class HttpClient
|
|
156
193
|
#Sends an HTTP PUT request and returns response.
|
157
194
|
def self.sendPUTRequest(authInfo, url, params = nil)
|
158
195
|
|
159
|
-
|
160
|
-
@sharedSecret = authInfo.getSharedSecret()
|
196
|
+
self.runChecks
|
161
197
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
198
|
+
begin
|
199
|
+
|
200
|
+
@applicationKey = authInfo.getApplicationKey()
|
201
|
+
@sharedSecret = authInfo.getSharedSecret()
|
202
|
+
|
203
|
+
#Add parameters if present
|
204
|
+
if (params != nil) then
|
205
|
+
url += "?"
|
206
|
+
params.each do |param|
|
207
|
+
url += param[0] + "=" + param[1] + "&"
|
208
|
+
end
|
168
209
|
|
169
|
-
|
170
|
-
|
171
|
-
|
210
|
+
#Remove last ampersand
|
211
|
+
url = url[0...-1]
|
212
|
+
end
|
172
213
|
|
173
|
-
|
214
|
+
@url = URI.parse(url)
|
174
215
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
216
|
+
#Setup SSL validation.
|
217
|
+
http = Net::HTTP.new(@url.host, @url.port)
|
218
|
+
http.use_ssl = true
|
219
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
220
|
+
http.cert_store = OpenSSL::X509::Store.new
|
221
|
+
http.cert_store.set_default_paths
|
222
|
+
http.cert_store.add_file(PEM_FILE_PATH)
|
182
223
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
224
|
+
#Create and execute request
|
225
|
+
request = Net::HTTP::Put.new(@url.request_uri)
|
226
|
+
request['Accept'] = APP_CONTENT_TYPE
|
227
|
+
request['Content-Type'] = APP_CONTENT_TYPE
|
228
|
+
request['Authorization'] = AUTH_SCHEME + createAuthorization("PUT", url)
|
229
|
+
response = http.request(request)
|
230
|
+
|
231
|
+
rescue Exception => e
|
232
|
+
raise "Error creating API request: " + e.message
|
233
|
+
|
234
|
+
end
|
189
235
|
|
190
236
|
#Raise error if response is not successful.
|
191
237
|
self.handleResponseError(response)
|