mirror of https://github.com/apache/jclouds.git
added new header methods to sign-blob-request, and enabled sign-blob-request-test
This commit is contained in:
parent
226179869a
commit
b7307add04
|
@ -241,26 +241,40 @@ Options can also be specified for extension modules
|
|||
|
||||
(defn sign-blob-request
|
||||
"Get a signed http request for manipulating a blob in another application.
|
||||
ex. curl"
|
||||
ex. curl.
|
||||
The request argument is used to specify charecteristics of the request
|
||||
to be signed. The :method key must be set to one of :get, :delete, and
|
||||
:put. For :put requests, :content-length must be specified. Optionally,
|
||||
:content-type and content-md5 may be given."
|
||||
([container-name path
|
||||
{:keys [method content-type content-length content-md5] :as request}]
|
||||
{:keys [method content-type content-length content-md5
|
||||
content-disposition content-encoding content-language] :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))]}
|
||||
{:keys [method content-type content-length content-md5
|
||||
content-disposition content-encoding content-language]} blobstore]
|
||||
{:pre [(#{:delete :get :put} method)
|
||||
(or content-length (#{:delete :get} method))]}
|
||||
(case method
|
||||
:delete (.signRemoveBlob (.. blobstore getContext getSigner) container-name path)
|
||||
:get (.signGetBlob (.. blobstore getContext getSigner) container-name path)
|
||||
:delete (.signRemoveBlob
|
||||
(.. blobstore getContext getSigner) container-name path)
|
||||
:get (.signGetBlob
|
||||
(.. blobstore getContext getSigner) container-name path)
|
||||
:put (.signPutBlob
|
||||
(.. blobstore getContext getSigner) container-name
|
||||
(doto (.newBlob blobstore path)
|
||||
(.setPayload
|
||||
(doto
|
||||
(PhantomPayload. )
|
||||
(let [payload (PhantomPayload.)
|
||||
metadata (.getContentMetadata payload)]
|
||||
;; TODO look into use of ContentMetadata constructor
|
||||
(.getContentMetadata (.setContentLength (long content-length)))
|
||||
(.getContentMetadata (.setContentType content-type))
|
||||
(.getContentMetadata (.setContentMD5 content-md5)))))))))
|
||||
(doto metadata
|
||||
(.setContentLength (long content-length))
|
||||
(.setContentType content-type)
|
||||
(.setContentMD5 content-md5)
|
||||
(.setContentDisposition content-disposition)
|
||||
(.setContentEncoding content-encoding)
|
||||
(.setContentLanguage content-language))
|
||||
payload)))))))
|
||||
|
||||
(defn get-blob-stream
|
||||
"Get an inputstream from the blob at a given path"
|
||||
|
|
|
@ -109,18 +109,35 @@
|
|||
(download-blob container-name name data-file)))
|
||||
(finally (.delete data-file))))))
|
||||
|
||||
;; this will fail until somebody fixes it!
|
||||
#_
|
||||
(deftest sing-blob-request-test
|
||||
(deftest sign-blob-request-test
|
||||
(testing "delete"
|
||||
(let [request (sign-blob-request "container" "path" {:method :delete})]
|
||||
(is (= "DELETE" (.getMethod request))))
|
||||
(is (= "DELETE" (.getMethod request)))))
|
||||
(testing "get"
|
||||
(let [request (sign-blob-request "container" "path" {:method :get})]
|
||||
(is (= "GET" (.getMethod request))))
|
||||
(is (= "GET" (.getMethod request)))))
|
||||
(testing "put"
|
||||
(let [request (sign-blob-request
|
||||
"container" "path" {:method :put :content-length 10})]
|
||||
(is (= "http://localhost/container/path" (str (.getEndpoint request))))
|
||||
(is (= "PUT" (.getMethod request)))
|
||||
(is (= "10" (get "Content-Length" (.getHeaders request))))
|
||||
(is (= "text/plain" (get "Content-Type" (.getHeaders request))))))
|
||||
(is (= "10" (first (.get (.getHeaders request) "Content-Length"))))
|
||||
(is (nil?
|
||||
(first (.get (.getHeaders request) "Content-Type"))))))
|
||||
(testing "put with headers"
|
||||
(let [request (sign-blob-request
|
||||
"container" "path"
|
||||
{:method :put :content-length 10
|
||||
:content-type "x"
|
||||
:content-language "en"
|
||||
:content-disposition "f"
|
||||
:content-encoding "g"})]
|
||||
(is (= "PUT" (.getMethod request)))
|
||||
(is (= "10" (first (.get (.getHeaders request) "Content-Length"))))
|
||||
(is (= "x" (first (.get (.getHeaders request) "Content-Type"))))
|
||||
(is (= "en" (first (.get (.getHeaders request) "Content-Language"))))
|
||||
(is (= "f" (first (.get (.getHeaders request) "Content-Disposition"))))
|
||||
(is (= "g" (first (.get (.getHeaders request) "Content-Encoding")))))))
|
||||
|
||||
;; TODO: more tests involving blob-specific functions
|
||||
|
||||
|
|
Loading…
Reference in New Issue