projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch '6087-collection-timing' (early part) refs #6087 refs #6092
[arvados.git]
/
services
/
api
/
app
/
models
/
blob.rb
diff --git
a/services/api/app/models/blob.rb
b/services/api/app/models/blob.rb
index c4e1881b29a6093cd12fefd2ffc49c469879dd1a..7ae13ef2d0126d0b41b28a344e391ad55a7e6a41 100644
(file)
--- a/
services/api/app/models/blob.rb
+++ b/
services/api/app/models/blob.rb
@@
-1,4
+1,13
@@
class Blob
class Blob
+ extend DbCurrentTime
+
+ def initialize locator
+ @locator = locator
+ end
+
+ def empty?
+ !!@locator.match(/^d41d8cd98f00b204e9800998ecf8427e(\+.*)?$/)
+ end
# In order to get a Blob from Keep, you have to prove either
# [a] you have recently written it to Keep yourself, or
# In order to get a Blob from Keep, you have to prove either
# [a] you have recently written it to Keep yourself, or
@@
-16,15
+25,6
@@
class Blob
class InvalidSignatureError < StandardError
end
class InvalidSignatureError < StandardError
end
- # Clock is a wrapper for Time.
- # It can be replaced with a stub for unit testing (the poor man's mock).
- # It must support a Clock.now method that returns a Time object.
- @@Clock = Time
-
- def self.set_clock c
- @@Clock = c
- end
-
# Blob.sign_locator: return a signed and timestamped blob locator.
#
# The 'opts' argument should include:
# Blob.sign_locator: return a signed and timestamped blob locator.
#
# The 'opts' argument should include:
@@
-44,7
+44,7
@@
class Blob
end
timestamp = opts[:expire]
else
end
timestamp = opts[:expire]
else
- timestamp =
@@Clock.now.to_i + (opts[:ttl] ||
600)
+ timestamp =
db_current_time.to_i + (opts[:ttl] || 1209
600)
end
timestamp_hex = timestamp.to_s(16)
# => "53163cb4"
end
timestamp_hex = timestamp.to_s(16)
# => "53163cb4"
@@
-91,7
+91,7
@@
class Blob
if !timestamp.match /^[\da-f]+$/
raise Blob::InvalidSignatureError.new 'Timestamp is not a base16 number.'
end
if !timestamp.match /^[\da-f]+$/
raise Blob::InvalidSignatureError.new 'Timestamp is not a base16 number.'
end
- if timestamp.to_i(16) <
@@Clock.now.to_i
+ if timestamp.to_i(16) <
(opts[:now] or db_current_time.to_i)
raise Blob::InvalidSignatureError.new 'Signature expiry time has passed.'
end
raise Blob::InvalidSignatureError.new 'Signature expiry time has passed.'
end