Created
April 1, 2011 21:03
-
-
Save davidsantiago/898851 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;; Instead of sign-blob-request | |
(defn sign-get | |
"Get a signed http GET request for manipulating a blob in another | |
application, Ex. curl." | |
[container-name name ^Blobstore blobstore] | |
(.signGetBlob (.. blobstore getContext getSigner) container-name name)) | |
(defn sign-put | |
"Get a signed http PUT request for manipulating a blob in another | |
application, Ex. curl. A Blob with at least the name and content-length | |
must be given." | |
[container-name ^Blob blob ^Blobstore blobstore] | |
(.signPutBlob (.. blobstore getContext getSigner) | |
container-name | |
blob)) | |
(defn sign-delete | |
"Get a signed http DELETE request for manipulating a blob in another | |
application, Ex. curl." | |
[container-name name ^Blobstore blobstore] | |
(.signRemoveBlob (.. blobstore getContext getSigner) container-name name)) | |
;; Instead of blob | |
(defn blob2 | |
"Create a new blob with the specified payload and options." | |
([^String name option-map] | |
(blob2 name option-map *blobstore*)) | |
([^String name | |
{:keys [payload content-type content-length content-md5 calculate-md5 | |
content-disposition content-encoding content-language metadata]} | |
^BlobStore blobstore] | |
{:pre [(not (and content-md5 calculate-md5)) | |
(not (and (nil? payload) calculate-md5))]} | |
(let [blob-builder (if payload | |
(.payload (.blobBuilder blobstore name) payload) | |
(.forSigning (.blobBuilder blobstore name))) | |
blob-builder (if content-length ;; Special case, arg is prim. | |
(.contentLength blob-builder content-length) | |
blob-builder) | |
blob-builder (if calculate-md5 ;; Only do calculateMD5 OR contentMD5. | |
(.calculateMD5 blob-builder) | |
(if content-md5 | |
(.contentMD5 blob-builder content-md5) | |
blob-builder))] | |
(doto blob-builder | |
(.contentType content-type) | |
(.contentDisposition content-disposition) | |
(.contentEncoding content-encoding) | |
(.contentLanguage content-language) | |
(.userMetadata metadata)) | |
(.build blob-builder)))) | |
;; The damn failing test from blobstore_test.clj | |
(deftest blob2-test | |
(let [a-blob (blob2 "test-name" {:payload "test-payload" | |
:calculate-MD5 true})] | |
(println (.getPayload a-blob)) | |
(is (= (.getContentMD5 (.getContentMetadata (.getPayload a-blob))) | |
; (.. a-blob (getPayload) (getContentMetadata) (getContentMD5)) | |
(CryptoStreams/md5 (.getBytes "test-payload")))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment