 (defn anonymize-leaf
   "Anonymize leaf data, if the context matches a rule"
   [value ltype context config]
-  (let [rules      (get config "rules")
-        type-rules (get rules (name ltype))]
-    ;; Preserve nils and booleans
-    (if (or (nil? value) (boolean? value))
-      value
-      (if (rules-match type-rules context)
-        (anonymize-leaf-memoize ltype value)
-        value))))
+  (let [type-rules (get-in config ["rules" (name ltype)])]
+    (if (rules-match type-rules context)
+      (anonymize-leaf-memoize ltype value)
+      value)))
 
 ;; Functions for anonymizing data structures
 

   context
   config]
  (if (= "time" (get metric "category"))
    (update-in metric ["name"] #(anonymize-lowercase-type % context config))
    metric))

(pls/defn-validated anonymize-metrics :- [metric-schema-str]
  [metrics :- (s/maybe [metric-schema-str])
   context
   config]
  (when metrics
    (map #(anonymize-metric % context config) metrics)))

(pls/defn-validated anonymize-log :- log-schema-str
  [log :- log-schema-str
   context
   config]
  (-> log
      (update-in ["message"] anonymize-leaf :log-message context config)
      (update-in ["source"] anonymize-log-source context config)
      (update-in ["tags"] anonymize-tags context config)
      (update-in ["file"] anonymize-leaf :file context config)
      (update-in ["line"] anonymize-leaf :line context config)))

(pls/defn-validated anonymize-logs :- (s/maybe [log-schema-str])
  [logs :- [log-schema-str]
   context
   config]

  (let [[_ rel-type rel-title] (re-matches #"(.+)\[(.+)\]" rel)
        ;; here we modify the context, as the anonymization of a reference
        ;; is not about where it appears
        newcontext {"node" (get context "node")
                    "title" rel-title
                    "type" rel-type}
        ;; optionally anonymize each part
        new-type (anonymize-leaf rel-type :type newcontext config)
        new-title (anonymize-leaf rel-title :title newcontext config)]
    (str new-type "[" new-title "]")))

(defn anonymize-references
