-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #311 from Deraen/gpg-binary
Use gpg binary for signing and reading credentials from encrypted file
- Loading branch information
Showing
9 changed files
with
211 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
(ns boot.gpg | ||
(:require | ||
[clojure.java.io :as io] | ||
[clojure.java.shell :as shell] | ||
[boot.pod :as pod] | ||
[boot.util :as util]) | ||
(:import [java.io StringReader File])) | ||
|
||
(defn ^{:boot/from :technomancy/leiningen} gpg-program | ||
"Lookup the gpg program to use, defaulting to 'gpg'" | ||
[] | ||
(or (System/getenv "BOOT_GPG") "gpg")) | ||
|
||
(defn- ^{:boot/from :technomancy/leiningen} get-english-env [] | ||
"Returns environment variables as a map with clojure keywords and LANGUAGE set to 'en'" | ||
(let [env (System/getenv) | ||
keywords (map #(keyword %) (keys env))] | ||
(merge (zipmap keywords (vals env)) | ||
{:LANGUAGE "en"}))) | ||
|
||
(defn ^{:boot/from :technomancy/leiningen} gpg | ||
"Shells out to (gpg-program) with the given arguments" | ||
[& args] | ||
(let [env (get-english-env)] | ||
(try | ||
(shell/with-sh-env env | ||
(apply shell/sh (gpg-program) args)) | ||
(catch java.io.IOException e | ||
{:exit 1 :err (.getMessage e)})))) | ||
|
||
(defn ^{:boot/from :technomancy/leiningen} signing-args | ||
"Produce GPG arguments for signing a file." | ||
[file opts] | ||
(let [key-spec (if-let [key (:gpg-key opts)] | ||
["--default-key" key]) | ||
passphrase-spec (if-let [pass (:gpg-passphrase opts)] | ||
["--passphrase-fd" "0"]) | ||
passphrase-in-spec (if-let [pass (:gpg-passphrase opts)] | ||
[:in (StringReader. pass)])] | ||
`["--yes" "-ab" ~@key-spec ~@passphrase-spec "--" ~file ~@passphrase-in-spec])) | ||
|
||
(defn ^{:boot/from :technomancy/leiningen} sign | ||
"Create a detached signature and return the signature file name." | ||
[file opts] | ||
(let [{:keys [err exit]} (apply gpg (signing-args file opts))] | ||
(when-not (zero? exit) | ||
(util/fail (str "Could not sign " file "\n" err | ||
"\n\nIf you don't expect people to need to verify the " | ||
"authorship of your jar, don't set :gpg-sign option of push task to true.\n"))) | ||
(str file ".asc"))) | ||
|
||
(defn sign-jar | ||
[outdir jarfile opts] | ||
(shell/with-sh-dir | ||
outdir | ||
(let [jarname (.getName jarfile) | ||
jarout (io/file outdir (str jarname ".asc")) | ||
pomfile (doto (File/createTempFile "pom" ".xml") | ||
(.deleteOnExit) | ||
(spit (pod/pom-xml jarfile))) | ||
pomout (io/file outdir (.replaceAll jarname "\\.jar$" ".pom.asc")) | ||
sign-it #(sign (.getPath %) opts)] | ||
(spit pomout (sign-it pomfile)) | ||
(spit jarout (sign-it jarfile)) | ||
{[:extension "jar.asc"] (.getPath jarout) | ||
[:extension "pom.asc"] (.getPath pomout)}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.