-
-
Notifications
You must be signed in to change notification settings - Fork 924
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
Aws sdk #935
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 themulti_json
dependency more difficult.There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💥 jmespath/jmespath.rb#7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats awesome @sferik