Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
hubble/src/clj/hubble/env.clj
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
51 lines (41 sloc)
1.51 KB
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
(ns hubble.env | |
(:require [mount.core :refer [defstate]] | |
[cprop.core :refer [load-config]] | |
[cprop.source :refer [from-system-props | |
from-env]] | |
[envoy.core :as envoy] | |
[clojure.tools.logging :as log] | |
[hubble.tools.vault :as vault])) | |
(defn to-consul-path | |
"consul config to 'host/kv-prefix/path'" | |
[cconf] | |
(->> cconf | |
vals | |
(apply str))) | |
(defn with-creds [conf at token] | |
(-> (vault/merge-config conf {:at at | |
:vhost [:hubble :vault :url] | |
:token token}) | |
(get-in at))) | |
(defn create-config [] | |
(let [conf (load-config :merge [(from-system-props) | |
(from-env)])] | |
(->> (conf :consul) | |
to-consul-path | |
(envoy/merge-with-consul conf)))) | |
(defstate config :start (create-config)) | |
;; playground | |
(defn init-consul | |
"load config to consul without consul props and creds | |
this is done once (usually before the app is deployed), | |
and here is mostly for demo / repro purposes" | |
[] | |
(let [{:keys [] {host :host | |
kv :kv-prefix} :consul :as conf} (load-config) | |
cpath (str host kv)] | |
(log/info "initializing Consul at" cpath) | |
(as-> (dissoc conf :consul) $ | |
(update-in $ [:hubble :log] dissoc :auth-token) | |
(update-in $ [:hubble :log :hazelcast] dissoc :group-name | |
:group-password) | |
(envoy/map->consul cpath $)))) |