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
|
(defn sign-blob-request
|
||||||
"Get a signed http request for manipulating a blob in another application.
|
"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
|
([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*))
|
(sign-blob-request container-name path request *blobstore*))
|
||||||
([container-name path
|
([container-name path
|
||||||
{:keys [method content-type content-length content-md5]} blobstore]
|
{:keys [method content-type content-length content-md5
|
||||||
{:pre [(or content-length (#{:delete :get} method))]}
|
content-disposition content-encoding content-language]} blobstore]
|
||||||
|
{:pre [(#{:delete :get :put} method)
|
||||||
|
(or content-length (#{:delete :get} method))]}
|
||||||
(case method
|
(case method
|
||||||
:delete (.signRemoveBlob (.. blobstore getContext getSigner) container-name path)
|
:delete (.signRemoveBlob
|
||||||
:get (.signGetBlob (.. blobstore getContext getSigner) container-name path)
|
(.. blobstore getContext getSigner) container-name path)
|
||||||
|
:get (.signGetBlob
|
||||||
|
(.. blobstore getContext getSigner) container-name path)
|
||||||
:put (.signPutBlob
|
:put (.signPutBlob
|
||||||
(.. blobstore getContext getSigner) container-name
|
(.. blobstore getContext getSigner) container-name
|
||||||
(doto (.newBlob blobstore path)
|
(doto (.newBlob blobstore path)
|
||||||
(.setPayload
|
(.setPayload
|
||||||
(doto
|
(let [payload (PhantomPayload.)
|
||||||
(PhantomPayload. )
|
metadata (.getContentMetadata payload)]
|
||||||
;; TODO look into use of ContentMetadata constructor
|
;; TODO look into use of ContentMetadata constructor
|
||||||
(.getContentMetadata (.setContentLength (long content-length)))
|
(doto metadata
|
||||||
(.getContentMetadata (.setContentType content-type))
|
(.setContentLength (long content-length))
|
||||||
(.getContentMetadata (.setContentMD5 content-md5)))))))))
|
(.setContentType content-type)
|
||||||
|
(.setContentMD5 content-md5)
|
||||||
|
(.setContentDisposition content-disposition)
|
||||||
|
(.setContentEncoding content-encoding)
|
||||||
|
(.setContentLanguage content-language))
|
||||||
|
payload)))))))
|
||||||
|
|
||||||
(defn get-blob-stream
|
(defn get-blob-stream
|
||||||
"Get an inputstream from the blob at a given path"
|
"Get an inputstream from the blob at a given path"
|
||||||
|
|
|
@ -109,18 +109,35 @@
|
||||||
(download-blob container-name name data-file)))
|
(download-blob container-name name data-file)))
|
||||||
(finally (.delete data-file))))))
|
(finally (.delete data-file))))))
|
||||||
|
|
||||||
;; this will fail until somebody fixes it!
|
(deftest sign-blob-request-test
|
||||||
#_
|
(testing "delete"
|
||||||
(deftest sing-blob-request-test
|
|
||||||
(let [request (sign-blob-request "container" "path" {:method :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})]
|
(let [request (sign-blob-request "container" "path" {:method :get})]
|
||||||
(is (= "GET" (.getMethod request))))
|
(is (= "GET" (.getMethod request)))))
|
||||||
|
(testing "put"
|
||||||
(let [request (sign-blob-request
|
(let [request (sign-blob-request
|
||||||
"container" "path" {:method :put :content-length 10})]
|
"container" "path" {:method :put :content-length 10})]
|
||||||
|
(is (= "http://localhost/container/path" (str (.getEndpoint request))))
|
||||||
(is (= "PUT" (.getMethod request)))
|
(is (= "PUT" (.getMethod request)))
|
||||||
(is (= "10" (get "Content-Length" (.getHeaders request))))
|
(is (= "10" (first (.get (.getHeaders request) "Content-Length"))))
|
||||||
(is (= "text/plain" (get "Content-Type" (.getHeaders request))))))
|
(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
|
;; TODO: more tests involving blob-specific functions
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue