Merge pull request #62 from raboof/allow-reading-secrets-from-separate-file

Allow reading credentials from separate file
master
Dmitri Sotnikov 4 years ago committed by GitHub
commit 3de9416ed6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,15 +20,25 @@
(js/process.exit 1)) (js/process.exit 1))
(defn find-config [config-location] (defn find-config [config-location]
(let [config (or config-location (or config-location
(-> js/process .-env .-MASTODON_BOT_CONFIG) (-> js/process .-env .-MASTODON_BOT_CONFIG)
"config.edn")] "config.edn"))
(defn read-edn [config]
(if config
(if (fs/existsSync config) (if (fs/existsSync config)
config ;(edn/read-string (fs/readFileSync #js {:encoding "UTF-8"} config))
(exit-with-error (str "failed to read config: " config))))) (edn/read-string (fs/readFileSync config "UTF-8"))
(exit-with-error (str "config file does not exist: " config)))
nil))
(defn load-config [config-location] (defn load-credentials-config []
(read-edn (-> js/process .-env .-MASTODON_BOT_CREDENTIALS)))
(defn load-main-config [config-location]
(-> config-location (-> config-location
(find-config) (find-config)
(fs/readFileSync #js {:encoding "UTF-8"}) (read-edn)))
edn/read-string))
(defn load-config [config-location]
(merge (load-main-config config-location) (load-credentials-config)))