forked from mcohen01/amazonica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glacier.clj
34 lines (30 loc) · 1.08 KB
/
glacier.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(ns amazonica.aws.glacier
(:use [amazonica.core :only (parse-args set-client to-file)]
[robert.hooke :only (add-hook)])
(:import com.amazonaws.services.glacier.AmazonGlacierClient
amazonica.TreeHash
[java.io File BufferedInputStream FileInputStream]))
(set-client AmazonGlacierClient *ns*)
(defn- file-hash->map
[^File file]
{:content-length (.length file)
:checksum (-> file
TreeHash/computeSHA256TreeHash
TreeHash/toHex)
:body (-> file
(FileInputStream.)
(BufferedInputStream.))})
(defn tree-hash
[f cred & args]
(let [arg-map (parse-args cred args)
func (if (contains? arg-map :cred)
(partial f cred)
f)
m (apply hash-map (:args arg-map))
file (to-file (:body m))
mm (merge-with
(fn [_ e] e)
m
(file-hash->map file))]
(apply func (mapcat identity mm))))
(add-hook #'upload-archive #'tree-hash)