Last active
February 14, 2020 15:57
-
-
Save caioaao/d8aefd60b110d92ab89b7aef28e34aa4 to your computer and use it in GitHub Desktop.
buddy keys aero tagged literals
This file contains hidden or 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
(ns common.config | |
(:require [aero.alpha.core :as aero.alpha] | |
[aero.core :as aero] | |
[clojure.java.io :as io] | |
[buddy.core.keys :as buddy.keys])) | |
(defn- rewrap [tl] | |
(fn [v] (tagged-literal (:tag tl) v))) | |
(defmethod aero.alpha/eval-tagged-literal 'priv-key | |
[{:keys [form] :as tl} opts env ks] | |
(let [{conf-m ::aero/value | |
m-incomplete? ::aero/incomplete? | |
:as m-expansion} | |
(aero.alpha/expand-scalar-repeatedly form opts env ks)] | |
(if m-incomplete? | |
(update m-expansion ::aero/value rewrap) | |
(if (map? conf-m) | |
(let [{::aero/keys [value incomplete?] :as expansion} | |
(aero.alpha/expand-coll conf-m opts env ks)] | |
(if incomplete? | |
(update expansion ::aero/value rewrap) | |
(-> (buddy.keys/private-key (:path value) (:passphrase value)) | |
(aero.alpha/expand-scalar opts env ks)))) | |
(-> (buddy.keys/private-key conf-m) | |
(aero.alpha/expand-scalar opts env ks)))))) | |
(defmethod aero.alpha/eval-tagged-literal 'pub-key | |
[{:keys [form] :as tl} opts env ks] | |
(let [{::aero/keys [value incomplete?] | |
:as expansion} | |
(aero.alpha/expand-scalar-repeatedly form opts env ks)] | |
(if incomplete? | |
(update expansion ::aero/value rewrap) | |
(-> (buddy.keys/public-key value) | |
(aero.alpha/expand-scalar opts env ks))))) | |
(defmethod aero.alpha/eval-tagged-literal 'io/resource | |
[{:keys [form] :as tl} opts env ks] | |
(-> (io/resource form) | |
(aero.alpha/expand-scalar opts env ks))) | |
(defn read-config | |
([profile] | |
(read-config profile (io/resource "config.edn"))) | |
([profile config-path] | |
(aero/read-config config-path {:profile profile | |
:resolver aero/root-resolver}))) |
This file contains hidden or 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
{:jwt-priv-key #priv-key #profile {:dev #io/resource "jwt_key.pem" | |
:default {:path #join [#env HOME "/.keys/jwt_key.pem"] | |
:passphrase #ref [:secrets :jwt-priv-key :passphrase]}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment