-
Notifications
You must be signed in to change notification settings - Fork 3
/
registration.clj
43 lines (37 loc) · 1.53 KB
/
registration.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
(ns certificaat.acme4j.registration
(:require [certificaat.acme4j.account :as account]
[certificaat.acme4j.session :as session]
[certificaat.util.tentoonstelling :as t]
[certificaat.domain :refer [Certificaat]]
[clojure.tools.logging :as log]
[environ.core :refer [env]])
(:import [org.shredzone.acme4j Registration RegistrationBuilder]
[org.shredzone.acme4j.exception AcmeException AcmeConflictException]))
(defn accept-agreement [reg]
(let [url (.getAgreement reg)]
(t/show-tos "Terms of Service:" "The agreement has been saved to disk. By clicking OK you are accepting the terms.")
(.commit (.setAgreement (.modify reg) url))
(log/info "Agreement accepted")
reg))
(defn create [keypair acme-uri contact]
(let [session (session/create keypair acme-uri)]
(try
(let [builder (-> (RegistrationBuilder.)
(.addContact contact))
reg (.create builder session)]
(log/info "Registered a new user, URI:" (.getLocation reg))
reg)
(catch AcmeConflictException e
(let [reg (Registration/bind session (.getLocation e))]
(log/warn "Account already exists, URI:" (.getLocation reg))
reg))
(catch AcmeException e (log/error (.getMessage e))))))
(defn swap-keys [reg new-keypair]
(.changeKey reg new-keypair))
(defn restore [session uri]
(Registration/bind session uri))
(defn delete [reg]
(.deactivate reg))
(extend-type Registration
Certificaat
(valid? [this] true))