Created
March 20, 2013 16:30
-
-
Save amitsaxena/5206087 to your computer and use it in GitHub Desktop.
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
Ruby aws-sdk has poor documentation, and I wasn't able to locate it as well. Below is a function that I have created to check whether a file has read permission or not. Modify it as per your needs: | |
def check_if_public_read(object) | |
object.acl.grants.each do |grant| | |
begin | |
if(grant.grantee.uri == "http://acs.amazonaws.com/groups/global/AllUsers") | |
return true if ([:read, :full_control].include?(grant.permission.name)) | |
end | |
rescue | |
end | |
end | |
return false | |
end | |
where object is any S3 Object: | |
AWS.config( | |
:access_key_id => "access key", | |
:secret_access_key => "secret key" | |
) | |
s3 = AWS::S3.new | |
file = s3.buckets["my_bucket"].objects["path/to/file.png"] | |
check_if_public_read(file) => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment