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.
This commit is contained in:
Jeroen De Meerleer 2023-07-09 00:44:21 +02:00
parent f7a2228f26
commit 9977a93874
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
1 changed files with 3 additions and 3 deletions

View File

@ -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 {