Replace :env values in :repositories with lookups from environment.

Needed for unattended builds.
This commit is contained in:
Phil Hagelberg 2012-06-01 17:26:16 -07:00
parent 2a089a131b
commit 674b4d52ae
3 changed files with 22 additions and 3 deletions

View file

@ -77,7 +77,8 @@
that didn't have an explicit entry." that didn't have an explicit entry."
[[id {:keys [url] :as repo}]] [[id {:keys [url] :as repo}]]
(let [repo-creds (or (user/credentials) (let [repo-creds (or (user/credentials)
(-> (user/profiles) :auth :repository-auth))] (-> (user/profiles) :auth :repository-auth))
repo (user/env-auth repo)]
(when (-> (user/profiles) :auth :repository-auth) (when (-> (user/profiles) :auth :repository-auth)
(println "Warning: :repository-auth in the :auth profile is deprecated.") (println "Warning: :repository-auth in the :auth profile is deprecated.")
(println "Please use ~/.lein/credentials.clj.gpg instead.")) (println "Please use ~/.lein/credentials.clj.gpg instead."))

View file

@ -1,6 +1,7 @@
(ns leiningen.core.user (ns leiningen.core.user
"Functions exposing user-level configuration." "Functions exposing user-level configuration."
(:require [clojure.java.io :as io] (:require [clojure.java.io :as io]
[clojure.string :as str]
[clojure.java.shell :as shell])) [clojure.java.shell :as shell]))
(defn leiningen-home (defn leiningen-home
@ -21,12 +22,25 @@
(catch Exception e (catch Exception e
(.printStackTrace e)))))))) (.printStackTrace e))))))))
(defn profiles [] (defn profiles
"Load profiles.clj from your Leiningen home if present."
[]
(let [profiles-file (io/file (leiningen-home) "profiles.clj")] (let [profiles-file (io/file (leiningen-home) "profiles.clj")]
(if (.exists profiles-file) (if (.exists profiles-file)
(read-string (slurp profiles-file))))) (read-string (slurp profiles-file)))))
(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 credentials-fn (defn credentials-fn
"Decrypt map from credentials.clj.gpg in Leiningen home if present."
([] (let [cred-file (io/file (leiningen-home) "credentials.clj.gpg")] ([] (let [cred-file (io/file (leiningen-home) "credentials.clj.gpg")]
(when (.exists cred-file) (when (.exists cred-file)
(credentials-fn cred-file)))) (credentials-fn cred-file))))

View file

@ -147,7 +147,11 @@
;; {:username "milgrim" ;; {:username "milgrim"
;; :password "locative.1"}}}} ;; :password "locative.1"}}}}
"snapshots" "http://blueant.com/archiva/snapshots" "snapshots" "http://blueant.com/archiva/snapshots"
"releases" "http://blueant.com/archiva/internal"} "releases" {:url "http://blueant.com/archiva/internal"
;; Using :env as a value here will cause an
;; enironment variable to be used based on
;; the key; in this case LEIN_PASSWORD.
:username "milgrim" :password :env}}
;; You can set :update and :checksum policies here to have them ;; You can set :update and :checksum policies here to have them
;; apply for all :repositories. Usually you will not set :update ;; apply for all :repositories. Usually you will not set :update
;; directly but apply the "update" profile instead. ;; directly but apply the "update" profile instead.