This repository was archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.clj
57 lines (52 loc) · 2.79 KB
/
main.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(ns main
(:require [babashka.pods :as pods]
[clojure.edn :as edn]
[babashka.curl :as curl]
[clojure.string :as string]))
(def x (pods/load-pod 'atomisthq/tools.docker "0.1.0"))
(require '[pod.atomisthq.docker :as docker])
(defn do-transaction [all-hashes transactions m token digest]
(let [tx-data (->> @all-hashes
(filter (fn [{:keys [path]}] (if path (string/includes? path ".exe"))))
(mapcat (fn [{:keys [hash diff-id]}]
(let [blob-digest (get m diff-id)]
(if blob-digest
[{:schema/entity blob-digest
:schema/entity-type :docker.image/blob
:docker.image.blob/digest blob-digest}
{:schema/entity-type :docker.image.blob/file
:docker.image.blob.file/sha256 hash
:docker.image.blob.file/blob blob-digest}]
(do
(println diff-id "not in " m)
[])))))
(into []))]
(try
(println "tx-data" tx-data)
(println
(curl/post transactions
{:body (pr-str {:transactions [{:data tx-data}]})
:headers {"Authorization" (format "Bearer %s" token)
"Content-Type" "application/edn"}}))
(println
(curl/post transactions
{:body (pr-str {:transactions [{:data [{:docker.image/digest digest
:schema/entity-type :docker/image
:malware.status/indexed :malware.status.indexed/complete}]}]})
:headers {"Authorization" (format "Bearer %s" token)
"Content-Type" "application/edn"}}))
(System/exit 0)
(catch Throwable t
(println "error " t)
(System/exit 1)))))
(defn transact-hashes [{:keys [image digest m transactions token]}]
(println image digest transactions)
(let [all-hashes (atom [])]
(docker/hashes image (fn [event]
(if (= "done" (:status event))
(do-transaction all-hashes transactions m token digest)
(swap! all-hashes conj (edn/read-string event)))))))
#_(let [[image digest m transaction-url token] *command-line-args*]
(transact-hashes {:image image :digest digest :diff-id->digest (edn/read-string m) :transaction-url transaction-url :token token}))
(transact-hashes (edn/read-string (slurp "/Users/slim/atmhq/malware/test1.edn")))
(while true (Thread/sleep 5000))