-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.clj
51 lines (37 loc) · 1.36 KB
/
config.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(ns freecoin-lib.config
(:require [environ.core :as env]))
(def env-vars #{:port :host :base-url :secure :debug
:client-id :client-secret :rpc-config})
(defn create-config []
(select-keys env/env env-vars))
(defn get-env
"Like a normal 'get' except it also ensures the key is in the env-vars set"
([config-m key]
(get config-m (env-vars key)))
([config-m key default]
(get config-m (env-vars key) default)))
(defn port [config-m]
(Integer. (get-env config-m :port "8000")))
(defn host [config-m]
(get-env config-m :host "localhost"))
(defn base-url [config-m]
(get-env config-m :base-url "http://localhost:8000"))
(defn client-id [config-m]
(get-env config-m :client-id))
(defn client-secret [config-m]
(get-env config-m :client-secret))
(defn rpc-config [config-m]
(get-env config-m :rpc-config))
(defn cookie-secret [config-m]
(get-env config-m :cookie-secret "encryptthecookie"))
(defn debug [config-m]
(get-env config-m :debug true))
(defn- get-docker-mongo-uri [config-m]
(when-let [mongo-ip (get-env config-m :mongo-port-27017-tcp-addr)]
(format "mongodb://%s:27017/freecoin" mongo-ip)))
(defn mongo-uri [config-m]
(or (get-docker-mongo-uri config-m)
(get-env config-m :mongo-uri)
"mongodb://localhost:27017/freecoin"))
(defn secure? [config-m]
(not (= "false" (get-env config-m :secure "true"))))