Add support for:

* namespaced keywords to control lookup of credentials in env vars
* using a vector to define a number of credential sources to be checked in series

(gh-768)
This commit is contained in:
Chas Emerick 2012-09-05 07:59:28 -04:00
parent 856207caf0
commit 268d723796
4 changed files with 28 additions and 18 deletions

View file

@ -81,7 +81,7 @@
would be applied to all repositories with URLs matching the regex key would be applied to all repositories with URLs matching the regex key
that didn't have an explicit entry." that didn't have an explicit entry."
[[id repo]] [[id repo]]
[id (-> repo user/profile-auth user/gpg-auth user/env-auth)]) [id (-> repo user/profile-auth user/resolve-credentials)])
(defn get-proxy-settings (defn get-proxy-settings
"Returns a map of the JVM proxy settings" "Returns a map of the JVM proxy settings"

View file

@ -43,6 +43,7 @@
;; TODO: point to releases-only before 2.0 is out ;; TODO: point to releases-only before 2.0 is out
["clojars" {:url "https://clojars.org/repo/"}]] ["clojars" {:url "https://clojars.org/repo/"}]]
:deploy-repositories [["clojars" {:url "https://clojars.org/repo/" :deploy-repositories [["clojars" {:url "https://clojars.org/repo/"
:username :gpg
:password :gpg}]] :password :gpg}]]
:jar-exclusions [#"^\."] :jar-exclusions [#"^\."]
:jvm-opts ["-XX:+TieredCompilation"] :jvm-opts ["-XX:+TieredCompilation"]

View file

@ -56,16 +56,6 @@
(def credentials (memoize credentials-fn)) (def credentials (memoize credentials-fn))
(defn- env-auth-key [settings [k v]]
(assoc settings k (if (= :env v)
(System/getenv (str "LEIN_" (str/upper-case (name k))))
v)))
(defn env-auth
"Replace all :env values in map with LEIN_key environment variables."
[settings]
(reduce env-auth-key {} settings))
(defn- match-credentials [settings auth-map] (defn- match-credentials [settings auth-map]
(get auth-map (:url settings) (get auth-map (:url settings)
(first (for [[re? cred] auth-map (first (for [[re? cred] auth-map
@ -73,12 +63,31 @@
(re-find re? (:url settings)))] (re-find re? (:url settings)))]
cred)))) cred))))
(defn gpg-auth (defn- resolve-credential
"Merge values from ~/.lein/credentials.gpg if settings include :gpg." [source-settings result [k v]]
(letfn [(resolve [v]
(cond
(= :env v)
(System/getenv (str "LEIN_" (str/upper-case (name k))))
(and (keyword? v) (= "env" (namespace v)))
(System/getenv (str/upper-case (name v)))
(= :gpg v)
(get (match-credentials source-settings (credentials)) k)
(coll? v)
(->> (map resolve v)
(remove nil?)
first)
:else v))]
(assoc result k (resolve v))))
(defn resolve-credentials
"Applies credentials from environment or ~/.lein/credentials.clj.gpg
as they are specified and available."
[settings] [settings]
(if (some (partial = :gpg) (vals settings)) (reduce (partial resolve-credential settings) (empty settings) settings))
(merge settings (match-credentials settings (credentials)))
settings))
(def profile-auth-warn (def profile-auth-warn
(delay (println "Warning: :repository-auth in the :auth profile is deprecated.") (delay (println "Warning: :repository-auth in the :auth profile is deprecated.")

View file

@ -92,9 +92,9 @@
:username "flynn" :password "flotilla"}] :username "flynn" :password "flotilla"}]
["sonatype" {:url "https://oss.sonatype.org/"}] ["sonatype" {:url "https://oss.sonatype.org/"}]
["internal" {:password "reindur" :username "milgrim" ["internal" {:password "reindur" :username "milgrim"
:url "https://sekrit.info/repo" :creds :gpg}]] :url "https://sekrit.info/repo"}]]
(map add-repo-auth (map add-repo-auth
[["clojars" {:url "http://clojars.org/repo"}] [["clojars" {:url "http://clojars.org/repo"}]
["sonatype" {:url "https://oss.sonatype.org/"}] ["sonatype" {:url "https://oss.sonatype.org/"}]
["internal" {:url "https://sekrit.info/repo" ["internal" {:url "https://sekrit.info/repo"
:creds :gpg}]]))))) :username :gpg :password :gpg}]])))))