Skip to content

Commit

Permalink
Read boot-env using io/resource and io/reader
Browse files Browse the repository at this point in the history
Previously used io/file with io/resource, which is not safe when the resource is not a file
  • Loading branch information
larkery authored Apr 17, 2018
1 parent a20fac7 commit 60c58c5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions environ/src/environ/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@
(map (fn [[k v]] [(keywordize k) v]))
(into {})))

(defn- read-env-reader [r]
(when-let [reader (io/reader r)]
(into {}
(for [[k v] (edn/read-string (slurp r))
[(santitize-key k) (sanitize-val k v)]))))

(defn- read-env-file [f]
(if-let [env-file (io/file f)]
(if (.exists env-file)
(into {} (for [[k v] (edn/read-string (slurp env-file))]
[(sanitize-key k) (sanitize-val k v)])))))
(read-env-reader env-file))))

(defn- read-env-resource [r]
(if-let [resource (io/resource r)]
(read-env-reader resource)))

(defn- warn-on-overwrite [ms]
(doseq [[k kvs] (group-by key (apply concat ms))
:let [vs (map val kvs)]
Expand All @@ -51,6 +60,6 @@
env
(merge-env
(read-env-file ".lein-env")
(read-env-file (io/resource ".boot-env"))
(read-env-resource ".boot-env")
(read-system-env)
(read-system-props)))

0 comments on commit 60c58c5

Please sign in to comment.