about summary refs log tree commit diff
path: root/web/panettone/src
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-07-21T23·36-0400
committerglittershark <grfn@gws.fyi>2020-07-23T22·09+0000
commit974c2e05af96ca2681239e41b1281cdb0d22347f (patch)
treef570de6981edbd2b9f64bb37d8d0e7ef5d75fed3 /web/panettone/src
parent9a85694b8616f2e10f19440f4db9017d44dfae18 (diff)
feat(web/panettone): Read config from env r/1438
Read the port and data directory from environment variables, in
preparation for deploying as a systemd unit to Whitby

Change-Id: I066dced7b7926b6bdc77132d13a4da6c886b20e8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1338
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'web/panettone/src')
-rw-r--r--web/panettone/src/panettone.lisp34
1 files changed, 23 insertions, 11 deletions
diff --git a/web/panettone/src/panettone.lisp b/web/panettone/src/panettone.lisp
index f42a449b00ae..16ab7cd969d6 100644
--- a/web/panettone/src/panettone.lisp
+++ b/web/panettone/src/panettone.lisp
@@ -2,6 +2,7 @@
   (:use :cl :klatre :easy-routes)
   (:import-from :defclass-std :defclass/std)
   (:import-from :alexandria :if-let)
+  (:shadowing-import-from :alexandria :when-let)
   (:export :start-panettone :main))
 (in-package :panettone)
 
@@ -32,10 +33,10 @@
 (defvar *ldap* nil
   "The ldap connection")
 
-(defun connect-ldap ()
-  ;; TODO(grfn): make this configurable
-  (setq *ldap* (ldap:new-ldap :host "localhost"
-                              :port 3899)))
+(defun connect-ldap (&key
+                       (host "localhost")
+                       (port 389))
+  (setq *ldap* (ldap:new-ldap :host host :port port)))
 
 (defun ldap-entry->user (entry)
   (apply
@@ -269,20 +270,30 @@ updated issue"
 (defvar *acceptor* nil
   "Hunchentoot acceptor for Panettone's web server.")
 
-(defun start-panettone (&key port data-dir)
-  (connect-ldap)
+(defun start-panettone (&key port data-dir
+                          (ldap-host "localhost")
+                          (ldap-port 389))
+  (connect-ldap :host ldap-host
+                :port ldap-port)
   (initialize-persistence data-dir)
 
   (setq *acceptor*
         (make-instance 'easy-routes:routes-acceptor :port port))
   (hunchentoot:start *acceptor*))
 
+(defun integer-env (var &key default)
+  (or
+   (when-let ((str (uiop:getenvp var)))
+     (try-parse-integer str))
+   default))
+
 (defun main ()
-  ;; TODO(grfn): Read config from env
-  (let ((port 6161)
-        (data-dir "/tmp/panettone"))
+  (let ((port (integer-env "PANETTONE_PORT" :default 6161))
+        (ldap-port (integer-env "LDAP_PORT" :default 389))
+        (data-dir (or (uiop:getenvp "PANETTONE_DATA_DIR") "/var/lib/panettone")))
     (start-panettone :port port
-                     :data-dir data-dir)
+                     :data-dir data-dir
+                     :ldap-port ldap-port)
     (sb-thread:join-thread
      (find-if (lambda (th)
                 (string= (sb-thread:thread-name th)
@@ -291,5 +302,6 @@ updated issue"
 
 (comment
  (start-panettone :port 6161
-                  :data-dir "/tmp/panettone")
+                  :data-dir "/tmp/panettone"
+                  :ldap-port 3899)
  )