-
Notifications
You must be signed in to change notification settings - Fork 17
/
v2.clj
865 lines (737 loc) · 28.3 KB
/
v2.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
(ns vault.secret.kv.v2
"The kv secrets engine is used to store arbitrary secrets within the
configured physical storage for Vault. Writing to a key in the kv-v1 backend
will replace the old value; sub-fields are not merged together.
Reference: https://www.vaultproject.io/api-docs/secret/kv/kv-v1"
(:require
[clojure.data.json :as json]
[clojure.string :as str]
[vault.client.http :as http]
[vault.client.mock :as mock]
[vault.lease :as lease]
[vault.util :as u])
(:import
clojure.lang.IObj
java.time.Instant
vault.client.http.HTTPClient
vault.client.mock.MockClient))
(def default-mount
"Default mount point to use if one is not provided."
"secret")
;; ## API Protocol
(defprotocol API
"The kv secrets engine is used to store arbitrary static secrets within
Vault. V2 of the engine enables secret versioning and metadata capabilities.
All of the methods in this protocol expect `path` to be relative to the
secret engine mount point. To specify a custom mount, use `with-mount`."
(with-mount
[client mount]
"Return an updated client which will resolve secrets against the provided
mount instead of the default. Passing `nil` will reset the client to the
default.")
(list-secrets
[client path]
"List the secret names located under a path prefix location. Returns a map
with a `:keys` vector of name strings, where further folders are suffixed
with `/`. The path must be a folder; calling this method on a file or a
prefix which does not exist will return `nil`.")
(read-secret
[client path]
[client path opts]
"Read the secret at the provided path. Returns the secret data, if present.
Throws an exception or returns the provided not-found value if not. The
returned value will have the additional information about the secret, such
as the version, attached as metadata.
Options:
- `:version` (integer)
Read a specific version of the secret. Defaults to the latest version.
- `:not-found` (any)
If no secret exists at the given path or version, return this value
instead of throwing an exception.
- `:refresh?` (boolean)
Always make a read for fresh data, even if a cached secret is
available.
- `:ttl` (integer)
Cache the data read for the given number of seconds. A value of zero or
less will disable caching.
Note that Vault internally stores data as JSON, so not all Clojure types
will round-trip successfully!")
(write-secret!
[client path data]
[client path data opts]
"Store data at the provided path, creating a new version of the secret.
Returns the secret metadata.
Options:
- `:cas` (integer)
If set, the write will only succeed if the current version of the secret
matches this value. If set to `0`, it will only succeed if the key doesn't
exist.
Note that Vault internally stores data as JSON, so not all Clojure types
will round-trip successfully!")
(patch-secret!
[client path data]
[client path data opts]
"Patch an existing secret at the provided location. The secret must neither
be deleted nor destroyed. A new version will be created upon successfully
applying a patch with the provided data. Returns the secret metadata.
Options:
- `:cas` (integer)
If set, the update will only succeed if the current version of the secret
matches this value.
Note that Vault internally stores data as JSON, so not all Clojure types
will round-trip successfully!")
(delete-secret!
[client path]
"Delete the latest version of the secret at the provided path, if any.
Returns `nil`.
This is a soft-delete that may later be reverted with [[undelete-versions!]].")
(destroy-secret!
[client path]
"Permanently delete the secret metadata and all version data for the given
path. All version history will be removed. Returns `nil`.")
(delete-versions!
[client path versions]
"Issue a soft delete of the specified versions of the secret. Returns
`nil`.
This marks the versions as deleted and will stop them from being returned
from reads, but the underlying data will not be removed. A delete can be
undone using the `undelete-versions!` method.")
(undelete-versions!
[client path versions]
"Undelete the data for the provided versions of the secret. Returns `nil`.
This restores the data, allowing it to be returned on get requests.")
(destroy-versions!
[client path versions]
"Permanently remove the data for the provided secret and version numbers.
Returns `nil`.")
(read-metadata
[client path]
"Read the metadata and versions for the secret at the specified path.
Metadata is version-agnostic.")
(write-metadata!
[client path opts]
"Update the metadata of a secret at the specified path. Returns `nil`. This
does not create a new version.
Options:
- `:max-versions` (integer)
Number of versions to keep per key. Once the secret has more than the
configured allowed versions, the oldest version will be permanently
deleted.
- `:cas-required` (boolean)
If true, the key will require the cas parameter to be set on all write requests.
- `:delete-version-after` (string)
Duration string specifying the time after which all new versions written
to this secret should be deleted. Accepts Go duration format strings.
- `:custom-metadata` (map)
Map of arbitrary string-to-string valued user-provided metadata meant to
describe the secret.")
(patch-metadata!
[client path opts]
"Patch the existing metadata for the secret at the provided location.
Returns `nil`.
See [[write-metadata!]] for options."))
;; ## Mock Client
(defn- qualify-keyword
"Update a keyword so that it is namespaced by 'vault.secret.kv.v2'."
[k]
(keyword "vault.secret.kv.v2" (name k)))
(defn- ex-not-found
"Construct a new not-found exception for the given mount and path."
([ex]
(let [data (ex-data ex)]
(ex-not-found (::mount data) (::path data) data)))
([mount path]
(ex-not-found mount path nil))
([mount path data]
(ex-info (str "No kv-v2 secret found at " mount ":" path)
(assoc data
::mount mount
::path path))))
(defn- mock-patch
"Given an existing map value and a JSON-patch-style map, apply the updates."
[m u]
(reduce
(fn maybe-update
[acc k]
(cond
;; key is on both sides
(and (contains? m k) (contains? u k))
(let [mv (get m k)
uv (get u k)]
(cond
;; nil overwrites original entry to remove it, so we just don't add
;; it here
(nil? uv)
acc
;; if both sides are maps, recurse
(and (map? mv) (map? uv))
(assoc acc k (mock-patch mv uv))
;; otherwise overwrite
:else
(assoc acc k uv)))
;; key only in original
(contains? m k)
(assoc acc k (get m k))
;; key only in updates
:else
(assoc acc k (get u k))))
(empty m)
(set (concat (keys m) (keys u)))))
(extend-type MockClient
API
(with-mount
[client mount]
(if (some? mount)
(assoc client ::mount mount)
(dissoc client ::mount)))
(list-secrets
[client path]
(let [mount (::mount client default-mount)
path (u/trim-path path)
data (get-in @(:memory client) [::data mount])
result (mock/list-paths (keys data) path)]
(mock/success-response
client
(when (seq result)
{:keys result}))))
(read-secret
([client path]
(read-secret client path nil))
([client path opts]
(let [mount (::mount client default-mount)
path (u/trim-path path)
secret (get-in @(:memory client) [::data mount path])
version-id (or (:version opts)
(:current-version secret))
version (get (:versions secret) version-id)]
(cond
(and version
(or (nil? (:deletion-time version))
(.isBefore (u/now) (:deletion-time version)))
(not (:destroyed version)))
(mock/success-response
client
(-> (:data version)
(json/read-str)
(u/keywordize-keys)
(vary-meta merge
{::mount mount
::path path
::version version-id
::created-time (:created-time version)
::destroyed false}
(when-let [cm (:custom-metadata secret)]
{::custom-metadata (u/keywordize-keys (json/read-str cm))}))))
(contains? opts :not-found)
(mock/success-response client (:not-found opts))
:else
(mock/error-response client (ex-not-found mount path))))))
(write-secret!
([client path data]
(write-secret! client path data nil))
([client path data opts]
(let [mount (::mount client default-mount)
path (u/trim-path path)
serialized (-> data
(u/stringify-keys)
(json/write-str))]
(mock/update-secret!
client
[::data mount path]
(fn update-secret
[secret]
(let [current (:current-version secret 0)
cas (:cas opts)]
(when (and cas (not= cas current))
(throw (ex-info (str "Write failed, cas wanted version " cas
" but found secret version " current)
{::mount mount
::path path
::version current}))))
(let [max-version (if (seq (:versions secret))
(apply max (keys (:versions secret)))
0)
version-id (inc max-version)
version {:data serialized
:created-time (u/now)
:destroyed false}]
(-> (or secret {:created-time (u/now)})
(assoc-in [:versions version-id] version)
(assoc :current-version version-id
:updated-time (u/now)))))
(fn secret-meta
[secret]
(let [current (:current-version secret)
version (get-in secret [:versions current])]
(merge
(select-keys secret [:custom-metadata])
(select-keys version [:created-time :destroyed])
{:version current})))))))
(patch-secret!
([client path data]
(patch-secret! client path data nil))
([client path data opts]
(let [mount (::mount client default-mount)
path (u/trim-path path)]
(mock/update-secret!
client
[::data mount path]
(fn update-secret
[secret]
(let [current (:current-version secret 0)
version (get (:versions secret) current)
cas (:cas opts)]
(when (or (nil? version)
(and (:deletion-time version)
(.isAfter (u/now) (:deletion-time version)))
(:destroyed version))
(mock/error-response client (ex-not-found mount path)))
(when (and cas (not= cas current))
(throw (ex-info (str "Write failed, cas wanted version " cas
" but found secret version " current)
{::mount mount
::path path
::version current})))
(let [new-data (-> (:data version)
(json/read-str)
(u/keywordize-keys)
(mock-patch data)
(u/stringify-keys)
(json/write-str))
max-version (apply max (keys (:versions secret)))
version-id (inc max-version)
version {:data new-data
:created-time (u/now)
:destroyed false}]
(-> secret
(assoc-in [:versions version-id] version)
(assoc :current-version version-id
:updated-time (u/now))))))
(fn secret-meta
[secret]
(let [current (:current-version secret)
version (get-in secret [:versions current])]
(merge
(select-keys secret [:custom-metadata])
(select-keys version [:created-time :destroyed])
{:version current})))))))
(delete-secret!
[client path]
(let [mount (::mount client default-mount)
path (u/trim-path path)]
(mock/update-secret!
client
[::data mount path]
(fn update-secret
[secret]
(when secret
(assoc-in secret [:versions (:current-version secret) :deletion-time] (u/now)))))))
(destroy-secret!
[client path]
(let [mount (::mount client default-mount)
path (u/trim-path path)]
(swap! (:memory client) update-in [::data mount] dissoc path)
(mock/success-response client nil)))
(delete-versions!
[client path versions]
(let [mount (::mount client default-mount)
path (u/trim-path path)
versions (set versions)]
(mock/update-secret!
client
[::data mount path]
(fn update-secret
[secret]
(when secret
(assoc secret
:versions
(reduce
(fn set-deletions
[acc version-id]
(if (contains? acc version-id)
(assoc-in acc [version-id :deletion-time] (u/now))
acc))
(:versions secret)
versions)))))))
(undelete-versions!
[client path versions]
(let [mount (::mount client default-mount)
path (u/trim-path path)
versions (set versions)]
(mock/update-secret!
client
[::data mount path]
(fn update-secret
[secret]
(when secret
(assoc secret
:versions
(reduce
(fn unset-deletions
[acc version-id]
(if (contains? acc version-id)
(update acc version-id dissoc :deletion-time)
acc))
(:versions secret)
versions)))))))
(destroy-versions!
[client path versions]
(let [mount (::mount client default-mount)
path (u/trim-path path)
versions (set versions)]
(mock/update-secret!
client
[::data mount path]
(fn update-secret
[secret]
(when secret
(assoc secret
:versions
(reduce
(fn destroy
[acc version-id]
(if (contains? acc version-id)
(-> acc
(update version-id dissoc :data)
(assoc-in [version-id :destroyed] true))
acc))
(:versions secret)
versions)))))))
(read-metadata
[client path]
(let [mount (::mount client default-mount)
path (u/trim-path path)
secret (get-in @(:memory client) [::data mount path])]
(if secret
(mock/success-response
client
(-> (merge {:max-versions 0
:cas-required false
:delete-version-after "0s"}
secret)
(select-keys [:max-versions
:cas-required
:created-time
:updated-time
:current-version
:custom-metadata
:delete-version-after])
(assoc :oldest-version (if (seq (:versions secret))
(->> (:versions secret)
(sort-by (comp :created-time val))
(first)
(key))
0)
:versions (into {}
(map (juxt key #(select-keys (val %)
[:created-time
:deletion-time
:destroyed])))
(:versions secret)))
(u/update-some :custom-metadata (comp u/keywordize-keys json/read-str))))
(mock/error-response client (ex-not-found mount path)))))
(write-metadata!
[client path opts]
(let [mount (::mount client default-mount)
path (u/trim-path path)]
(mock/update-secret!
client
[::data mount path]
(fn update-secret
[secret]
(when secret
(-> secret
(merge (select-keys opts
[:max-versions
:cas-required
:delete-version-after]))
(cond->
(:custom-metadata opts)
(assoc :custom-metadata
(-> (:custom-metadata opts)
(u/stringify-keys)
(update-vals str)
(json/write-str))))))))))
(patch-metadata!
[client path opts]
(let [mount (::mount client default-mount)
path (u/trim-path path)]
(mock/update-secret!
client
[::data mount path]
(fn update-secret
[secret]
(when-not secret
(throw (ex-not-found mount path)))
(-> secret
(merge (select-keys opts
[:max-versions
:cas-required
:delete-version-after]))
(cond->
(:custom-metadata opts)
(assoc :custom-metadata
(-> (:custom-metadata secret)
(json/read-str)
(u/keywordize-keys)
(mock-patch (:custom-metadata opts))
(u/stringify-keys)
(update-vals str)
(json/write-str))))))))))
;; ## HTTP Client
(defn- parse-meta-times
"Update the data map by parsing any keywords which end in '-time' as
Instants. Entries with blank values will be removed."
[data]
(into (empty data)
(keep
(fn [[k v :as entry]]
(if (str/ends-with? (name k) "-time")
(when-not (str/blank? v)
[k (Instant/parse v)])
entry)))
data))
(defn- parse-secret-metadata
"Interpret a secret metadata response."
[body]
(let [raw-data (get body "data")]
(-> raw-data
(dissoc "custom_metadata" "versions")
(u/kebabify-keys)
(parse-meta-times)
(merge
(when-let [cm (get raw-data "custom_metadata")]
{:custom-metadata (u/keywordize-keys cm)})
(when-let [versions (not-empty (get raw-data "versions"))]
{:versions (into (sorted-map)
(map
(fn parse-version
[[version-id-str version]]
[(or (parse-long version-id-str) version-id-str)
(-> version
(u/kebabify-keys)
(parse-meta-times))]))
versions)})))))
(defn- synthesize-lease
"Produce a synthetic map of lease information from the cache key and an
optional custom TTL. Returns nil if the TTL is not a positive number."
[cache-key ttl]
(when (and ttl (pos? ttl))
{::lease/id (str (random-uuid))
::lease/key cache-key
::lease/duration (long ttl)
::lease/expires-at (.plusSeconds (u/now) (long ttl))}))
(defn- wrap-not-found
"Handle an API exception and wrap 404s as a standard not-found exception.
Other exceptions are returned as-is."
[ex]
(if (http/not-found? ex)
(ex-not-found ex)
ex))
(extend-type HTTPClient
API
(with-mount
[client mount]
(if (some? mount)
(assoc client ::mount mount)
(dissoc client ::mount)))
(list-secrets
[client path]
(let [mount (::mount client default-mount)
path (u/trim-path path)]
(http/call-api
client ::list-secrets
:list (u/join-path mount "metadata" path)
{:info {::mount mount, ::path path}
:handle-response
(fn handle-response
[body]
(u/kebabify-keys (get body "data")))
:handle-error
(fn handle-error
[ex]
(when-not (http/not-found? ex)
ex))})))
(read-secret
([client path]
(read-secret client path nil))
([client path opts]
(let [mount (::mount client default-mount)
path (u/trim-path path)
version (:version opts)
info (cond-> {::mount mount, ::path path}
version
(assoc ::version version))
cache-key [::secret mount path]
cached (when-not (:refresh? opts)
(lease/find-data client cache-key))]
(if (and cached
(or (nil? version)
(= version (::version (meta cached)))))
(http/cached-response client ::read-secret info cached)
(http/call-api
client ::read-secret
:get (u/join-path mount "data" path)
{:info info
:query-params (if version
{:version version}
{})
:handle-response
(fn handle-response
[body]
(let [lease (synthesize-lease cache-key (:ttl opts))
metadata (-> (get-in body ["data" "metadata"])
(u/kebabify-keys)
(parse-meta-times)
(update-keys qualify-keyword))
data (-> (get-in body ["data" "data"])
(u/keywordize-keys)
(vary-meta merge metadata))]
(when lease
(lease/invalidate! client cache-key)
(lease/put! client lease data))
(vary-meta data merge lease)))
:handle-error
(fn handle-error
[ex]
(if (http/not-found? ex)
(if-let [[_ not-found] (find opts :not-found)]
(if (instance? IObj not-found)
(vary-meta not-found merge (ex-data ex))
not-found)
(ex-not-found ex))
ex))})))))
(write-secret!
([client path data]
(write-secret! client path data nil))
([client path data opts]
(let [mount (::mount client default-mount)
path (u/trim-path path)
cache-key [::secret mount path]]
(lease/invalidate! client cache-key)
(http/call-api
client ::write-secret!
:post (u/join-path mount "data" path)
{:info {::mount mount, ::path path}
:content-type :json
:body {:options (select-keys opts [:cas])
:data (u/stringify-keys data)}
:handle-response parse-secret-metadata}))))
(patch-secret!
([client path data]
(patch-secret! client path data nil))
([client path data opts]
(let [mount (::mount client default-mount)
path (u/trim-path path)
cache-key [::secret mount path]]
(lease/invalidate! client cache-key)
(http/call-api
client ::patch-secret!
:patch (u/join-path mount "data" path)
{:info {::mount mount, ::path path}
:headers {"content-type" "application/merge-patch+json"}
:body (json/write-str
{:options (select-keys opts [:cas])
:data data})
:handle-response parse-secret-metadata
:handle-error wrap-not-found}))))
(delete-secret!
[client path]
(let [mount (::mount client default-mount)
path (u/trim-path path)
cache-key [::secret mount path]]
(lease/invalidate! client cache-key)
(http/call-api
client ::delete-secret!
:delete (u/join-path mount "data" path)
{:info {::mount mount, ::path path}})))
(destroy-secret!
[client path]
(let [mount (::mount client default-mount)
path (u/trim-path path)
cache-key [::secret mount path]]
(lease/invalidate! client cache-key)
(http/call-api
client ::destroy-secret!
:delete (u/join-path mount "metadata" path)
{:info {::mount mount, ::path path}})))
(delete-versions!
[client path versions]
(let [mount (::mount client default-mount)
path (u/trim-path path)
cache-key [::secret mount path]]
(lease/invalidate! client cache-key)
(http/call-api
client ::delete-versions!
:post (u/join-path mount "delete" path)
{:info {::mount mount, ::path path, ::versions versions}
:content-type :json
:body {:versions versions}})))
(undelete-versions!
[client path versions]
(let [mount (::mount client default-mount)
path (u/trim-path path)
cache-key [::secret mount path]]
(lease/invalidate! client cache-key)
(http/call-api
client ::undelete-versions!
:post (u/join-path mount "undelete" path)
{:info {::mount mount, ::path path, ::versions versions}
:content-type :json
:body {:versions versions}})))
(destroy-versions!
[client path versions]
(let [mount (::mount client default-mount)
path (u/trim-path path)
cache-key [::secret mount path]]
(lease/invalidate! client cache-key)
(http/call-api
client ::destroy-versions!
:post (u/join-path mount "destroy" path)
{:info {::mount mount, ::path path, ::versions versions}
:content-type :json
:body {:versions versions}})))
(read-metadata
[client path]
(let [mount (::mount client default-mount)
path (u/trim-path path)]
(http/call-api
client ::read-metadata
:get (u/join-path mount "metadata" path)
{:info {::mount mount, ::path path}
:handle-response parse-secret-metadata
:handle-error wrap-not-found})))
(write-metadata!
[client path opts]
(let [mount (::mount client default-mount)
path (u/trim-path path)]
(http/call-api
client ::write-metadata!
:post (u/join-path mount "metadata" path)
{:info {::mount mount, ::path path}
:content-type :json
:body (-> opts
(dissoc :custom-metadata)
(u/snakify-keys)
(cond->
(seq (:custom-metadata opts))
(assoc :custom_metadata
(u/stringify-keys (:custom-metadata opts)))))})))
(patch-metadata!
[client path opts]
(let [mount (::mount client default-mount)
path (u/trim-path path)]
(http/call-api
client ::patch-metadata!
:patch (u/join-path mount "metadata" path)
{:info {::mount mount, ::path path}
:headers {"content-type" "application/merge-patch+json"}
:body (json/write-str
(-> opts
(dissoc :custom-metadata)
(u/snakify-keys)
(cond->
(seq (:custom-metadata opts))
(assoc :custom_metadata
(u/stringify-keys (:custom-metadata opts))))))
:handle-error wrap-not-found}))))