projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
6203: compute_pdh, computed_pdh etc etc etc confusion. clean up to make it easier...
[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 5decd77261a44bdc0ec4145cf5b3fce80aa7cb2b..56cdfb83a47d6487edd0494271b329075dbc0888 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
@@
-19,8
+28,8
@@
class Blob
# 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:
- # [required] :
key - the Arvados server-side blobstore key
- # [
required] :api_token - user's API token
+ # [required] :
api_token - API token (signatures only work for this token)
+ # [
optional] :key - the Arvados server-side blobstore key
# [optional] :ttl - number of seconds before signature should expire
# [optional] :expire - unix timestamp when signature should expire
#
# [optional] :ttl - number of seconds before signature should expire
# [optional] :expire - unix timestamp when signature should expire
#
@@
-35,14
+44,16
@@
class Blob
end
timestamp = opts[:expire]
else
end
timestamp = opts[:expire]
else
- timestamp = Time.now.to_i + (opts[:ttl] || 600)
+ timestamp = db_current_time.to_i +
+ (opts[:ttl] || Rails.configuration.blob_signature_ttl)
end
timestamp_hex = timestamp.to_s(16)
# => "53163cb4"
# Generate a signature.
signature =
end
timestamp_hex = timestamp.to_s(16)
# => "53163cb4"
# Generate a signature.
signature =
- generate_signature opts[:key], blob_hash, opts[:api_token], timestamp_hex
+ generate_signature((opts[:key] or Rails.configuration.blob_signing_key),
+ blob_hash, opts[:api_token], timestamp_hex)
blob_locator + '+A' + signature + '@' + timestamp_hex
end
blob_locator + '+A' + signature + '@' + timestamp_hex
end
@@
-82,12
+93,13
@@
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) <
Time.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
my_signature =
raise Blob::InvalidSignatureError.new 'Signature expiry time has passed.'
end
my_signature =
- generate_signature opts[:key], blob_hash, opts[:api_token], timestamp
+ generate_signature((opts[:key] or Rails.configuration.blob_signing_key),
+ blob_hash, opts[:api_token], timestamp)
if my_signature != given_signature
raise Blob::InvalidSignatureError.new 'Signature is invalid.'
if my_signature != given_signature
raise Blob::InvalidSignatureError.new 'Signature is invalid.'