Skip to content

Instantly share code, notes, and snippets.

@andrewmcveigh
Created February 12, 2014 15:58
Show Gist options
  • Save andrewmcveigh/8958263 to your computer and use it in GitHub Desktop.
Save andrewmcveigh/8958263 to your computer and use it in GitHub Desktop.
(defplan remote-directory-content []
(let [nv (exec-script "ls /etc/openvpn/keys/*.crt -1")]
(return-value-expr
[nv]
(let [c (:out nv)]
(remove ["ca" "openvpn"]
(-> c
(string/split #"\n")
string/trim
(string/replace #"^/etc/openvpn/keys/" "")
(string/replace #"\.crt$" "")))))))
(defplan gen-openssl-client-certs []
(let [remote-hosts (set (remote-directory-content))
local-hosts #{"client-1"
"client-2"
"client-3"}]
(doseq [host (set/difference remote-hosts local-hosts)]
(exec-script ~(format "openssl ca -revoke /etc/openvpn/keys/%1.crt \\
-keyfile /etc/openvpn/keys/ca.key \\
-cert /etc/openvpn/keys/ca.crt"
host)))
(doseq [host (set/difference local-hosts remote-hosts)]
(remote-file (format "/etc/openvpn/keys/%s.crt" host)
:template "..."
:values {:cn host})
(exec-script ~(format ".......%s" host)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment