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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74b72025bcaf34acdcce3558a4685553eed135ee
4
- data.tar.gz: 2c1b5e61d064dfc866a2c50d0f699c5d71eff441
3
+ metadata.gz: 7073bd4444bd3db84ea5e8dd7fba708196c1aa01
4
+ data.tar.gz: 355aebf3a4a5a1dd8b36d69e9ec0625a7a0ef539
5
5
  SHA512:
6
- metadata.gz: 5a3c40c2275f65b85ec5bb74fc9081f738e26fa9e9794e8ceb149e94d5cc9d9442c5f08be9648dbf3a97487693283ed4234789ca697050902bd460c0af9edcaf
7
- data.tar.gz: 7b1d461c5d5fc5ce7b1e166205baf7fa62a651bc3c73689732543e2968e5ea174a937510769721b5459bfdd1254ebbce4c772dbf7a1defea01252054b572015d
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 :guid, :public_download_url, :internal_download_url, :public_upload_url
4
+ attr_reader :key
5
5
 
6
- def initialize(guid:, public_download_url:, internal_download_url:, public_upload_url:)
7
- @guid = guid
8
- @public_download_url = public_download_url
9
- @internal_download_url = internal_download_url
10
- @public_upload_url = public_upload_url
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
- guid: key,
106
- public_download_url: signed_url(key),
107
- public_upload_url: signed_url(key, verb: 'put')+'&async=true',
108
- internal_download_url: generate_private_url(key)
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BitsServiceClient
4
- VERSION = '3.2.0'
4
+ VERSION = '3.3.0.pre.1'
5
5
  end
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.2.0
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-08-02 00:00:00.000000000 Z
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: '0'
200
+ version: 1.3.1
201
201
  requirements: []
202
202
  rubyforge_project:
203
203
  rubygems_version: 2.6.14.1