Created
February 12, 2014 15:58
-
-
Save andrewmcveigh/8958263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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