Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
Switch to aws-sdk v2
Browse files Browse the repository at this point in the history
  • Loading branch information
eagletmt committed Nov 2, 2014
1 parent 0c6bdae commit 79de167
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion akabei.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "libarchive"
spec.add_dependency "safe_yaml"
spec.add_dependency "thor"
spec.add_development_dependency "aws-sdk"
spec.add_development_dependency "aws-sdk-resources"
spec.add_development_dependency "bundler"
spec.add_development_dependency "coveralls"
spec.add_development_dependency "rake"
Expand Down
4 changes: 2 additions & 2 deletions lib/akabei/omakase/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def init(name)

if options[:s3]
begin
require 'aws-sdk'
require 'aws-sdk-resources'
rescue LoadError => e
say("WARNING: You don't have aws-sdk installed. Disable S3 repository.", :yellow)
say("WARNING: You don't have aws-sdk-resources installed. Disable S3 repository.", :yellow)
options[:s3] = false
end
end
Expand Down
17 changes: 10 additions & 7 deletions lib/akabei/omakase/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module Omakase
class S3
def initialize(aws_config, shell)
if aws_config
require 'aws-sdk'
@bucket = AWS::S3.new(
require 'aws-sdk-resources'
@bucket = Aws::S3::Resource.new(
access_key_id: aws_config['access_key_id'],
secret_access_key: aws_config['secret_access_key'],
region: aws_config['region'],
).buckets[aws_config['bucket']]
).bucket(aws_config['bucket'])
@write_options = aws_config['write_options']
@shell = shell
end
Expand All @@ -34,9 +34,7 @@ def download_repository(config, arch)
def get(path)
@shell.say("Download #{path}", :blue)
path.open('wb') do |f|
@bucket.objects[path.to_s].read do |chunk|
f.write(chunk)
end
@bucket.object(path.to_s, target: f)
end
rescue AWS::S3::Errors::NoSuchKey
@shell.say("S3: #{path} not found", :red)
Expand Down Expand Up @@ -64,7 +62,12 @@ def upload_repository(config, arch, packages)

def put(path, mime_type)
@shell.say("Upload #{path}", :green)
@bucket.objects[path.to_s].write(path, @write_options.merge(content_type: mime_type))
path.open do |f|
@bucket.object(path.to_s).put(@write_options.merge(
body: f,
content_type: mime_type,
))
end
end
end
end
Expand Down

0 comments on commit 79de167

Please sign in to comment.