bits_service_client 3.1.0 → 3.2.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/client.rb +31 -28
- 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: 44e82c59bafd111f31c71bee2ad4394f96114289
|
4
|
+
data.tar.gz: 345531e83292d27d85d041c7cd9f9ccbbcecf06f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94d69cc843e90f3a66fe03181d93a6454f3ec35549efbc32ed441febd0d07dbb9ef6976f01c3c850684a3992db7c89ff9c816d1b50f65c1c2df455e597314279
|
7
|
+
data.tar.gz: fbe522713d8379704f999fe0b2ca80cbef68d7bd417b3c0c3e7c4336bf1e94cbdb3b9537a708e2993d558f8e92ce0ebf5d1719c8f7d2d6495b255433089ef1e2
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'active_support/inflector'
|
3
3
|
require 'bits_service_client/logging_http_client'
|
4
|
+
require 'tmpdir'
|
5
|
+
require "open3"
|
4
6
|
|
5
7
|
module BitsService
|
6
8
|
class Client
|
@@ -33,29 +35,39 @@ module BitsService
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def cp_to_blobstore(source_path, destination_key, resources: nil)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
if source_path.to_s.empty?
|
39
|
+
file = Tempfile.new(['empty', '.zip'])
|
40
|
+
source_path = file.path
|
41
|
+
file.close!
|
42
|
+
Dir.mktmpdir do |dir|
|
43
|
+
output, error, status = Open3.capture3(%(/usr/bin/zip #{source_path} #{dir}))
|
44
|
+
unless status.success?
|
45
|
+
logger.error("Could not create a zip with no contents.\n STDOUT: \"#{output}\"\n STDERR: \"#{error}\"")
|
46
|
+
raise Errors::Error.new('Could not create a zip with no contents')
|
47
|
+
end
|
42
48
|
end
|
49
|
+
end
|
43
50
|
|
44
|
-
|
45
|
-
validate_response_code!(201, response)
|
46
|
-
if response.body == nil
|
47
|
-
logger.error("UnexpectedMissingBody: expected body with json payload. Got empty body.")
|
51
|
+
body = { :"#{@resource_type.to_s.singularize}" => UploadIO.new(source_path, 'application/octet-stream') }
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
response_body: response.body,
|
52
|
-
response: response
|
53
|
-
}.to_json)
|
54
|
-
end
|
55
|
-
shas = JSON.parse(response.body, symbolize_names: true)
|
56
|
-
validate_keys_present!([:sha1, :sha256], shas, response)
|
57
|
-
return shas
|
53
|
+
if resources != nil
|
54
|
+
body[:resources] = resources.to_json
|
58
55
|
end
|
56
|
+
|
57
|
+
response = @private_http_client.do_request(Net::HTTP::Put::Multipart.new(resource_path(destination_key), body), @vcap_request_id)
|
58
|
+
validate_response_code!(201, response)
|
59
|
+
if response.body == nil
|
60
|
+
logger.error("UnexpectedMissingBody: expected body with json payload. Got empty body.")
|
61
|
+
|
62
|
+
fail BlobstoreError.new({
|
63
|
+
response_code: response.code,
|
64
|
+
response_body: response.body,
|
65
|
+
response: response
|
66
|
+
}.to_json)
|
67
|
+
end
|
68
|
+
shas = JSON.parse(response.body, symbolize_names: true)
|
69
|
+
validate_keys_present!([:sha1, :sha256], shas, response)
|
70
|
+
return shas
|
59
71
|
end
|
60
72
|
|
61
73
|
def download_from_blobstore(source_key, destination_path, mode: nil)
|
@@ -204,15 +216,6 @@ module BitsService
|
|
204
216
|
File.join('/', prefix.to_s, guid.to_s)
|
205
217
|
end
|
206
218
|
|
207
|
-
def with_file_attachment!(file_path, filename, &block)
|
208
|
-
raise Errors::FileDoesNotExist.new("Could not find file: #{file_path}") unless File.exist?(file_path)
|
209
|
-
|
210
|
-
File.open(file_path) do |file|
|
211
|
-
attached_file = UploadIO.new(file, 'application/octet-stream', filename)
|
212
|
-
yield attached_file
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
219
|
def endpoint(http_client)
|
217
220
|
http_client == @public_http_client ? @public_endpoint : @private_endpoint
|
218
221
|
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.
|
4
|
+
version: 3.2.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-08-02 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
|