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