Created
April 21, 2021 20:11
-
-
Save jeff303/b3711b720bbdb06b7b77a737b528b0e1 to your computer and use it in GitHub Desktop.
Remove keys with the word "password" from deeply nested maps using Specter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[com.rpl.specter :refer :all]) | |
(def data {:a 1 :b 2 :c {:x 14 :my-password "foo" :y {:foo "bar" :baz-password-value "secret" :z 141}}}) | |
;; from https://github.com/redplanetlabs/specter/wiki/Using-Specter-Recursively#recursively-navigate-to-every-map-in-a-map-of-maps | |
(def MAP-NODES | |
(recursive-path [] p | |
(if-path map? | |
(continue-then-stay MAP-VALS p)))) | |
(setval [MAP-NODES MAP-KEYS #(->> % name (re-matches #".*password.*"))] NONE data) | |
=> {:a 1, :b 2, :c {:x 14, :y {:foo "bar", :z 141}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment