From 9977a938749b43c6e3d107377c01df8871825e91 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Sun, 9 Jul 2023 00:44:21 +0200 Subject: [PATCH] Refactor JobRepository to decrypt secret values in commands This commit modifies the JobRepository class to decrypt secret values in commands. It replaces placeholders with decrypted values using the Secret::decrypt() function. This change ensures that sensitive information is not exposed in plain text within the commands. --- src/Repository/JobRepository.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Repository/JobRepository.php b/src/Repository/JobRepository.php index 8f41040..3e2bc35 100644 --- a/src/Repository/JobRepository.php +++ b/src/Repository/JobRepository.php @@ -239,7 +239,7 @@ class JobRepository extends EntityRepository $command = $job->getData('command'); if(!empty($job->getData('vars'))) { foreach ($job->getData('vars') as $key => $var) { - $command = str_replace('{' . $key . '}', $var['value'], $job->getData('command')); + $command = str_replace('{' . $key . '}', ($var['issecret'] ? Secret::decrypt(base64_decode($var['value'])) : $var['value']), $job->getData('command')); } } @@ -336,7 +336,7 @@ class JobRepository extends EntityRepository if (!empty($job->getData('vars'))) { foreach ($job->getData('vars') as $key => $var) { - $rebootcommand = str_replace('{' . $key . '}', $var['value'], $rebootcommand); + $rebootcommand = str_replace('{' . $key . '}', ($var['issecret'] ? Secret::decrypt(base64_decode($var['value'])) : $var['value']), $rebootcommand); } } @@ -385,7 +385,7 @@ class JobRepository extends EntityRepository $getservicescommand = $job->getData('getservices-command'); if (!empty($job->getData('vars'))) { foreach ($job->getData('vars') as $key => $var) { - $getservicescommand = str_replace('{' . $key . '}', $var['value'], $job->getData('getservices-command')); + $getservicescommand = str_replace('{' . $key . '}', ($var['issecret'] ? Secret::decrypt(base64_decode($var['value'])) : $var['value']), $job->getData('getservices-command')); } } try {