diff --git a/project.clj b/project.clj index 25b939f..3d57c23 100644 --- a/project.clj +++ b/project.clj @@ -2,5 +2,6 @@ :description "Clojure Amazon S3 library." :dependencies [[org.clojure/clojure "1.2.1"] [com.amazonaws/aws-java-sdk "1.4.2.1"] - [clj-time "0.5.0"]] + [clj-time "0.5.0"] + [cheshire "5.3.1"]] :plugins [[codox "0.6.4"]]) diff --git a/src/aws/sdk/s3.clj b/src/aws/sdk/s3.clj index 768de0b..aef644a 100644 --- a/src/aws/sdk/s3.clj +++ b/src/aws/sdk/s3.clj @@ -7,7 +7,8 @@ (:require [clojure.string :as str] [clj-time.core :as t] [clj-time.coerce :as coerce] - [clojure.walk :as walk]) + [clojure.walk :as walk] + [cheshire.core :as json]) (:import com.amazonaws.auth.BasicAWSCredentials com.amazonaws.auth.BasicSessionCredentials com.amazonaws.services.s3.AmazonS3Client @@ -16,6 +17,7 @@ com.amazonaws.HttpMethod com.amazonaws.services.s3.model.AccessControlList com.amazonaws.services.s3.model.Bucket + com.amazonaws.services.s3.model.BucketPolicy com.amazonaws.services.s3.model.Grant com.amazonaws.services.s3.model.CanonicalGrantee com.amazonaws.services.s3.model.CopyObjectResult @@ -533,7 +535,10 @@ Map may also contain the configuration keys :conn-timeout, AccessControlList (to-map [acl] {:grants (set (map to-map (.getGrants acl))) - :owner (to-map (.getOwner acl))})) + :owner (to-map (.getOwner acl))}) + BucketPolicy + (to-map [policy] + (json/parse-string (.getPolicyText policy)))) (defn get-bucket-acl "Get the access control list (ACL) for the supplied bucket. The ACL is a map @@ -548,6 +553,14 @@ Map may also contain the configuration keys :conn-timeout, [cred ^String bucket] (to-map (.getBucketAcl (s3-client cred) bucket))) +(defn get-bucket-policy + "Get the bucket policy for the supplied bucket + For details on the policy data structure please refer + to the AWS documentation: + http://docs.aws.amazon.com/AmazonS3/latest/dev/AccessPolicyLanguage.html" + [cred ^String bucket] + (to-map (.getBucketPolicy (s3-client cred) bucket))) + (defn get-object-acl "Get the access control list (ACL) for the supplied object. See get-bucket-acl for a detailed description of the return value." @@ -611,6 +624,15 @@ Map may also contain the configuration keys :conn-timeout, (update-acl acl funcs) (.setBucketAcl (s3-client cred) bucket acl))) +(defn update-bucket-policy + "Update the policy associated with the specified bucket. + For details on the policy data structure please refer + to the AWS documentation: + http://docs.aws.amazon.com/AmazonS3/latest/dev/AccessPolicyLanguage.html" + [cred ^String name policy] + (let [policy-json (json/generate-string policy)] + (.setBucketPolicy (s3-client cred) name policy-json))) + (defn update-object-acl "Updates the access control list (ACL) for the supplied object using functions that update a set of grants (see update-bucket-acl for more details)."