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

constraints in copy-object, get-object; process put-object result #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
46 changes: 40 additions & 6 deletions src/aws/sdk/s3.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
com.amazonaws.services.s3.model.Bucket
com.amazonaws.services.s3.model.Grant
com.amazonaws.services.s3.model.CanonicalGrantee
com.amazonaws.services.s3.model.CopyObjectRequest
com.amazonaws.services.s3.model.CopyObjectResult
com.amazonaws.services.s3.model.EmailAddressGrantee
com.amazonaws.services.s3.model.GetObjectRequest
Expand All @@ -35,6 +36,7 @@
com.amazonaws.services.s3.model.ObjectListing
com.amazonaws.services.s3.model.Permission
com.amazonaws.services.s3.model.PutObjectRequest
com.amazonaws.services.s3.model.PutObjectResult
com.amazonaws.services.s3.model.S3Object
com.amazonaws.services.s3.model.S3ObjectSummary
com.amazonaws.services.s3.model.S3VersionSummary
Expand Down Expand Up @@ -214,7 +216,7 @@
(->PutObjectRequest bucket key))]
(when permissions
(.setAccessControlList req (create-acl permissions)))
(.putObject (s3-client cred) req)))
(to-map (.putObject (s3-client cred) req))))

(defn- initiate-multipart-upload
[cred bucket key]
Expand Down Expand Up @@ -343,7 +345,15 @@
:expiration-time (.getExpirationTime result)
:expiration-time-rule-id (.getExpirationTimeRuleId result)
:last-modified-date (.getLastModifiedDate result)
:server-side-encryption (.getServerSideEncryption result)}))
:server-side-encryption (.getServerSideEncryption result)})
PutObjectResult
(to-map [result]
{:versionId (.getVersionId result)
:etag (.getETag result)
:server-side-encryption (.getServerSideEncryption result)
:expiration-time (.getExpirationTime result)
:expiration-time-rule-id (.getExpirationTimeRuleId result)
:content-md5 (.getContentMd5 result)}))

(defn get-object
"Get an object from an S3 bucket. The object is returned as a map with the
Expand All @@ -362,9 +372,22 @@
If these rules are not followed, the client can run out of resources by
allocating too many open, but unused, HTTP connections."
([cred ^String bucket ^String key]
(to-map (.getObject (s3-client cred) bucket key)))
([cred ^String bucket ^String key ^String version-id]
(to-map (.getObject (s3-client cred) (GetObjectRequest. bucket key version-id)))))
(to-map (.getObject (s3-client cred) bucket key)))
; ([cred ^String bucket ^String key ^String version-id]
; (to-map (.getObject (s3-client cred) (GetObjectRequest. bucket key version-id)))))
([cred ^String bucket ^String key {:keys [version-id matching-etags nonmatching-etags modified-since unmodified-since] :as opts}]
(let [req (GetObjectRequest. bucket key)]
(when version-id
(.setVersionId req version-id))
(when matching-etags
(.setMatchingETagConstraints req matching-etags))
(when nonmatching-etags
(.setNonmatchingETagConstraints req nonmatching-etags))
(when modified-since
(.setModifiedSinceConstraint req modified-since))
(when unmodified-since
(.setUnmodifiedSinceConstraint req unmodified-since))
(to-map (.getObject (s3-client cred) req)))))

(defn- map->GetObjectMetadataRequest
"Create a ListObjectsRequest instance from a map of values."
Expand Down Expand Up @@ -464,7 +487,18 @@
([cred bucket src-key dest-key]
(copy-object cred bucket src-key bucket dest-key))
([cred src-bucket src-key dest-bucket dest-key]
(to-map (.copyObject (s3-client cred) src-bucket src-key dest-bucket dest-key))))
(to-map (.copyObject (s3-client cred) src-bucket src-key dest-bucket dest-key)))
([cred src-bucket src-key dest-bucket dest-key {:keys [matching-etags nonmatching-etags modified-since unmodified-since] :as opts}]
(let [req (CopyObjectRequest. src-bucket src-key dest-bucket dest-key)]
(when matching-etags
(.setMatchingETagConstraints req matching-etags))
(when nonmatching-etags
(.setNonmatchingETagConstraints req nonmatching-etags))
(when modified-since
(.setModifiedSinceConstraint req modified-since))
(when unmodified-since
(.setUnmodifiedSinceConstraint req unmodified-since))
(to-map (.copyObject (s3-client cred) req)))))

(defn- map->ListVersionsRequest
"Create a ListVersionsRequest instance from a map of values."
Expand Down