secured_cloud_api_client 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d6206f2d96d105b093a709d0c4ed98ef41fe447
4
- data.tar.gz: 58ffd32666332b32f5031e8c35b6982a58249dce
3
+ metadata.gz: 5d6449ab212d358c4e72f0346eb3c134ea47f639
4
+ data.tar.gz: eccea57c73d0dd52f9c3da66dacb2e0a92faadac
5
5
  SHA512:
6
- metadata.gz: f9169c07d53fe554d1b974407532c6cda355c3c730e015bdd0877824e8968338be571096d8a51c3e97a8addb41aa93bdf67aced725b98ba2b2e4c06bf3911908
7
- data.tar.gz: a75b25ded2f956be0fabfe0d7991744c86a8052a64f2b659326a5848e680287edcef8853944da35e98f952891a76a1bd6b21799968f03d6ab7f49bf0b285e115
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
- @applicationKey = authInfo.getApplicationKey()
53
- @sharedSecret = authInfo.getSharedSecret()
62
+ self.runChecks
63
+
64
+ begin
65
+
66
+ @applicationKey = authInfo.getApplicationKey()
67
+ @sharedSecret = authInfo.getSharedSecret()
54
68
 
55
- @url = URI.parse(url)
69
+ @url = URI.parse(url)
56
70
 
57
- #Setup SSL validation.
58
- http = Net::HTTP.new(@url.host, @url.port)
59
- http.use_ssl = true
60
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
61
- http.cert_store = OpenSSL::X509::Store.new
62
- http.cert_store.set_default_paths
63
- http.cert_store.add_file(Dir.pwd + "/cert/sc.pem")
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
- #Create and execute request
66
- request = Net::HTTP::Get.new(@url.request_uri)
67
- request['Accept'] = APP_CONTENT_TYPE
68
- request['Authorization'] = AUTH_SCHEME + createAuthorization("GET", url)
69
- response = http.request(request)
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
- @applicationKey = authInfo.getApplicationKey()
85
- @sharedSecret = authInfo.getSharedSecret()
103
+ self.runChecks
104
+
105
+ begin
106
+
107
+ @applicationKey = authInfo.getApplicationKey()
108
+ @sharedSecret = authInfo.getSharedSecret()
86
109
 
87
- @url = URI.parse(url)
110
+ @url = URI.parse(url)
88
111
 
89
- #Setup SSL validation.
90
- http = Net::HTTP.new(@url.host, @url.port)
91
- http.use_ssl = true
92
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
93
- http.cert_store = OpenSSL::X509::Store.new
94
- http.cert_store.set_default_paths
95
- http.cert_store.add_file(Dir.pwd + "/cert/sc.pem")
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
- #Create and execute request
98
- request = Net::HTTP::Post.new(@url.request_uri)
99
- request['Accept'] = APP_CONTENT_TYPE
100
- request['Content-Type'] = APP_CONTENT_TYPE
101
- request['Authorization'] = AUTH_SCHEME + createAuthorization("POST", url)
102
- request.body = body
103
- response = http.request(request)
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
- @applicationKey = authInfo.getApplicationKey()
117
- @sharedSecret = authInfo.getSharedSecret()
144
+ self.runChecks
118
145
 
119
- #Add parameters if present
120
- if (params != nil) then
121
- url += "?"
122
- params.each do |param|
123
- url += param[0] + "=" + param[1] + "&"
124
- end
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
- #Remove last ampersand
127
- url = url[0...-1]
128
- end
158
+ #Remove last ampersand
159
+ url = url[0...-1]
160
+ end
129
161
 
130
- @url = URI.parse(url)
162
+ @url = URI.parse(url)
131
163
 
132
- #Setup SSL validation.
133
- http = Net::HTTP.new(@url.host, @url.port)
134
- http.use_ssl = true
135
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
136
- http.cert_store = OpenSSL::X509::Store.new
137
- http.cert_store.set_default_paths
138
- http.cert_store.add_file(Dir.pwd + "/cert/sc.pem")
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
- #Create and execute request
141
- request = Net::HTTP::Delete.new(@url.request_uri)
142
- request['Accept'] = APP_CONTENT_TYPE
143
- request['Content-Type'] = APP_CONTENT_TYPE
144
- request['Authorization'] = AUTH_SCHEME + createAuthorization("DELETE", url)
145
- response = http.request(request)
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
- @applicationKey = authInfo.getApplicationKey()
160
- @sharedSecret = authInfo.getSharedSecret()
196
+ self.runChecks
161
197
 
162
- #Add parameters if present
163
- if (params != nil) then
164
- url += "?"
165
- params.each do |param|
166
- url += param[0] + "=" + param[1] + "&"
167
- end
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
- #Remove last ampersand
170
- url = url[0...-1]
171
- end
210
+ #Remove last ampersand
211
+ url = url[0...-1]
212
+ end
172
213
 
173
- @url = URI.parse(url)
214
+ @url = URI.parse(url)
174
215
 
175
- #Setup SSL validation.
176
- http = Net::HTTP.new(@url.host, @url.port)
177
- http.use_ssl = true
178
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
179
- http.cert_store = OpenSSL::X509::Store.new
180
- http.cert_store.set_default_paths
181
- http.cert_store.add_file(Dir.pwd + "/cert/sc.pem")
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
- #Create and execute request
184
- request = Net::HTTP::Put.new(@url.request_uri)
185
- request['Accept'] = APP_CONTENT_TYPE
186
- request['Content-Type'] = APP_CONTENT_TYPE
187
- request['Authorization'] = AUTH_SCHEME + createAuthorization("PUT", url)
188
- response = http.request(request)
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secured_cloud_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Vella