Compare commits

..

No commits in common. "8f8f0d643a24ed7450addfe70a39361040f6ceb4" and "e9011773e7f53d0b52c84047c717d057a8461f90" have entirely different histories.

4 changed files with 0 additions and 97 deletions

View file

@ -1,51 +0,0 @@
(ns dda.build.gopass
(:require [orchestra.core :refer [defn-spec]]
[clojure.spec.test.alpha :as st]
[cheshire.core :refer [parse-string generate-string]]
[dda.build.devops :as d]
[dda.build.gopass.domain :as domain]
[dda.build.c4k.domain :as c4k-d]
[dda.build.infrastructure :as i]))
(def default
(merge d/default {:c4k-auth-filename "c4k-auth.yaml"}))
(defn-spec run-gopass-command! string?
[devops ::d/devops
entry ::domain/gopass-entry]
(let [config (merge default devops)
c (domain/gopass-show-command entry)]
(i/execute-output! c config)))
(defn-spec resolve-gopass! ::resolved-config
"Resolves gopass values inside a map of key names and entries
entries may either contain only a path
{:path \"test/path\"}
or a path and a field
{:path \"test/path\" :field \"field\"}
"
[devops ::d/devops
config ::domain/config]
(update-vals config #(run-gopass-command! devops %)))
(defn-spec insert-gopass! nil?
"Inserts values from the resolved auth config into the c4k auth
Default: c4k-auth.yaml
can be changed by adding another value for ':c4k-auth-filename'
"
[devops ::d/devops
resolved-config ::resolved-config]
(let [config (merge default devops)
default-c4k-auth (parse-string (slurp (c4k-d/auth-path config))
(fn [k] (keyword (.toLowerCase k))))]
(->> default-c4k-auth
(merge resolved-config)
(generate-string)
(spit (domain/config-path config)))))
(st/instrument `run-gopass-command!)
(st/instrument `resolve-gopass!)
(st/instrument `insert-gopass!)

View file

@ -1,21 +0,0 @@
(ns dda.build.gopass.domain
(:require [clojure.spec.alpha :as s]
[orchestra.core :refer [defn-spec]]))
(s/def ::path string?)
(s/def ::field string?)
(s/def ::gopass-entry (s/keys :req-un [::path]
:opt-un [::field]))
(s/def ::config (s/map-of keyword? ::gopass-entry))
(s/def ::resolved-config (s/map-of keyword? string?))
(s/def ::gopass-command (s/coll-of string?))
(s/def ::gopass-commands (s/coll-of ::gopass-command))
(defn-spec gopass-show-command ::gopass-command
[entry ::gopass-entry]
(let [{:keys [path field] :or {field nil}} entry]
(if (nil? field)
["gopass" "show" "-y" "-o" path]
["gopass" "show" "-y" "-o" path field])))

View file

@ -11,15 +11,3 @@
(println command))
(when-not dry-run
(apply t/shell command))))
(defn-spec execute-output! string?
[command seq?
devops ::d/devops]
(let [{:keys [dry-run debug]} devops]
(when debug
(println command))
(when-not dry-run
(->> command
(t/shell {:out :string})
:out
clojure.string/trim))))

View file

@ -1,13 +0,0 @@
(ns dda.build.gopass.domain-test
(:require
[clojure.test :refer [deftest is]]
[clojure.spec.test.alpha :as st]
[dda.build.gopass.domain :as cut]))
(st/instrument `cut/gopass-show-command)
(deftest should-show-gopass-command
(is (= ["gopass" "show" "-y" "-o" "test/pass"]
(cut/gopass-show-command {:path "test/pass"})))
(is (= ["gopass" "show" "-y" "-o" "test/pass" "field"]
(cut/gopass-show-command {:path "test/pass" :field "field"}))))