mirror of
https://github.com/penpot/penpot.git
synced 2025-02-08 16:18:11 -05:00
✨ Make file schema validation configurable using flags
This commit is contained in:
parent
0081db4770
commit
ac3d7f00d5
6 changed files with 43 additions and 12 deletions
|
@ -26,7 +26,9 @@ export PENPOT_FLAGS="\
|
|||
enable-soft-rpc-rlimit \
|
||||
enable-webhooks \
|
||||
enable-access-tokens \
|
||||
enable-file-validation";
|
||||
disable-file-validation \
|
||||
disable-file-schema-validation \
|
||||
enable-soft-file-schema-validation";
|
||||
|
||||
# export PENPOT_DATABASE_URI="postgresql://172.17.0.1:5432/penpot"
|
||||
# export PENPOT_DATABASE_USERNAME="penpot"
|
||||
|
|
|
@ -17,7 +17,9 @@ export PENPOT_FLAGS="\
|
|||
disable-secure-session-cookies \
|
||||
enable-smtp \
|
||||
enable-access-tokens \
|
||||
enable-file-validation";
|
||||
disable-file-validation \
|
||||
disable-file-schema-validation \
|
||||
enable-soft-file-schema-validation";
|
||||
|
||||
# Initialize MINIO config
|
||||
mc alias set penpot-s3/ http://minio:9000 minioadmin minioadmin
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
(defn record->report
|
||||
[{:keys [::l/context ::l/message ::l/props ::l/logger ::l/level ::l/cause] :as record}]
|
||||
(us/assert! ::l/record record)
|
||||
|
||||
(if (or (instance? java.util.concurrent.CompletionException cause)
|
||||
(instance? java.util.concurrent.ExecutionException cause))
|
||||
(-> record
|
||||
|
|
|
@ -781,11 +781,19 @@
|
|||
(update :components relink-shapes)
|
||||
(update :media relink-media)
|
||||
(pmg/migrate-data)
|
||||
(d/without-nils))))
|
||||
(d/without-nils)))))
|
||||
|
||||
(cond-> (contains? cf/flags :file-validation)
|
||||
(fval/validate-file-schema!))
|
||||
params (if (contains? cf/flags :file-schema-validation)
|
||||
(fval/validate-file-schema! params)
|
||||
params)
|
||||
|
||||
_ (when (contains? cf/flags :soft-file-schema-validation)
|
||||
(try
|
||||
(fval/validate-file-schema! params)
|
||||
(catch Throwable cause
|
||||
(l/error :hint "file schema validation error" :cause cause))))
|
||||
|
||||
params (-> params
|
||||
(postprocess-file)
|
||||
(update :features #(db/create-array conn "text" %))
|
||||
(update :data blob/encode))]
|
||||
|
@ -878,7 +886,7 @@
|
|||
{:on-conflict-do-nothing overwrite?}))))
|
||||
|
||||
(doseq [item (:thumbnails @*state*)]
|
||||
(l/dbg :hint "inserting file tagged object thumbnail"
|
||||
(l/dbg :hint "inserting file object thumbnail"
|
||||
:file-id (:file-id item)
|
||||
:object-id (:object-id item)
|
||||
::l/sync? true)
|
||||
|
|
|
@ -266,6 +266,14 @@
|
|||
;; Retrieve and return lagged data
|
||||
(get-lagged-changes conn params))))
|
||||
|
||||
(defn- soft-validate-file-schema!
|
||||
[file]
|
||||
(try
|
||||
(val/validate-file-schema! file)
|
||||
(catch Throwable cause
|
||||
(l/error :hint "file schema validation error" :cause cause)))
|
||||
|
||||
file)
|
||||
|
||||
(defn- update-file-data
|
||||
[conn file changes skip-validate]
|
||||
|
@ -295,8 +303,14 @@
|
|||
;; If `libs` is defined, then full validation is performed
|
||||
(cond-> (and (contains? cf/flags :file-validation)
|
||||
(not skip-validate))
|
||||
(-> (val/validate-file! libs)
|
||||
(val/validate-file-schema!)))
|
||||
(val/validate-file! libs))
|
||||
|
||||
(cond-> (and (contains? cf/flags :file-schema-validation)
|
||||
(not skip-validate))
|
||||
(val/validate-file-schema!))
|
||||
|
||||
(cond-> (contains? cf/flags :soft-file-schema-validation)
|
||||
(soft-validate-file-schema!))
|
||||
|
||||
(cond-> (and (contains? cfeat/*current* "fdata/objects-map")
|
||||
(not (contains? cfeat/*previous* "fdata/objects-map")))
|
||||
|
|
|
@ -151,7 +151,9 @@
|
|||
(ps/acquire! feat/*semaphore*)
|
||||
(px/submit! scope (fn []
|
||||
(-> (assoc system ::db/rollback rollback?)
|
||||
(feat/migrate-file! file-id :validate? validate?)))))
|
||||
(feat/migrate-file! file-id
|
||||
:validate? validate?
|
||||
:throw-on-validate? (not skip-on-error))))))
|
||||
(get-candidates))
|
||||
|
||||
(p/await! scope))
|
||||
|
@ -182,7 +184,9 @@
|
|||
(binding [feat/*stats* stats
|
||||
feat/*skip-on-error* skip-on-error]
|
||||
(-> (assoc system ::db/rollback rollback?)
|
||||
(feat/migrate-team! team-id :validate? validate?))
|
||||
(feat/migrate-team! team-id
|
||||
:validate? validate?
|
||||
:throw-on-validate? (not skip-on-error)))
|
||||
|
||||
(print-stats!
|
||||
(-> (deref feat/*stats*)
|
||||
|
@ -238,7 +242,9 @@
|
|||
(migrate-team [team-id]
|
||||
(try
|
||||
(-> (assoc system ::db/rollback rollback?)
|
||||
(feat/migrate-team! team-id :validate? validate? :throw-on-validate? (not skip-on-error)))
|
||||
(feat/migrate-team! team-id
|
||||
:validate? validate?
|
||||
:throw-on-validate? (not skip-on-error)))
|
||||
(catch Throwable cause
|
||||
(l/err :hint "unexpected error on processing team" :team-id (dm/str team-id) :cause cause))))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue