File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11(ns certificaat.acme4j.order
22 (:require [certificaat.domain :refer [Certificaat]]
3- [certificaat.utils :refer [load-url]]
3+ [certificaat.utils :refer [load-url exit]]
4+ [clojure.core.async :as a :refer [<! <!! >!! chan thread go-loop]]
45 [clojure.tools.logging :as log]
56 [clojure.java.io :as io])
67 (:import [org.shredzone.acme4j Order]
78 [org.shredzone.acme4j Status]
8- [org.shredzone.acme4j.exception AcmeProtocolException]
9+ [org.shredzone.acme4j.exception AcmeException AcmeRetryAfterException AcmeServerException AcmeProtocolException]
910 [java.net URL]))
1011
1112
3637 (= Status/INVALID (.getStatus this)))
3738 (marshal [this path]
3839 (spit path (.getLocation this))))
40+
41+ (defn ready-to-finalize? [order]
42+ (let [c (chan )]
43+ (a/thread (loop [y 1
44+ ms nil ]
45+ (<!! (a/timeout (or ms 15000 )))
46+ (log/debug " Retrieving order status, attempt" y ms)
47+ (cond
48+ (d/ready? order) (do (log/debug " Order is ready" )
49+ true )
50+ (d/invalid? order) (exit 1 " Order is invalid" )
51+ (> y 10 ) (exit 1 " Too many attempts " )
52+ :else (recur (inc y) (try
53+ (.update order)
54+ (catch AcmeRetryAfterException e
55+ (log/error (.getMessage e))
56+ (.getRetryAfter e)))))))))
Original file line number Diff line number Diff line change 122122 csrb (certificate/prepare domain-keypair domains (:organisation options))
123123 csr (.getEncoded csrb)]
124124 (certificate/persist-certificate-request csrb (str config-dir domain " /cert.csr" ))
125- (.execute order csr)))
125+ (when ( <!! ( order/ready-to-finalize? order)) ( .execute order csr) )))
126126
127127(defn certificate-location [{{{path :path enabled :enabled } :copy-to-path } :plugins config-dir :config-dir domain :domain :as options}]
128128 (if enabled path (str config-dir domain " /" )))
Original file line number Diff line number Diff line change 205205 csrb (certificate/prepare domain-keypair domains (:organisation options))
206206 csr (.getEncoded csrb)]
207207 (certificate/persist-certificate-request csrb (str (:config-dir options) (:domain options) " /cert.csr" ))
208- (.execute order csr)
208+ (when ( <!! ( order/ready-to-finalize? order)) ( .execute order csr) )
209209 (.update order)
210210 (is (= true (valid? order)))))
211211
You can’t perform that action at this time.
0 commit comments