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

Add bucket policy functions #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"]])
26 changes: 24 additions & 2 deletions src/aws/sdk/s3.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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."
Expand Down Expand Up @@ -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)."
Expand Down