mirror of https://github.com/apache/jclouds.git
Added sign-blob-request method, and some tests (broken)
This commit is contained in:
parent
f068a06354
commit
754a511ec2
|
@ -44,11 +44,11 @@ See http://code.google.com/p/jclouds for details."
|
|||
AsyncBlobStore BlobStore BlobStoreContext BlobStoreContextFactory
|
||||
domain.BlobMetadata domain.StorageMetadata domain.Blob
|
||||
options.ListContainerOptions]
|
||||
[org.jclouds.io Payloads]
|
||||
[org.jclouds.io.payloads PhantomPayload]
|
||||
[java.util Arrays]
|
||||
org.jclouds.io.Payloads
|
||||
org.jclouds.io.payloads.PhantomPayload
|
||||
java.util.Arrays
|
||||
[java.security DigestOutputStream MessageDigest]
|
||||
[com.google.common.collect ImmutableSet]))
|
||||
com.google.common.collect.ImmutableSet))
|
||||
|
||||
(try
|
||||
(require '[clojure.contrib.io :as io])
|
||||
|
@ -240,12 +240,12 @@ Options can also be specified for extension modules
|
|||
(.getBlob blobstore container-name path)))
|
||||
|
||||
(defn sign-get-blob-request
|
||||
"Get a signed http request for a blob, so that you can retrieve it
|
||||
"Get a signed http request for a blob, so that you can retrieve it
|
||||
in another application. ex. curl"
|
||||
([container-name path]
|
||||
(sign-get-blob-request container-name path *blobstore*))
|
||||
([container-name path #^BlobStore blobstore]
|
||||
(.signGetBlob (.getContext blobstore) container-name path)))
|
||||
(.signGetBlob (.. blobstore getContext getSigner) container-name path)))
|
||||
|
||||
(defn sign-remove-blob-request
|
||||
"Get a signed http request for deleting a blob in another application.
|
||||
|
@ -253,7 +253,7 @@ in another application. ex. curl"
|
|||
([container-name path]
|
||||
(sign-remove-blob-request container-name path *blobstore*))
|
||||
([container-name path #^BlobStore blobstore]
|
||||
(.signRemoveBlob (.getContext blobstore) container-name path)))
|
||||
(.signRemoveBlob (.. blobstore getContext getSigner) container-name path)))
|
||||
|
||||
(defn sign-put-blob-request
|
||||
"Get a signed http request for uploading a blob in another application.
|
||||
|
@ -261,13 +261,32 @@ in another application. ex. curl"
|
|||
([container-name path content-type size]
|
||||
(sign-put-blob-request container-name path content-type size *blobstore*))
|
||||
([container-name path content-type size #^BlobStore blobstore]
|
||||
(.signPutBlob (.getContext blobstore) container-name
|
||||
(.signPutBlob (.. blobstore getContext getSigner) container-name
|
||||
(doto (.newBlob blobstore path)
|
||||
(.setPayload (doto
|
||||
;; until we pass content md5
|
||||
(PhantomPayload. size nil)
|
||||
(.setContentType content-type)))))))
|
||||
|
||||
(defn sign-blob-request
|
||||
"Get a signed http request for manipulating a blob in another application.
|
||||
ex. curl"
|
||||
([container-name path
|
||||
{:keys [method content-type content-length content-md5] :as request}]
|
||||
(sign-blob-request container-name path request *blobstore*))
|
||||
([container-name path
|
||||
{:keys [method content-type content-length content-md5]} blobstore]
|
||||
{:pre [(or content-length (#{:delete :get} method))]}
|
||||
(case method
|
||||
:delete (sign-remove-blob-request container-name path blobstore)
|
||||
:get (sign-get-blob-request container-name path blobstore)
|
||||
:put (.signPutBlob
|
||||
(.. blobstore getContext getSigner) container-name
|
||||
(doto (.newBlob blobstore path)
|
||||
(.setPayload
|
||||
(doto (PhantomPayload. content-length content-md5)
|
||||
(.setContentType content-type))))))))
|
||||
|
||||
(defn get-blob-stream
|
||||
"Get an inputstream from the blob at a given path"
|
||||
([container-name path]
|
||||
|
|
|
@ -109,6 +109,25 @@
|
|||
(download-blob container-name name data-file)))
|
||||
(finally (.delete data-file))))))
|
||||
|
||||
;; this will fail until transient provider handles signing
|
||||
(deftest sing-put-blob-request-test
|
||||
(let [request (sign-put-blob-request "container" "path" "text/plain" 10)]
|
||||
(is (= "PUT" (.getMethod request)))
|
||||
(is (= "10" (get "Content-Length" (.getHeaders request))))
|
||||
(is (= "text/plain" (get "Content-Type" (.getHeaders request))))))
|
||||
|
||||
;; this will fail until transient provider handles signing
|
||||
(deftest sing-blob-request-test
|
||||
(let [request (sign-blob-request "container" "path" {:method :delete})]
|
||||
(is (= "DELETE" (.getMethod request))))
|
||||
(let [request (sign-blob-request "container" "path" {:method :get})]
|
||||
(is (= "GET" (.getMethod request))))
|
||||
(let [request (sign-blob-request
|
||||
"container" "path" {:method :put :content-length 10})]
|
||||
(is (= "PUT" (.getMethod request)))
|
||||
(is (= "10" (get "Content-Length" (.getHeaders request))))
|
||||
(is (= "text/plain" (get "Content-Type" (.getHeaders request))))))
|
||||
|
||||
;; TODO: more tests involving blob-specific functions
|
||||
|
||||
(deftest corruption-hunt
|
||||
|
|
Loading…
Reference in New Issue