blobstore_client 1.3215.4.0 → 1.3232.0

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: 30b0f1640de3d9c8079f33f6c7f52d7892b27b24
4
- data.tar.gz: 600739dc68d5676bf9995c1048b96d60ec26a345
3
+ metadata.gz: a06a98a43ef258f0524a1499be7e8b0debcbaa98
4
+ data.tar.gz: eef981f753d46a86b6f2b4d97f268e84536c1825
5
5
  SHA512:
6
- metadata.gz: 384fc07ad7e960890338dbe0f9fbfe6e5352234c5783f9c22b17bdd94256a82bfe8870a0a1189e63b8ace1fdfa1d45d0f932b3f3661d9dab004eb13e52ada148
7
- data.tar.gz: 1685b461e46162ad8d87834f26e7cd96b056099b3136ecc840620d547297370b53998cedb01bd2ec8a4e3a2dbadb500f9ec485180e2051f308432c35d3109eee
6
+ metadata.gz: 2e7ac4e932a04a0b00ebd603fda7cd4faa3f8e68434470acbdab809c56bbbba5f8e37877f20fdd4383b13002c4b85518836e2c598ad593c45d8ec60c0c1c527e
7
+ data.tar.gz: 563a9ef2d01c7255513d3098450ee02d9bc9d0ee8d957da13a6af8421efe87ffdd2c6d7d86bda03104cf4d1161b22c30b0882d25ade946fc323dee4d1f077c36
@@ -11,3 +11,4 @@ Bosh::Blobstore.autoload(:S3BlobstoreClient, 'blobstore_client/s3_blobstore_clie
11
11
  Bosh::Blobstore.autoload(:SimpleBlobstoreClient, 'blobstore_client/simple_blobstore_client')
12
12
  Bosh::Blobstore.autoload(:LocalClient, 'blobstore_client/local_client')
13
13
  Bosh::Blobstore.autoload(:DavBlobstoreClient, 'blobstore_client/dav_blobstore_client')
14
+ Bosh::Blobstore.autoload(:S3cliBlobstoreClient, 'blobstore_client/s3cli_blobstore_client')
@@ -1,7 +1,7 @@
1
1
  module Bosh
2
2
  module Blobstore
3
3
  class Client
4
- PROVIDER_NAMES = %w[dav simple s3 local]
4
+ PROVIDER_NAMES = %w[dav simple s3 local s3cli]
5
5
 
6
6
  def self.create(blobstore_provider, options = {})
7
7
  unless PROVIDER_NAMES.include?(blobstore_provider)
@@ -0,0 +1,133 @@
1
+ require 'openssl'
2
+ require 'digest/sha1'
3
+ require 'base64'
4
+ require 'securerandom'
5
+ require 'open3'
6
+ require 'json'
7
+
8
+ module Bosh
9
+ module Blobstore
10
+ class S3cliBlobstoreClient < BaseClient
11
+
12
+ # Blobstore client for S3, using s3cli Go version
13
+ # @param [Hash] options S3connection options
14
+ # @option options [Symbol] bucket_name
15
+ # key that is applied before the object is sent to S3
16
+ # @option options [Symbol, optional] access_key_id
17
+ # @option options [Symbol, optional] secret_access_key
18
+ # @option options [Symbol] s3cli_path
19
+ # path to s3cli binary
20
+ # @option options [Symbol, optional] s3cli_config_path
21
+ # path to store configuration files
22
+ # @note If access_key_id and secret_access_key are not present, the
23
+ # blobstore client operates in read only mode
24
+ def initialize(options)
25
+ super(options)
26
+
27
+ @s3cli_path = @options.fetch(:s3cli_path)
28
+ unless Kernel.system("#{@s3cli_path} --v", out: "/dev/null", err: "/dev/null")
29
+ raise BlobstoreError, "Cannot find s3cli executable. Please specify s3cli_path parameter"
30
+ end
31
+
32
+ @s3cli_options = {
33
+ bucket_name: @options[:bucket_name],
34
+ use_ssl: @options.fetch(:use_ssl, true),
35
+ host: @options[:host],
36
+ port: @options[:port],
37
+ region: @options[:region],
38
+ ssl_verify_peer: @options.fetch(:ssl_verify_peer, true),
39
+ credentials_source: @options.fetch(:credentials_source, 'none'),
40
+ access_key_id: @options[:access_key_id],
41
+ secret_access_key: @options[:secret_access_key],
42
+ signature_version: @options[:signature_version]
43
+ }
44
+
45
+ @s3cli_options.reject! {|k,v| v.nil?}
46
+
47
+ if @options[:access_key_id].nil? &&
48
+ @options[:secret_access_key].nil?
49
+ @options[:credentials_source] = 'none'
50
+ end
51
+
52
+ @config_file = write_config_file(@options.fetch(:s3cli_config_path, nil))
53
+ end
54
+
55
+ # @param [File] file file to store in S3
56
+ def create_file(object_id, file)
57
+ object_id ||= generate_object_id
58
+ # in Ruby 1.8 File doesn't respond to :path
59
+ path = file.respond_to?(:path) ? file.path : file
60
+
61
+ store_in_s3(path, full_oid_path(object_id))
62
+
63
+ object_id
64
+ end
65
+
66
+ # @param [String] object_id object id to retrieve
67
+ # @param [File] file file to store the retrived object in
68
+ def get_file(object_id, file)
69
+ begin
70
+ out, err, status = Open3.capture3("#{@s3cli_path} -c #{@config_file} get #{object_id} #{file.path}")
71
+ rescue Exception => e
72
+ raise BlobstoreError, e.inspect
73
+ end
74
+ raise BlobstoreError, "Failed to download S3 object, code #{status.exitstatus}, output: '#{out}', error: '#{err}'" unless status.success?
75
+ end
76
+
77
+ # @param [String] object_id object id to delete
78
+ def delete_object(object_id)
79
+ begin
80
+ out, err, status = Open3.capture3("#{@s3cli_path} -c #{@config_file} delete #{object_id}")
81
+ rescue Exception => e
82
+ raise BlobstoreError, e.inspect
83
+ end
84
+ raise BlobstoreError, "Failed to delete S3 object, code #{status.exitstatus}, output: '#{out}', error: '#{err}'" unless status.success?
85
+ end
86
+
87
+ def object_exists?(object_id)
88
+ begin
89
+ out, err, status = Open3.capture3("#{@s3cli_path} -c #{@config_file} exists #{object_id}")
90
+ if status.exitstatus == 0
91
+ return true
92
+ end
93
+ if status.exitstatus == 3
94
+ return false
95
+ end
96
+ rescue Exception => e
97
+ raise BlobstoreError, e.inspect
98
+ end
99
+ raise BlobstoreError, "Failed to check existence of S3 object, code #{status.exitstatus}, output: '#{out}', error: '#{err}'" unless status.success?
100
+ end
101
+
102
+ protected
103
+
104
+ # @param [String] path path to file which will be stored in S3
105
+ # @param [String] oid object id
106
+ # @return [void]
107
+ def store_in_s3(path, oid)
108
+ begin
109
+ out, err, status = Open3.capture3("#{@s3cli_path} -c #{@config_file} put #{path} #{oid}")
110
+ rescue Exception => e
111
+ raise BlobstoreError, e.inspect
112
+ end
113
+ raise BlobstoreError, "Failed to create S3 object, code #{status.exitstatus}, output: '#{out}', error: '#{err}'" unless status.success?
114
+ end
115
+
116
+ def full_oid_path(object_id)
117
+ @options[:folder] ? @options[:folder] + '/' + object_id : object_id
118
+ end
119
+
120
+ def write_config_file(config_file_dir = nil)
121
+ config_file_dir = Dir::tmpdir unless config_file_dir
122
+ Dir.mkdir(config_file_dir) unless File.exists?(config_file_dir)
123
+ random_name = "s3_blobstore_config-#{SecureRandom.uuid}"
124
+ config_file = File.join(config_file_dir, random_name)
125
+ config_data = JSON.dump(@s3cli_options)
126
+
127
+ File.write(config_file, config_data)
128
+ config_file
129
+ end
130
+
131
+ end
132
+ end
133
+ end
@@ -1,7 +1,7 @@
1
1
  module Bosh
2
2
  module Blobstore
3
3
  class Client
4
- VERSION = '1.3215.4.0'
4
+ VERSION = '1.3232.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blobstore_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3215.4.0
4
+ version: 1.3232.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-14 00:00:00.000000000 Z
11
+ date: 2016-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-resources
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.3215.4.0
61
+ version: 1.3232.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.3215.4.0
68
+ version: 1.3232.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -155,6 +155,7 @@ files:
155
155
  - lib/blobstore_client/null_blobstore_client.rb
156
156
  - lib/blobstore_client/retryable_blobstore_client.rb
157
157
  - lib/blobstore_client/s3_blobstore_client.rb
158
+ - lib/blobstore_client/s3cli_blobstore_client.rb
158
159
  - lib/blobstore_client/sha1_verifiable_blobstore_client.rb
159
160
  - lib/blobstore_client/simple_blobstore_client.rb
160
161
  - lib/blobstore_client/version.rb