From 6089c7a7127194c35355636a44151f5a330bdb5c Mon Sep 17 00:00:00 2001 From: Gary Johnson Date: Wed, 4 Sep 2024 10:33:06 -0400 Subject: [PATCH] Review fixes: see below for details * Global - Rename `:truncate-request?` to `:truncate-request` everywhere * README.org - Make `:truncate-request` false by default (more intuitive) * config.namespaced-example.edn - Add example for `:triangulum.handler/truncate-request` * config.nested-example.edn - Add example for `:server` -> `:truncate-request` * src/triangulum/config.clj - 27: `::boolean` spec is unused * src/triangulum/config_namespaced_spec.clj - 36: Include `:triangulum.handler/truncate-request` in server spec * src/triangulum/config_nested_spec.clj - 23: Include `:triangulum.handler/truncate-request` in server spec * src/triangulum/handler.clj - 38: Add spec: `::truncate-request boolean?` - Change :truncate-request logic to be false by default (more intuitive) * src/triangulum/server.clj - 28: Remove `::truncate-request` spec --- README.org | 2 +- config.namespaced-example.edn | 1 + config.nested-example.edn | 1 + src/triangulum/config.clj | 1 - src/triangulum/config_namespaced_spec.clj | 1 + src/triangulum/config_nested_spec.clj | 1 + src/triangulum/handler.clj | 5 ++--- src/triangulum/server.clj | 1 - 8 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.org b/README.org index 5101128..c95c80d 100644 --- a/README.org +++ b/README.org @@ -67,7 +67,7 @@ file logging system, and worker functions for non-HTTP-related tasks. :cider-nrepl true ; If your editor supports CIDER middleware :mode "dev" ; or prod :log-dir "logs" ; or "" for stdout - :truncate-request? false ; true by default + :truncate-request true ; false by default :handler product-ns.routing/handler :workers {:scheduler {:start product-ns.jobs/start-scheduled-jobs! :stop product-ns.jobs/stop-scheduled-jobs!}} diff --git a/config.namespaced-example.edn b/config.namespaced-example.edn index 22dbf37..d9e38dc 100644 --- a/config.namespaced-example.edn +++ b/config.namespaced-example.edn @@ -18,6 +18,7 @@ :triangulum.handler/route-authenticator product-ns.handlers/route-authenticator :triangulum.handler/routing-tables [backend-libary-ns.routing/routes product-ns.routing/routes] :triangulum.handler/bad-tokens #{".php"} + :triangulum.handler/truncate-request false :triangulum.handler/private-request-keys #{:base64Image :plotFileBase64 :sampleFileBase64} :triangulum.handler/private-response-keys #{} diff --git a/config.nested-example.edn b/config.nested-example.edn index 1acb921..28914c7 100644 --- a/config.nested-example.edn +++ b/config.nested-example.edn @@ -18,6 +18,7 @@ :route-authenticator product-ns.handlers/route-authenticator :routing-tables [common-libary-ns.routing/routes product-ns.routing/routes] :bad-tokens #{".php"} + :truncate-request false :private-request-keys #{:base64Image :plotFileBase64 :sampleFileBase64} :private-response-keys #{} diff --git a/src/triangulum/config.clj b/src/triangulum/config.clj index f575188..0e8dcb7 100644 --- a/src/triangulum/config.clj +++ b/src/triangulum/config.clj @@ -24,7 +24,6 @@ (s/def ::url-or-file-path (s/and string? #(re-matches #"^(https?:\/\/[^\s\/$.?#].[^\s]*)|(/[^:*?\"<>|]*)$" %))) (s/def ::path (s/and string? #(re-matches #"[./][^:*?\"<>|]*" %))) (s/def ::hostname (s/and string? #(re-matches #"[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}" %))) -(s/def ::boolean boolean?) ;; Config file diff --git a/src/triangulum/config_namespaced_spec.clj b/src/triangulum/config_namespaced_spec.clj index b6be39e..40f2123 100644 --- a/src/triangulum/config_namespaced_spec.clj +++ b/src/triangulum/config_namespaced_spec.clj @@ -33,6 +33,7 @@ :triangulum.handler/redirect-handler :triangulum.handler/route-authenticator :triangulum.handler/routing-tables + :triangulum.handler/truncate-request :triangulum.handler/private-request-keys :triangulum.handler/private-response-keys :triangulum.handler/bad-tokens diff --git a/src/triangulum/config_nested_spec.clj b/src/triangulum/config_nested_spec.clj index 3c4072e..8acbd45 100644 --- a/src/triangulum/config_nested_spec.clj +++ b/src/triangulum/config_nested_spec.clj @@ -20,6 +20,7 @@ :triangulum.handler/route-authenticator :triangulum.handler/routing-tables :triangulum.handler/bad-tokens + :triangulum.handler/truncate-request :triangulum.handler/private-request-keys :triangulum.handler/private-response-keys :triangulum.worker/workers diff --git a/src/triangulum/handler.clj b/src/triangulum/handler.clj index 45214b8..a4cfc5c 100644 --- a/src/triangulum/handler.clj +++ b/src/triangulum/handler.clj @@ -35,6 +35,7 @@ (s/def ::route-authenticator ::config/namespaced-symbol) (s/def ::routing-tables (s/coll-of ::config/namespaced-symbol)) (s/def ::bad-tokens (s/coll-of ::config/string :kind set? :min-count 0)) +(s/def ::truncate-request boolean?) (s/def ::private-request-keys (s/coll-of keyword :kind set?)) (s/def ::private-response-keys (s/coll-of keyword :kind set?)) @@ -85,11 +86,9 @@ [handler] (fn [request] (let [{:keys [uri request-method params]} request + truncate-request? (get-config :server :truncate-request) private-request-keys (or (get-config :server :private-request-keys) #{:password :passwordConfirmation}) - truncate-request? (if (some? (get-config :server :truncate-request?)) - (get-config :server :truncate-request?) - true) param-str (pr-str (apply dissoc params private-request-keys))] (log (apply str "Request(" (name request-method) "): \"" uri "\" " param-str) :truncate? truncate-request?) (handler request)))) diff --git a/src/triangulum/server.clj b/src/triangulum/server.clj index 5e6bb89..169e1ab 100644 --- a/src/triangulum/server.clj +++ b/src/triangulum/server.clj @@ -25,7 +25,6 @@ (s/def ::cider-nrepl boolean?) (s/def ::mode (s/and ::config/string #{"dev" "prod"})) (s/def ::log-dir ::config/string) -(s/def ::truncate-request? ::config/boolean) (s/def ::handler ::config/namespaced-symbol) (s/def ::keystore-file ::config/string) (s/def ::keystore-type ::config/string)