From 3caf1ddb7d11bfdcbd21555cfb2b766e8acee16e Mon Sep 17 00:00:00 2001 From: Oscar Zhou <100548325+oscarzhou-portainer@users.noreply.github.com> Date: Mon, 26 Feb 2024 09:00:12 +1300 Subject: [PATCH] fix(edge/template): validate app template env vars [EE-6743] (#11235) --- .../create-edge-stack-view.controller.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/edge/views/edge-stacks/createEdgeStackView/create-edge-stack-view.controller.js b/app/edge/views/edge-stacks/createEdgeStackView/create-edge-stack-view.controller.js index f8293cfd3..33c920c17 100644 --- a/app/edge/views/edge-stacks/createEdgeStackView/create-edge-stack-view.controller.js +++ b/app/edge/views/edge-stacks/createEdgeStackView/create-edge-stack-view.controller.js @@ -226,6 +226,10 @@ export default class CreateEdgeStackViewController { return this.$async(async () => { const name = this.formValues.Name; + if (!this.validateTemplate()) { + return; + } + let envVars = this.formValues.envVars; if (this.state.Method === 'template' && this.state.templateValues.type === 'app') { envVars = [...envVars, ...Object.entries(this.state.templateValues.envVars).map(([key, value]) => ({ name: key, value }))]; @@ -363,12 +367,26 @@ export default class CreateEdgeStackViewController { }); } + validateTemplate() { + if (this.state.Method === 'template' && this.state.templateValues.type === 'app') { + return Object.entries(this.state.templateValues.envVars).every(([, value]) => !!value); + } + + if (this.state.Method === 'template' && this.state.templateValues.type === 'custom') { + return Object.entries(this.state.templateValues.variables).every(([, v]) => { + return !!v.value; + }); + } + return true; + } + formIsInvalid() { return ( this.form.$invalid || !this.formValues.Groups.length || (['template', 'editor'].includes(this.state.Method) && !this.formValues.StackFileContent) || - ('upload' === this.state.Method && !this.formValues.StackFile) + ('upload' === this.state.Method && !this.formValues.StackFile) || + !this.validateTemplate() ); } }