36 lines
1.1 KiB
Common Lisp
36 lines
1.1 KiB
Common Lisp
;;;; cl-scopes/config
|
|
|
|
;;;; Utilities for configuration of scopes services.
|
|
|
|
(defpackage :scopes/config
|
|
(:use :common-lisp)
|
|
(:export #:base
|
|
#:env-data #:env-keys #:env-prefix #:env-path))
|
|
|
|
(in-package :scopes/config)
|
|
|
|
(defclass base ()
|
|
((env-keys :reader env-keys
|
|
:initform nil
|
|
:allocation :class)
|
|
(env-prefix :reader env-prefix
|
|
:initarg :env-prefix
|
|
:initform "SCOPES_")
|
|
(env-path :reader env-path
|
|
:initarg :env-path
|
|
:initform nil)
|
|
(env-data :accessor env-data
|
|
:initform (make-hash-table))))
|
|
|
|
(defmethod initialize-instance :after ((cfg base) &key &allow-other-keys)
|
|
(let* ((data (env-data cfg))
|
|
(prefix (env-prefix cfg))
|
|
(ep (env-path cfg))
|
|
(dotenv-data (if ep (dotenv:read-env ep))))
|
|
(dolist (sl (env-keys cfg))
|
|
(let* ((key (str:concat prefix (string sl)))
|
|
(env-val (uiop:getenv key))
|
|
(dotenv-val (if dotenv-data (gethash key dotenv-data))))
|
|
(if env-val
|
|
(setf (gethash sl data) env-val)
|
|
(setf (gethash sl data) dotenv-val))))))
|