ocean-rails 6.1.7 → 6.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ocean/api.rb +32 -22
- data/lib/ocean/version.rb +1 -1
- 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: a7db358dd02e5c6518a773461ca0d22b6123b0e8
|
4
|
+
data.tar.gz: 72830f4405a9d35e22693795de20d3bbb211be22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a9d574e20a145ecc738b0e7566ade9de5608505d64de0cb49391e8262e8723846f1ef4f5f6ff117caee49ba0b146fe5e767934ef7235a62c2789bb36ef58c02
|
7
|
+
data.tar.gz: 9e8f1cf62eabfcc3d297eb16392e1e79d25a523cdff38b279faf212be072edb72c8d9528322f15183a5491231193da55f37c9e33158209b92c8d59b557ab95bf
|
data/lib/ocean/api.rb
CHANGED
@@ -202,7 +202,7 @@ class Api
|
|
202
202
|
|
203
203
|
url = url.first == "/" ? "#{INTERNAL_OCEAN_API_URL}#{url}" : Api.internalize_uri(url)
|
204
204
|
|
205
|
-
# This is a Proc when run queues the request and schedules retries
|
205
|
+
# This is a Proc which when run queues the request and schedules retries
|
206
206
|
enqueue_request = lambda do
|
207
207
|
# First construct a request. It will not be sent yet.
|
208
208
|
request = Typhoeus::Request.new(url,
|
@@ -379,27 +379,37 @@ class Api
|
|
379
379
|
# If not successful, +nil+ is returned.
|
380
380
|
#
|
381
381
|
def self.authenticate(username=API_USER, password=API_PASSWORD)
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
382
|
+
attempts = 3
|
383
|
+
loop do
|
384
|
+
response = Typhoeus.post "#{INTERNAL_OCEAN_API_URL}/v1/authentications",
|
385
|
+
body: "", headers: {'X-API-Authenticate' => credentials(username, password)}
|
386
|
+
case response.code
|
387
|
+
when 100..199
|
388
|
+
return nil if attempts < 1
|
389
|
+
attempts -= 1
|
390
|
+
next
|
391
|
+
when 200..299
|
392
|
+
token = JSON.parse(response.body)['authentication']['token']
|
393
|
+
@service_token = token if username == API_USER && password == API_PASSWORD
|
394
|
+
return token
|
395
|
+
when 403
|
396
|
+
# Does not authenticate. Don't repeat the request.
|
397
|
+
return nil
|
398
|
+
when 400
|
399
|
+
# Malformed credentials. Don't repeat the request.
|
400
|
+
return nil
|
401
|
+
when 400..499
|
402
|
+
# Client error. Don't repeat the request.
|
403
|
+
return nil
|
404
|
+
when 500
|
405
|
+
# Error. Don't repeat.
|
406
|
+
return nil if attempts < 1
|
407
|
+
attempts -= 1
|
408
|
+
next
|
409
|
+
else
|
410
|
+
# Should never end up here.
|
411
|
+
raise "Authentication weirdness"
|
412
|
+
end
|
403
413
|
end
|
404
414
|
end
|
405
415
|
|
data/lib/ocean/version.rb
CHANGED