Commit 30dac29d authored by Jay Mundrawala's avatar Jay Mundrawala

Merge pull request #534 from chef/jdm/del-uber-s3-publisher

Modify s3 publisher to use aws-sdk instead of uber-s3
parents b0ac938d 358fe535
......@@ -51,6 +51,10 @@ module Omnibus
desc: 'The accessibility of the uploaded packages',
enum: %w(public private),
default: 'private'
method_option :region,
type: :string,
desc: 'The region in which the bucket is located',
default: 'us-east-1'
desc 's3 BUCKET PATTERN', 'Publish to an S3 bucket'
def s3(bucket, pattern)
options[:bucket] = bucket
......
......@@ -14,11 +14,14 @@
# limitations under the License.
#
require 'omnibus/s3_helpers'
module Omnibus
class S3Publisher < Publisher
include S3Helpers
def publish(&block)
log.info(log_key) { 'Starting S3 publisher' }
safe_require('uber-s3')
packages.each do |package|
# Make sure the package is good to go!
......@@ -27,16 +30,13 @@ module Omnibus
# Upload the metadata first
log.debug(log_key) { "Uploading '#{package.metadata.name}'" }
client.store(key_for(package, package.metadata.name), package.metadata.to_json,
access: access_policy,
)
store_object(key_for(package, package.metadata.name), package.metadata.to_json,
nil, access_policy)
# Upload the actual package
log.info(log_key) { "Uploading '#{package.name}'" }
client.store(key_for(package, package.name), package.content,
access: access_policy,
content_md5: package.metadata[:md5],
)
store_object(key_for(package, package.name), package.content,
package.metadata[:md5], access_policy)
# If a block was given, "yield" the package to the caller
block.call(package) if block
......@@ -45,18 +45,13 @@ module Omnibus
private
#
# The actual S3 client object to communicate with the S3 API.
#
# @return [UberS3]
#
def client
@client ||= UberS3.new(
access_key: Config.publish_s3_access_key,
def s3_configuration
{
region: @options[:region],
access_key_id: Config.publish_s3_access_key,
secret_access_key: Config.publish_s3_secret_key,
bucket: @options[:bucket],
adaper: :net_http,
)
bucket_name: @options[:bucket],
}
end
#
......@@ -85,14 +80,14 @@ module Omnibus
# initializer option. Any access control that is not the strict string
# +"public"+ is assumed to be private.
#
# @return [Symbol]
# the UberS3-ready access policy
# @return [String]
# the access policy
#
def access_policy
if @options[:acl].to_s == 'public'
:public_read
'public-read'
else
:private
'private'
end
end
end
......
......@@ -109,8 +109,10 @@ module Omnibus
# @return [String]
#
def to_base64_digest(content_md5)
md5_digest = content_md5.unpack('a2'*16).collect {|i| i.hex.chr }.join
Base64.encode64(md5_digest).strip
if content_md5
md5_digest = content_md5.unpack('a2'*16).collect {|i| i.hex.chr }.join
Base64.encode64(md5_digest).strip
end
end
end
end
......
......@@ -27,7 +27,6 @@ Gem::Specification.new do |gem|
gem.add_dependency 'mixlib-versioning'
gem.add_dependency 'ohai', '~> 8.0'
gem.add_dependency 'ruby-progressbar', '~> 1.7'
gem.add_dependency 'uber-s3', '~> 0.2.4'
gem.add_dependency 'aws-sdk', '~> 2'
gem.add_dependency 'thor', '~> 0.18'
......
......@@ -30,11 +30,12 @@ module Omnibus
let(:packages) { [package] }
let(:client) { double('UberS3', store: nil) }
let(:client) { double('Aws::S3::Resource') }
before do
allow(package).to receive(:metadata).and_return(metadata)
allow(subject).to receive(:client).and_return(client)
allow(subject).to receive(:store_object)
end
subject { described_class.new(path) }
......@@ -48,21 +49,22 @@ module Omnibus
end
it 'uploads the metadata' do
expect(client).to receive(:store).with(
expect(subject).to receive(:store_object).with(
'ubuntu/14.04/x86_64/chef.deb/chef.deb.metadata.json',
package.metadata.to_json,
access: :private,
nil,
'private',
).once
subject.publish
end
it 'uploads the package' do
expect(client).to receive(:store).with(
expect(subject).to receive(:store_object).with(
'ubuntu/14.04/x86_64/chef.deb/chef.deb',
package.content,
access: :private,
content_md5: package.metadata[:md5],
package.metadata[:md5],
'private'
).once
subject.publish
......@@ -72,10 +74,11 @@ module Omnibus
subject { described_class.new(path, acl: 'public') }
it 'sets the access control to public_read' do
expect(client).to receive(:store).with(
expect(subject).to receive(:store_object).with(
'ubuntu/14.04/x86_64/chef.deb/chef.deb.metadata.json',
package.metadata.to_json,
access: :public_read,
nil,
'public-read',
).once
subject.publish
......@@ -86,10 +89,11 @@ module Omnibus
subject { described_class.new(path, acl: 'baconbits') }
it 'sets the access control to private' do
expect(client).to receive(:store).with(
expect(subject).to receive(:store_object).with(
'ubuntu/14.04/x86_64/chef.deb/chef.deb.metadata.json',
package.metadata.to_json,
access: :private,
nil,
'private',
).once
subject.publish
......
......@@ -23,6 +23,10 @@ module Omnibus
it 'turns "c3b5247592ce694f7097873aa07d66fe" into "w7UkdZLOaU9wl4c6oH1m/g=="' do
expect(to_base64_digest("c3b5247592ce694f7097873aa07d66fe")).to eql('w7UkdZLOaU9wl4c6oH1m/g==')
end
it 'allows a nil input without error' do
expect(to_base64_digest(nil)).to be_nil
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment