Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aws sdk #935

Merged
merged 4 commits into from
Apr 13, 2015
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ gem 'rails', '~> 4.2.1'
gem 'psych', '~> 2.0.12'
gem 'builder'
gem 'dynamic_form'
gem 's3'
gem 'aws-sdk-core'
gem 'gchartrb', require: 'google_chart'
gem 'gravtastic'
gem 'high_voltage'
Expand Down
11 changes: 7 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ GEM
arel (6.0.0)
autoprefixer-rails (4.0.2.2)
execjs
aws-sdk-core (2.0.38)
builder (~> 3.0)
jmespath (~> 1.0)
multi_json (~> 1.0)
bcrypt (3.1.10)
builder (3.2.2)
capistrano (2.15.5)
Expand Down Expand Up @@ -99,6 +103,8 @@ GEM
honeybadger (1.16.7)
json
i18n (0.7.0)
jmespath (1.0.2)
multi_json (~> 1.0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 overall. This dependency ties us tighter to multi_json. I’m okay with it but it will make your project to completely eliminate the multi_json dependency more difficult.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I guess multi_json will stick around for a while still.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats awesome @sferik

jquery-rails (3.1.2)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
Expand Down Expand Up @@ -131,7 +137,6 @@ GEM
paul_revere (1.3)
rails (>= 3.0)
pg (0.18.1)
proxies (0.2.1)
psych (2.0.13)
rack (1.6.0)
rack-test (0.6.3)
Expand Down Expand Up @@ -175,8 +180,6 @@ GEM
netrc (~> 0.7)
rr (1.1.2)
ruby-graphviz (1.0.9)
s3 (0.3.21)
proxies (~> 0.2.0)
sass (3.4.13)
sass-rails (5.0.1)
railties (>= 4.0.0, < 5.0)
Expand Down Expand Up @@ -229,6 +232,7 @@ PLATFORMS

DEPENDENCIES
autoprefixer-rails
aws-sdk-core
builder
capistrano (~> 2.0)
capistrano-notification
Expand Down Expand Up @@ -266,7 +270,6 @@ DEPENDENCIES
redis
rest-client
rr
s3
sass-rails (~> 5.0.0)
shoulda
statsd-instrument (~> 2.0.6)
Expand Down
38 changes: 25 additions & 13 deletions lib/rubygem_fs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ def fs.base_dir
end

def self.s3!(host)
uri = URI(host)
@fs = RubygemFs::S3.new
s3 = @fs.s3(access_key_id: 'k', secret_access_key: 's', proxy: {host: uri.host, port: uri.port})
s3.buckets.build(Gemcutter.config['s3_bucket']).save
s3 = @fs.s3(access_key_id: 'k',
secret_access_key: 's',
endpoint: host,
force_path_style: true,
region: 'us-east-1')
s3.create_bucket(bucket: Gemcutter.config['s3_bucket'])
end

class Local
Expand Down Expand Up @@ -51,29 +54,38 @@ def base_dir

class S3
def store(key, body)
object = bucket.objects.build(key)
object.content = body
object.save
s3.put_object(key: key, body: body, bucket: bucket, acl: 'public-read')
end

def get(key)
if object = bucket.objects.find(key)
object.content
end
s3.get_object(key: key, bucket: bucket).body.read
rescue Aws::S3::Errors::NoSuchKey
nil
end

def remove(key)
if object = bucket.objects.find(key)
object.destroy
s3.delete_object(key: key, bucket: bucket)
end

def restore(key)
begin
s3.get_object(key: key, bucket: bucket);
rescue Aws::S3::Errors::NoSuchKey=> e
version_id = e.context.http_response.headers["x-amz-version-id"]
s3.delete_object(key: key, bucket: bucket, version_id: version_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we're expecting the get to fail every time and raise the exception?

end
end

def bucket
@bucket ||= s3.buckets.find(Gemcutter.config['s3_bucket'])
Gemcutter.config['s3_bucket']
end

def s3(options = nil)
@s3 ||= ::S3::Service.new(options || { access_key_id: ENV['S3_KEY'], secret_access_key: ENV['S3_SECRET'] })
@s3 ||= Aws::S3::Client.new(options ||
{ access_key_id: ENV['S3_KEY'],
secret_access_key: ENV['S3_SECRET'],
region: 'us-east-1',
endpoint: "https://s3.amazonaws.com" })
end
end
end