bits_service_client 3.2.0 → 3.3.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bits_service_client/blob.rb +80 -7
- data/lib/bits_service_client/client.rb +7 -31
- data/lib/bits_service_client/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7073bd4444bd3db84ea5e8dd7fba708196c1aa01
|
4
|
+
data.tar.gz: 355aebf3a4a5a1dd8b36d69e9ec0625a7a0ef539
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 111df09d52b46ee4bd06d5bc0cd6704166524b9afc7590363b3c5c9ea0da2ded407943897ae233bf815465afea3634ef50ac035dd41ef33cab25932d7d256b15
|
7
|
+
data.tar.gz: 0fcc11ab565da88f9a7d05c9bf02fd6e70fd86ecf41f4204bbd4a16a7aefa3d67fe40d1e4ff2a95bfff1958721814d14cb015019afa25f09b5f26be728d3c4a8
|
@@ -1,17 +1,90 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module BitsService
|
3
3
|
class Blob
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :key
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
6
|
+
def initialize(key:, private_endpoint:, private_http_client:, vcap_request_id:, username:, password:, resource_type:)
|
7
|
+
@key = key
|
8
|
+
@private_http_client = private_http_client
|
9
|
+
@vcap_request_id = vcap_request_id
|
10
|
+
@username = username
|
11
|
+
@password =password
|
12
|
+
@resource_type = resource_type
|
13
|
+
@private_endpoint = private_endpoint
|
11
14
|
end
|
12
15
|
|
13
16
|
def attributes(*_)
|
14
|
-
|
17
|
+
{}
|
18
|
+
end
|
19
|
+
|
20
|
+
def guid
|
21
|
+
key
|
22
|
+
end
|
23
|
+
|
24
|
+
def public_download_url
|
25
|
+
signed_url(key)
|
26
|
+
end
|
27
|
+
|
28
|
+
def public_upload_url
|
29
|
+
signed_url(key, verb: 'put')+'&async=true'
|
30
|
+
end
|
31
|
+
|
32
|
+
def internal_download_url
|
33
|
+
generate_private_url(key)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def signed_url(key, verb: nil)
|
39
|
+
query = if verb.nil?
|
40
|
+
''
|
41
|
+
else
|
42
|
+
"?verb=#{verb}"
|
43
|
+
end
|
44
|
+
|
45
|
+
response = @private_http_client.get("/sign#{resource_path(key)}#{query}", @vcap_request_id, { username: @username, password: @password })
|
46
|
+
validate_response_code!([200, 302], response)
|
47
|
+
|
48
|
+
response.tap do |result|
|
49
|
+
result.body = result['location'] if result.code.to_i == 302
|
50
|
+
end
|
51
|
+
|
52
|
+
response.body
|
53
|
+
end
|
54
|
+
|
55
|
+
def generate_private_url(key)
|
56
|
+
path = resource_path(key)
|
57
|
+
|
58
|
+
@private_http_client.head(path, @vcap_request_id).tap do |response|
|
59
|
+
return response['location'] if response.code.to_i == 302
|
60
|
+
end
|
61
|
+
|
62
|
+
File.join(@private_endpoint.to_s, path)
|
63
|
+
end
|
64
|
+
|
65
|
+
# TODO: Refactor the following code to avoid duplicate methods with BitsService::Client
|
66
|
+
|
67
|
+
def validate_response_code!(expected_codes, response)
|
68
|
+
return if Array(expected_codes).include?(response.code.to_i)
|
69
|
+
|
70
|
+
error = {
|
71
|
+
response_code: response.code,
|
72
|
+
response_body: response.body,
|
73
|
+
response: response
|
74
|
+
}.to_json
|
75
|
+
|
76
|
+
logger.error("UnexpectedResponseCode: expected '#{expected_codes}' got #{response.code}")
|
77
|
+
|
78
|
+
fail BlobstoreError.new(error)
|
79
|
+
end
|
80
|
+
|
81
|
+
def resource_path(key)
|
82
|
+
prefix = @resource_type == :buildpack_cache ? 'buildpack_cache/entries/' : @resource_type
|
83
|
+
File.join('/', prefix.to_s, key.to_s)
|
84
|
+
end
|
85
|
+
|
86
|
+
def logger
|
87
|
+
@logger ||= Steno.logger('cc.bits_service_client')
|
15
88
|
end
|
16
89
|
end
|
17
90
|
end
|
@@ -102,30 +102,16 @@ module BitsService
|
|
102
102
|
|
103
103
|
def blob(key)
|
104
104
|
Blob.new(
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
key: key,
|
106
|
+
private_http_client: @private_http_client,
|
107
|
+
private_endpoint: @private_endpoint,
|
108
|
+
vcap_request_id: @vcap_request_id,
|
109
|
+
username: @username,
|
110
|
+
password: @password,
|
111
|
+
resource_type: @resource_type
|
109
112
|
)
|
110
113
|
end
|
111
114
|
|
112
|
-
def signed_url(key, verb: nil)
|
113
|
-
query = if verb.nil?
|
114
|
-
''
|
115
|
-
else
|
116
|
-
"?verb=#{verb}"
|
117
|
-
end
|
118
|
-
|
119
|
-
response = @private_http_client.get("/sign#{resource_path(key)}#{query}", @vcap_request_id, { username: @username, password: @password })
|
120
|
-
validate_response_code!([200, 302], response)
|
121
|
-
|
122
|
-
response.tap do |result|
|
123
|
-
result.body = result['location'] if result.code.to_i == 302
|
124
|
-
end
|
125
|
-
|
126
|
-
response.body
|
127
|
-
end
|
128
|
-
|
129
115
|
def delete_blob(blob)
|
130
116
|
delete(blob.guid)
|
131
117
|
end
|
@@ -175,16 +161,6 @@ module BitsService
|
|
175
161
|
http_client.cert_store = cert_store
|
176
162
|
end
|
177
163
|
|
178
|
-
def generate_private_url(guid)
|
179
|
-
path = resource_path(guid)
|
180
|
-
|
181
|
-
@private_http_client.head(path, @vcap_request_id).tap do |response|
|
182
|
-
return response['location'] if response.code.to_i == 302
|
183
|
-
end
|
184
|
-
|
185
|
-
File.join(@private_endpoint.to_s, path)
|
186
|
-
end
|
187
|
-
|
188
164
|
def validate_response_code!(expected_codes, response)
|
189
165
|
return if Array(expected_codes).include?(response.code.to_i)
|
190
166
|
|
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: 3.
|
4
|
+
version: 3.3.0.pre.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rizwan Reza
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2018-
|
14
|
+
date: 2018-10-29 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -195,9 +195,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
195
|
version: '0'
|
196
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
197
|
requirements:
|
198
|
-
- - "
|
198
|
+
- - ">"
|
199
199
|
- !ruby/object:Gem::Version
|
200
|
-
version:
|
200
|
+
version: 1.3.1
|
201
201
|
requirements: []
|
202
202
|
rubyforge_project:
|
203
203
|
rubygems_version: 2.6.14.1
|