bits_service_client 4.0.0.pre.1 → 4.0.0.pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bits_service_client/blob.rb +26 -19
- data/lib/bits_service_client/version.rb +1 -1
- data/lib/util/signature_util.rb +4 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3e14006a7591b74626b0d7aae5f94271f4eba05
|
4
|
+
data.tar.gz: 3854d5007fc1c65ccc4a5c0b606305d52423f50f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f49af55aeb784e73e317358225f25359ab44c4af38d8e3497328729f2d9e9f9d6317f36617fff375ce571496dbf3372c998cb37dc1204f93054ba4aa4cab5993
|
7
|
+
data.tar.gz: 7cf1eb8b1a977db52fb6fa9f21f10e0a10f8b290f34b2c9d9917291c5a523904475ed0aafc894815ca4a9eba6c2350a5782f75feef020df45e983c5fbd9d0fbf
|
@@ -28,32 +28,23 @@ module BitsService
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def public_download_url
|
31
|
-
signed_url(key)
|
32
|
-
end
|
31
|
+
signed_url = "#{@public_endpoint}#{self.sign_signature(resource_path(key), @signing_key_secret, @signing_key_id)}"
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
33
|
+
response = @private_http_client.head(signed_url, @vcap_request_id)
|
34
|
+
validate_response_code!([200, 302], response)
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def signed_url(key, verb: nil)
|
45
|
-
query = if verb.nil?
|
46
|
-
''
|
36
|
+
if response.code.to_i == 302
|
37
|
+
response['location']
|
47
38
|
else
|
48
|
-
|
39
|
+
signed_url
|
49
40
|
end
|
41
|
+
end
|
50
42
|
|
51
|
-
|
52
|
-
|
53
|
-
return signed_url
|
43
|
+
def public_upload_url
|
44
|
+
"#{@public_endpoint}#{self.sign_signature(resource_path(key), @signing_key_secret, @signing_key_id)}&async=true&verb=put"
|
54
45
|
end
|
55
46
|
|
56
|
-
def
|
47
|
+
def internal_download_url
|
57
48
|
path = resource_path(key)
|
58
49
|
|
59
50
|
@private_http_client.head(path, @vcap_request_id).tap do |response|
|
@@ -63,6 +54,22 @@ module BitsService
|
|
63
54
|
File.join(@private_endpoint.to_s, path)
|
64
55
|
end
|
65
56
|
|
57
|
+
private
|
58
|
+
|
59
|
+
def validate_response_code!(expected_codes, response)
|
60
|
+
return if Array(expected_codes).include?(response.code.to_i)
|
61
|
+
|
62
|
+
error = {
|
63
|
+
response_code: response.code,
|
64
|
+
response_body: response.body,
|
65
|
+
response: response
|
66
|
+
}.to_json
|
67
|
+
|
68
|
+
logger.error("UnexpectedResponseCode: expected '#{expected_codes}' got #{response.code}")
|
69
|
+
|
70
|
+
fail BlobstoreError.new(error)
|
71
|
+
end
|
72
|
+
|
66
73
|
def resource_path(key)
|
67
74
|
prefix = @resource_type == :buildpack_cache ? 'buildpack_cache/entries/' : @resource_type
|
68
75
|
File.join('/', prefix.to_s, key.to_s)
|
data/lib/util/signature_util.rb
CHANGED
@@ -2,12 +2,10 @@ module BitsService
|
|
2
2
|
module SignatureUtil
|
3
3
|
def sign_signature(resource_path, key_secret, key_id)
|
4
4
|
expires = seconds_since_the_unix_epoch_with_offset(3600)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
signed_path = "#{resource_path}?signature=#{signature}&expires=#{expires}&AccessKeyId=#{key_id}"
|
10
|
-
return signed_path
|
5
|
+
"#{resource_path}?"+
|
6
|
+
"signature=#{OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, key_secret, "#{expires}#{resource_path} #{key_secret}")}&"+
|
7
|
+
"expires=#{expires}&"+
|
8
|
+
"AccessKeyId=#{key_id}"
|
11
9
|
end
|
12
10
|
|
13
11
|
def seconds_since_the_unix_epoch_with_offset(offset)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bits_service_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.pre.
|
4
|
+
version: 4.0.0.pre.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rizwan Reza
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2019-01-
|
15
|
+
date: 2019-01-25 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activesupport
|