From 9070072e55b14c690c119cc35b4f608c39a0c063 Mon Sep 17 00:00:00 2001 From: Philippe DUL Date: Tue, 14 Mar 2023 12:45:03 +0100 Subject: [PATCH] [releng] Add some guards on inputs --- vars/deployer.groovy | 91 ++++++++++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 29 deletions(-) diff --git a/vars/deployer.groovy b/vars/deployer.groovy index 9e6e915..85d39ce 100644 --- a/vars/deployer.groovy +++ b/vars/deployer.groovy @@ -1,40 +1,59 @@ def capellaNightlyProduct(String inputPath, String outputDirName) { - def outputPath = getFullCapellaProductPath(outputDirName) - def sshAccount = getSSHAccount() - - sshagent (['projects-storage.eclipse.org-bot-ssh']) { - sh "ssh ${sshAccount} mkdir -p ${outputPath}" - sh "scp -rp ${inputPath} ${sshAccount}:${outputPath}" - } + if (isInvalid(outputDirName)) { + log.error("Deployment Error: ${outputDirName} is not recognised") + } + else { + def outputPath = getFullCapellaProductPath(outputDirName) + def sshAccount = getSSHAccount() + + sshagent (['projects-storage.eclipse.org-bot-ssh']) { + sh "ssh ${sshAccount} mkdir -p ${outputPath}" + sh "scp -rp ${inputPath} ${sshAccount}:${outputPath}" + } + } } def capellaNightlyUpdateSite(String inputPath, String outputDirName) { - def outputPath = getFullCapellaUpdateSitePath(outputDirName) - def sshAccount = getSSHAccount() - - sshagent (['projects-storage.eclipse.org-bot-ssh']) { - sh "ssh ${sshAccount} mkdir -p ${outputPath}" - sh "scp -rp ${inputPath} ${sshAccount}:${outputPath}" - } + if (isInvalid(outputDirName)) { + log.error("Deployment Error: ${outputDirName} is not recognised") + } + else { + def outputPath = getFullCapellaUpdateSitePath(outputDirName) + def sshAccount = getSSHAccount() + + sshagent (['projects-storage.eclipse.org-bot-ssh']) { + sh "ssh ${sshAccount} mkdir -p ${outputPath}" + sh "scp -rp ${inputPath} ${sshAccount}:${outputPath}" + } + } } def cleanCapellaNightlyArtefacts(String dirName) { - def productPath = getFullCapellaProductPath(dirName) - def updateSitePath = getFullCapellaUpdateSitePath(dirName) - def sshAccount = getSSHAccount() - - sshagent (['projects-storage.eclipse.org-bot-ssh']) { - sh "ssh ${sshAccount} rm -rf ${productPath}" - sh "ssh ${sshAccount} rm -rf ${updateSitePath}" - } + if (isInvalid(dirName)) { + log.error("Deployment Error: ${dirName} is not recognised") + } + else { + + def productPath = getFullCapellaProductPath(dirName) + def updateSitePath = getFullCapellaUpdateSitePath(dirName) + def sshAccount = getSSHAccount() + + sshagent (['projects-storage.eclipse.org-bot-ssh']) { + sh "ssh ${sshAccount} rm -rf ${productPath}" + sh "ssh ${sshAccount} rm -rf ${updateSitePath}" + } + } } def addonNightlyDropins(String inputPath, String outputDirName) { - def addonDirName = getAddonDirName() + def addonDirName = getAddonDirName() - if(addonDirName.isEmpty()) { + if(isInvalid(addonDirName)) { log.error("Deployment Error: ${GIT_URL} repository is not recognised") + + } else if (isInvalid(outputDirName)) { + log.error("Deployment Error: ${outputDirName} is not recognised") } else { def outputPath = getFullAddonDropinsPath(addonDirName, outputDirName) @@ -48,10 +67,13 @@ def addonNightlyDropins(String inputPath, String outputDirName) { } def addonNightlyUpdateSite(String inputPath, String outputDirName) { - def addonDirName = getAddonDirName() + def addonDirName = getAddonDirName() - if(addonDirName.isEmpty()) { + if(isInvalid(addonDirName)) { log.error("Deployment Error: ${GIT_URL} repository is not recognised") + + } else if (isInvalid(outputDirName)) { + log.error("Deployment Error: ${outputDirName} is not recognised") } else { def outputPath = getFullAddonDropinsUpdateSitePath(addonDirName, outputDirName) @@ -65,11 +87,15 @@ def addonNightlyUpdateSite(String inputPath, String outputDirName) { } def addonNightlyProduct(String inputPath, String outputDirName) { - def addonDirName = getAddonDirName() + def addonDirName = getAddonDirName() - if(addonDirName.isEmpty()) { + if(isInvalid(addonDirName)) { log.error("Deployment Error: ${GIT_URL} repository is not recognised") + + } else if (isInvalid(outputDirName)) { + log.error("Deployment Error: ${outputDirName} is not recognised") } + else { def outputPath = getFullAddonProductPath(addonDirName, outputDirName) def sshAccount = getSSHAccount() @@ -84,8 +110,11 @@ def addonNightlyProduct(String inputPath, String outputDirName) { def cleanAddonNightlyArtefacts(String outputDirName) { def addonDirName = getAddonDirName() - if(addonDirName.isEmpty()) { + if(isInvalid(addonDirName)) { log.error("Deployment Error: ${GIT_URL} repository is not recognised") + + } else if (isInvalid(outputDirName)) { + log.error("Deployment Error: ${outputDirName} is not recognised") } else { def dropinPath = getFullAddonDropinsPath(addonDirName, outputDirName) @@ -135,6 +164,10 @@ private def getAddonDirName() { } } +private def isInvalid(path) { + return path.isEmpty() || path.contains('..') +} + private def getSSHAccount() { return "genie.capella@projects-storage.eclipse.org" }