secured_cloud_api_client 0.0.4 → 0.0.5

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: 18f67b7501fc4643d86bac1db9fbce0bdcf0d9f7
4
- data.tar.gz: 0cbfbb255c553911d3797514d79f1129dff3f05e
3
+ metadata.gz: 9d6206f2d96d105b093a709d0c4ed98ef41fe447
4
+ data.tar.gz: 58ffd32666332b32f5031e8c35b6982a58249dce
5
5
  SHA512:
6
- metadata.gz: 289a3fa97a09f3a60d08d7c51f4a22c5bd0449768dfabe151817055abe131bf5e45f63567a7e7e0837940cb604c9e8beb7624f1d443a283142c1e0b8be09dd4d
7
- data.tar.gz: b5c26511f522ffce53e3926d964a040038144e16a8c65f191ebaff79550f0ad839ebac986db30ccff98f58eb777b94e3570911a42ed2f2ace4b983cf63161dd3
6
+ metadata.gz: f9169c07d53fe554d1b974407532c6cda355c3c730e015bdd0877824e8968338be571096d8a51c3e97a8addb41aa93bdf67aced725b98ba2b2e4c06bf3911908
7
+ data.tar.gz: a75b25ded2f956be0fabfe0d7991744c86a8052a64f2b659326a5848e680287edcef8853944da35e98f952891a76a1bd6b21799968f03d6ab7f49bf0b285e115
@@ -7,6 +7,10 @@ require 'base64'
7
7
  # Class HttpClient performs HTTP requests to the Secured Cloud API Server.
8
8
  # Authentication is handled via the supplied application key and shared secret.
9
9
  #
10
+ # This class expects the pem file "/cert/sc.pem" to be found in the working
11
+ # directory of the application using this library. This pem file is used for
12
+ # SSL validation.
13
+ #
10
14
  # @author:: Alan Vella
11
15
  ##
12
16
 
@@ -41,7 +45,7 @@ class HttpClient
41
45
  end
42
46
  end
43
47
 
44
-
48
+
45
49
  #Sends an HTTP GET request and returns response.
46
50
  def self.sendGETRequest(authInfo, url)
47
51
 
@@ -49,22 +53,30 @@ class HttpClient
49
53
  @sharedSecret = authInfo.getSharedSecret()
50
54
 
51
55
  @url = URI.parse(url)
52
- req = Net::HTTP::Get.new(url)
53
-
54
- #Populate header with required stuff.
55
- req['Accept'] = APP_CONTENT_TYPE
56
- req['Authorization'] = AUTH_SCHEME + createAuthorization("GET", url)
57
-
58
- #Execute request.
59
- res = Net::HTTP.start(@url.host, @url.port,:use_ssl => @url.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) {|http|http.request(req)} # Net::HTTPResponse object
56
+
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")
64
+
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)
60
70
 
61
71
  #Raise error if response is not successful.
62
- self.handleResponseError(res)
72
+ self.handleResponseError(response)
63
73
 
64
74
  #Return response.
65
- return res
75
+ return response
66
76
  end
77
+
67
78
 
79
+
68
80
 
69
81
  #Sends an HTTP POST request and returns response.
70
82
  def self.sendPOSTRequest(authInfo, url, body)
@@ -73,22 +85,28 @@ class HttpClient
73
85
  @sharedSecret = authInfo.getSharedSecret()
74
86
 
75
87
  @url = URI.parse(url)
76
- req = Net::HTTP::Post.new(url)
77
- req.body = body
78
-
79
- #Populate header with required stuff.
80
- req['Accept'] = APP_CONTENT_TYPE
81
- req['Content-Type'] = APP_CONTENT_TYPE
82
- req['Authorization'] = AUTH_SCHEME + createAuthorization("POST", url)
83
-
84
- #Execute request.
85
- res = Net::HTTP.start(@url.host, @url.port,:use_ssl => @url.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) {|http|http.request(req)} # Net::HTTPResponse object
88
+
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")
96
+
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)
86
104
 
87
105
  #Raise error if response is not successful.
88
- self.handleResponseError(res)
89
-
106
+ self.handleResponseError(response)
107
+
90
108
  #Return response.
91
- return res
109
+ return response
92
110
  end
93
111
 
94
112
 
@@ -110,21 +128,27 @@ class HttpClient
110
128
  end
111
129
 
112
130
  @url = URI.parse(url)
113
- req = Net::HTTP::Delete.new(@url)
114
-
115
- #Populate header with required stuff.
116
- req['Accept'] = APP_CONTENT_TYPE
117
- req['Content-Type'] = APP_CONTENT_TYPE
118
- req['Authorization'] = AUTH_SCHEME + createAuthorization("DELETE", url)
119
-
120
- #Execute request.
121
- res = Net::HTTP.start(@url.host, @url.port,:use_ssl => @url.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) {|http|http.request(req)} # Net::HTTPResponse object
131
+
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")
139
+
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)
122
146
 
123
147
  #Raise error if response is not successful.
124
- self.handleResponseError(res)
125
-
148
+ self.handleResponseError(response)
149
+
126
150
  #Return response.
127
- return res
151
+ return response
128
152
 
129
153
  end
130
154
 
@@ -139,28 +163,35 @@ class HttpClient
139
163
  if (params != nil) then
140
164
  url += "?"
141
165
  params.each do |param|
142
- url += param[0] + "=" + param[1] + "&"
166
+ url += param[0] + "=" + param[1] + "&"
143
167
  end
168
+
144
169
  #Remove last ampersand
145
170
  url = url[0...-1]
146
171
  end
147
172
 
148
173
  @url = URI.parse(url)
149
- req = Net::HTTP::Put.new(@url)
150
-
151
- #Populate header with required stuff.
152
- req['Accept'] = APP_CONTENT_TYPE
153
- req['Content-Type'] = APP_CONTENT_TYPE
154
- req['Authorization'] = AUTH_SCHEME + createAuthorization("PUT", url)
155
-
156
- #Execute request.
157
- res = Net::HTTP.start(@url.host, @url.port,:use_ssl => @url.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) {|http|http.request(req)} # Net::HTTPResponse object
174
+
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")
182
+
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)
158
189
 
159
190
  #Raise error if response is not successful.
160
- self.handleResponseError(res)
161
-
191
+ self.handleResponseError(response)
192
+
162
193
  #Return response.
163
- return res
194
+ return response
164
195
 
165
196
  end
166
197
 
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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Vella