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
that didn't have an explicit entry."
[[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
"Returns a map of the JVM proxy settings"

View file

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

View file

@ -56,16 +56,6 @@
(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]
(get auth-map (:url settings)
(first (for [[re? cred] auth-map
@ -73,12 +63,31 @@
(re-find re? (:url settings)))]
cred))))
(defn gpg-auth
"Merge values from ~/.lein/credentials.gpg if settings include :gpg."
(defn- resolve-credential
[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]
(if (some (partial = :gpg) (vals settings))
(merge settings (match-credentials settings (credentials)))
settings))
(reduce (partial resolve-credential settings) (empty settings) settings))
(def profile-auth-warn
(delay (println "Warning: :repository-auth in the :auth profile is deprecated.")

View file

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