From 323c8449e2d8a7c1f5a51689fc1e5bc298eb5355 Mon Sep 17 00:00:00 2001 From: Jakob L. Kreuze Date: Sat, 5 Aug 2023 14:24:22 -0400 Subject: [dynamic] Implement debug mode for local development --- haunt/api.scm | 3 ++- haunt/jakob/dynamic/capabilities/comments.scm | 2 +- haunt/jakob/dynamic/capabilities/gallery.scm | 2 +- haunt/jakob/dynamic/capabilities/rsvp.scm | 2 +- haunt/jakob/dynamic/config.scm | 37 +++++++++++++++++++++++++++ haunt/jakob/dynamic/database.scm | 29 --------------------- haunt/jakob/dynamic/logging.scm | 4 ++- 7 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 haunt/jakob/dynamic/config.scm delete mode 100644 haunt/jakob/dynamic/database.scm diff --git a/haunt/api.scm b/haunt/api.scm index 2b476d7..b6093f6 100644 --- a/haunt/api.scm +++ b/haunt/api.scm @@ -17,6 +17,7 @@ (use-modules (ice-9 match) (jakob dynamic blacklist) (jakob dynamic captcha) + (jakob dynamic config) (jakob dynamic capabilities comment-form) (jakob dynamic capabilities comments) (jakob dynamic capabilities gallery) @@ -66,7 +67,7 @@ (values->list (format-error-response ex)))) (fail-when-ip-blacklisted originating-ip) (values->list - ((rate-limit-wrap + (((if (%debug-enabled) identity rate-limit-wrap) (match (cons (request-method request) endpoint) (('GET "apps" "comment-form" _) get-comment-form) ('(GET "api" "challenge" "proof-of-work") make-pow-challenge!) diff --git a/haunt/jakob/dynamic/capabilities/comments.scm b/haunt/jakob/dynamic/capabilities/comments.scm index 996c549..33f2429 100644 --- a/haunt/jakob/dynamic/capabilities/comments.scm +++ b/haunt/jakob/dynamic/capabilities/comments.scm @@ -18,7 +18,7 @@ #:use-module (ice-9 match) #:use-module (jakob dynamic capabilities common) #:use-module (jakob dynamic captcha) - #:use-module (jakob dynamic database) + #:use-module (jakob dynamic config) #:use-module (jakob dynamic errors) #:use-module (jakob dynamic util) #:use-module (json) diff --git a/haunt/jakob/dynamic/capabilities/gallery.scm b/haunt/jakob/dynamic/capabilities/gallery.scm index 591335e..7087149 100644 --- a/haunt/jakob/dynamic/capabilities/gallery.scm +++ b/haunt/jakob/dynamic/capabilities/gallery.scm @@ -17,7 +17,7 @@ (define-module (jakob dynamic capabilities gallery) #:use-module (haunt html) #:use-module (ice-9 match) - #:use-module (jakob dynamic database) + #:use-module (jakob dynamic config) #:use-module (jakob dynamic errors) #:use-module (jakob dynamic util) #:use-module (jakob theme) diff --git a/haunt/jakob/dynamic/capabilities/rsvp.scm b/haunt/jakob/dynamic/capabilities/rsvp.scm index 2975e4d..856f1f1 100644 --- a/haunt/jakob/dynamic/capabilities/rsvp.scm +++ b/haunt/jakob/dynamic/capabilities/rsvp.scm @@ -18,7 +18,7 @@ #:use-module (gcrypt base64) #:use-module (ice-9 binary-ports) #:use-module (ice-9 match) - #:use-module (jakob dynamic database) + #:use-module (jakob dynamic config) #:use-module (jakob dynamic errors) #:use-module (jakob dynamic util) #:use-module (json) diff --git a/haunt/jakob/dynamic/config.scm b/haunt/jakob/dynamic/config.scm new file mode 100644 index 0000000..5eb615b --- /dev/null +++ b/haunt/jakob/dynamic/config.scm @@ -0,0 +1,37 @@ +;;; Copyright © 2019 - 2023 Jakob L. Kreuze +;;; +;;; This program is free software; you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation; either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see +;;; . + +(define-module (jakob dynamic config) + #:export (%debug-enabled + paramstring-for-dbname)) + +;; Whether or not to enable "debug mode", in which: +;; +;; - Log messages are written to stdout. +;; - Rate limiting is disabled. +(define %debug-enabled (make-parameter (or (getenv "API_SERVER_DEBUG") #f))) + +;; Should be fairly self-explanatory. +(define %postgresql-user (make-parameter (or (getenv "API_SERVER_DB_USER") "jakob_dynamic"))) +(define %postgresql-host (make-parameter (or (getenv "API_SERVER_DB_HOST") "localhost"))) +(define %postgresql-port (make-parameter (or (getenv "API_SERVER_DB_PORT") "5432"))) + +(define (paramstring-for-dbname dbname) + (format #f "host=~a port=~a user=~a dbname=~a" + (%postgresql-host) + (%postgresql-port) + (%postgresql-user) + dbname)) diff --git a/haunt/jakob/dynamic/database.scm b/haunt/jakob/dynamic/database.scm deleted file mode 100644 index f5b1353..0000000 --- a/haunt/jakob/dynamic/database.scm +++ /dev/null @@ -1,29 +0,0 @@ -;;; Copyright © 2019 - 2023 Jakob L. Kreuze -;;; -;;; This program is free software; you can redistribute it and/or -;;; modify it under the terms of the GNU General Public License as -;;; published by the Free Software Foundation; either version 3 of the -;;; License, or (at your option) any later version. -;;; -;;; This program is distributed in the hope that it will be useful, -;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -;;; General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with this program. If not, see -;;; . - -(define-module (jakob dynamic database) - #:export (paramstring-for-dbname)) - -(define %postgresql-user (make-parameter (or (getenv "API_SERVER_DB_USER") "jakob_dynamic"))) -(define %postgresql-host (make-parameter (or (getenv "API_SERVER_DB_HOST") "localhost"))) -(define %postgresql-port (make-parameter (or (getenv "API_SERVER_DB_PORT") "5432"))) - -(define (paramstring-for-dbname dbname) - (format #f "host=~a port=~a user=~a dbname=~a" - (%postgresql-host) - (%postgresql-port) - (%postgresql-user) - dbname)) diff --git a/haunt/jakob/dynamic/logging.scm b/haunt/jakob/dynamic/logging.scm index 7b1bd0a..c937c66 100644 --- a/haunt/jakob/dynamic/logging.scm +++ b/haunt/jakob/dynamic/logging.scm @@ -16,11 +16,13 @@ (define-module (jakob dynamic logging) #:use-module (ice-9 format) + #:use-module (jakob dynamic config) #:use-module (srfi srfi-19) #:export (log-append!)) -(define %log-file-name (make-parameter "/var/log/jakob-dynamic.log")) (define %log-level (make-parameter 'info)) +(define %log-file-name + (make-parameter (if (%debug-enabled) "/dev/stdout" "/var/log/jakob-dynamic.log"))) (define (dominates message-level baseline-level) "Determine if `a' should be shown for baseline log level `b'." -- cgit v1.3