aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-02-25 16:14:24 -0600
committerColin Okay <okay@toyful.space>2022-02-25 16:14:24 -0600
commit78ec0a586fa865500e66a33a8cbcdf1edca3f9b4 (patch)
treefd4985003b0c6d1140960488d8ad2f30bf85bf41
parent595dbd34bb0b5f0a7adc9912d39198cf407974f4 (diff)
make-admins-from-file and some docstrings
-rw-r--r--src/main.lisp88
1 files changed, 62 insertions, 26 deletions
diff --git a/src/main.lisp b/src/main.lisp
index 2ddb845..1b4463c 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -228,41 +228,77 @@ accounts. So keep it secret, keep it safe."
(a:write-string-into-file
(uuid)
path))
- (a:read-file-into-string file))
+ (a:read-file-into-string path))
+
+
+(defun make-admins-from-file (path)
+ (if (uiop:file-exists-p path)
+ (let ((admins (with-open-file (input path) (read input))))
+ (assert (every #$(and (= 2 (length $admin)) (every 'stringp $admin)) admins)
+ () "Admins file formatted incorrectly. It should be a list of pairs of strings ((name pw) (name pw) ...)")
+ (loop for (name pass) in admins
+ unless (contributor-by-handle name)
+ do (make-new-admin-user name pass)
+ else
+ do (format *error-output* "Did not make admin ~a." name)))
+ (format *error-output*
+ "Though an admins file ~s was specified, it was not found on disk.~%"
+ path)))
(defun start-from-config (&optional (config-file +default-config-file+))
- (assert (uiop:file-exists-p config-file))
- (let ((config
- (with-open-file (input config-file)
- (read input))))
- (with-plist
- (port address salt-file domain store-dir admins swank-port) config
- ;; start the server with options in the config.
- (apply 'start
- (nconc
- (when port (list :port port))
- (when salt-file
- (list :salt (salt-from-file salt-file)))
- (when address (list :address address))
- (when domain (list :domain domain))
- (when store-dir (list :store-dir store-dir))))
- ;; make any admins listed.
- (when admins
- (loop for (name pass) in admins
- unless (contributor-by-handle name)
- do (make-new-admin-user name pass)))
- (when swank-port
- (setf *swank-thread*
- (bt:make-thread
- (lambda () (swank:create-server :port swank-port :dont-close t))))))))
+ "config file should contain several options:
+
+:PORT :ADDRESS :DOMAIN :STORE-DIR are all passed to START as-is.
+
+:SALT-FILE should be a path to a location on disk both readible and
+writable by the current process. This file contains the server salt,
+used to generate password hashes (along with contributor-salt). If a
+file at this location does not exist, it will be created. You should
+store this file somewhere besides the server after starting up, or you
+should ensure that this process, and only this process, has read/write
+access to it.
+
+:INIT-ADMINS-FILE should be a file that contains a list of pairs of
+strings. This list is interpeted to be ((HANDLE1 PW1) (HANDLE2 PW2)
+...) for admin users for this server. This file will be read and the
+users will be made. You should destroy this file after the initial
+boot up, subsequent boots will not need it, even if it remains
+mentioned in th config file.
+"
+
+ (handler-case
+ (progn
+ (assert (uiop:file-exists-p config-file))
+ (let ((config
+ (with-open-file (input config-file)
+ (read input))))
+ (with-plist
+ (port address salt-file domain store-dir init-admins-file swank-port) config
+ ;; start the server with options in the config.
+ (apply 'start
+ (nconc
+ (when port (list :port port))
+ (when salt-file
+ (list :salt (salt-from-file salt-file)))
+ (when address (list :address address))
+ (when domain (list :domain domain))
+ (when store-dir (list :store-dir store-dir))))
+ ;; make any admins listed.
+ (when init-admins-file
+ (make-admins-from-file init-admins-file))
+ (when swank-port
+ (setf *swank-thread*
+ (bt:make-thread
+ (lambda () (swank:create-server :port swank-port :dont-close t))))))))))
(defun start
(&key
(port 8888)
(address "127.0.0.1")
- (salt "change me")
+ salt
(domain "localhost")
store-dir)
+ (assert salt)
(setf *instance-salt* salt
*server-domain* domain)
(ensure-datastore store-dir)