mirror of
https://github.com/penpot/penpot.git
synced 2025-03-15 01:01:30 -05:00
✨ Improve configuration loading.
Removing unnecesary code.
This commit is contained in:
parent
c1dee0dbf7
commit
b98d8519d4
2 changed files with 37 additions and 63 deletions
|
@ -18,50 +18,20 @@
|
||||||
[mount.core :refer [defstate]]
|
[mount.core :refer [defstate]]
|
||||||
[uxbox.common.exceptions :as ex]))
|
[uxbox.common.exceptions :as ex]))
|
||||||
|
|
||||||
;; --- Configuration Reading & Loading
|
(def defaults
|
||||||
|
{:http-server-port 6060
|
||||||
(defn lookup-env
|
:http-server-cors "http://localhost:3449"
|
||||||
[env key default]
|
:database-uri "postgresql://127.0.0.1/uxbox"
|
||||||
(let [value (get env key ::empty)]
|
:media-directory "resources/public/media"
|
||||||
(if (= value ::empty)
|
:assets-directory "resources/public/static"
|
||||||
default
|
:media-uri "http://localhost:6060/media/"
|
||||||
(try
|
:assets-uri "http://localhost:6060/static/"
|
||||||
(read-string value)
|
:email-reply-to "no-reply@nodomain.com"
|
||||||
(catch Exception e
|
:email-from "no-reply@nodomain.com"
|
||||||
(log/warn (str/istr "can't parse `~{key}` env value"))
|
:smtp-enabled false
|
||||||
default)))))
|
:allow-demo-users true
|
||||||
|
:registration-enabled true
|
||||||
;; --- Configuration Loading & Parsing
|
})
|
||||||
|
|
||||||
(defn read-config
|
|
||||||
[]
|
|
||||||
{:http-server-port (:uxbox-http-server-port env 6060)
|
|
||||||
:http-server-debug (:uxbox-http-server-debug env true)
|
|
||||||
:http-server-cors (:uxbox-http-server-cors env "http://localhost:3449")
|
|
||||||
|
|
||||||
:database-username (:uxbox-database-username env nil)
|
|
||||||
:database-password (:uxbox-database-password env nil)
|
|
||||||
:database-uri (:uxbox-database-uri env "postgresql://127.0.0.1/uxbox")
|
|
||||||
:media-directory (:uxbox-media-directory env "resources/public/media")
|
|
||||||
:media-uri (:uxbox-media-uri env "http://localhost:6060/media/")
|
|
||||||
:assets-directory (:uxbox-assets-directory env "resources/public/static")
|
|
||||||
:assets-uri (:uxbox-assets-uri env "http://localhost:6060/static/")
|
|
||||||
|
|
||||||
:google-api-key (:uxbox-google-api-key env nil)
|
|
||||||
|
|
||||||
:email-reply-to (:uxbox-email-reply-to env "no-reply@nodomain.com")
|
|
||||||
:email-from (:uxbox-email-from env "no-reply@nodomain.com")
|
|
||||||
|
|
||||||
:smtp-host (:uxbox-smtp-host env "smtp")
|
|
||||||
:smtp-port (:uxbox-smtp-port env 25)
|
|
||||||
:smtp-user (:uxbox-smtp-user env nil)
|
|
||||||
:smtp-password (:uxbox-smtp-password env nil)
|
|
||||||
:smtp-tls (:uxbox-smtp-tls env false)
|
|
||||||
:smtp-ssl (:uxbox-smtp-ssl env false)
|
|
||||||
:smtp-enabled (:uxbox-smtp-enabled env false)
|
|
||||||
|
|
||||||
:allow-demo-users (:uxbox-allow-demo-users env true)
|
|
||||||
:registration-enabled (:uxbox-registration-enabled env true)})
|
|
||||||
|
|
||||||
(s/def ::http-server-port ::us/integer)
|
(s/def ::http-server-port ::us/integer)
|
||||||
(s/def ::http-server-debug ::us/boolean)
|
(s/def ::http-server-debug ::us/boolean)
|
||||||
|
@ -83,9 +53,10 @@
|
||||||
(s/def ::smtp-enabled ::us/boolean)
|
(s/def ::smtp-enabled ::us/boolean)
|
||||||
(s/def ::allow-demo-users ::us/boolean)
|
(s/def ::allow-demo-users ::us/boolean)
|
||||||
(s/def ::registration-enabled ::us/boolean)
|
(s/def ::registration-enabled ::us/boolean)
|
||||||
|
(s/def ::debug-humanize-transit ::us/boolean)
|
||||||
|
|
||||||
(s/def ::config
|
(s/def ::config
|
||||||
(s/keys :req-un [::http-server-cors
|
(s/keys :opt-un [::http-server-cors
|
||||||
::http-server-debug
|
::http-server-debug
|
||||||
::http-server-port
|
::http-server-port
|
||||||
::database-username
|
::database-username
|
||||||
|
@ -103,30 +74,32 @@
|
||||||
::smtp-tls
|
::smtp-tls
|
||||||
::smtp-ssl
|
::smtp-ssl
|
||||||
::smtp-enabled
|
::smtp-enabled
|
||||||
|
::debug-humanize-transit
|
||||||
::allow-demo-users
|
::allow-demo-users
|
||||||
::registration-enabled]))
|
::registration-enabled]))
|
||||||
|
|
||||||
|
(defn env->config
|
||||||
|
[env]
|
||||||
|
(reduce-kv (fn [acc k v]
|
||||||
|
(cond-> acc
|
||||||
|
(str/starts-with? (name k) "uxbox-")
|
||||||
|
(assoc (keyword (subs (name k) 6)) v)))
|
||||||
|
{}
|
||||||
|
env))
|
||||||
|
|
||||||
|
(defn read-config
|
||||||
|
[env]
|
||||||
|
(->> (env->config env)
|
||||||
|
(merge defaults)
|
||||||
|
(us/conform ::config)))
|
||||||
|
|
||||||
(defn read-test-config
|
(defn read-test-config
|
||||||
[]
|
[env]
|
||||||
(assoc (read-config)
|
(assoc (read-config env)
|
||||||
:database-uri "postgresql://postgres/uxbox_test"
|
:database-uri "postgresql://postgres/uxbox_test"
|
||||||
:media-directory "/tmp/uxbox/media"
|
:media-directory "/tmp/uxbox/media"
|
||||||
:assets-directory "/tmp/uxbox/static"
|
:assets-directory "/tmp/uxbox/static"
|
||||||
:migrations-verbose false))
|
:migrations-verbose false))
|
||||||
|
|
||||||
(defstate config
|
(defstate config
|
||||||
:start (us/conform ::config (read-config)))
|
:start (read-config env))
|
||||||
|
|
||||||
;; --- Secret Loading & Parsing
|
|
||||||
|
|
||||||
;; (defn- initialize-secret
|
|
||||||
;; [config]
|
|
||||||
;; (let [secret (:secret config)]
|
|
||||||
;; (when-not secret
|
|
||||||
;; (ex/raise :code ::missing-secret-key
|
|
||||||
;; :message "Missing `:secret` key in config."))
|
|
||||||
;; (hash/blake2b-256 secret)))
|
|
||||||
;;
|
|
||||||
;; (defstate secret
|
|
||||||
;; :start (initialize-secret config))
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[mount.core :as mount]
|
[mount.core :as mount]
|
||||||
|
[environ.core :refer [env]]
|
||||||
[datoteka.storages :as st]
|
[datoteka.storages :as st]
|
||||||
[uxbox.services.mutations.profile :as profile]
|
[uxbox.services.mutations.profile :as profile]
|
||||||
[uxbox.services.mutations.projects :as projects]
|
[uxbox.services.mutations.projects :as projects]
|
||||||
|
@ -19,7 +20,7 @@
|
||||||
|
|
||||||
(defn state-init
|
(defn state-init
|
||||||
[next]
|
[next]
|
||||||
(let [config (cfg/read-test-config)]
|
(let [config (cfg/read-test-config env)]
|
||||||
(-> (mount/only #{#'uxbox.config/config
|
(-> (mount/only #{#'uxbox.config/config
|
||||||
#'uxbox.core/system
|
#'uxbox.core/system
|
||||||
#'uxbox.db/pool
|
#'uxbox.db/pool
|
||||||
|
|
Loading…
Add table
Reference in a new issue