secrets should only get generated if defined in secrets of container.json

Signed-off-by: Simon L <szaimen@e.mail.de>
This commit is contained in:
Simon L 2022-12-25 02:26:32 +01:00
parent 4750fb228f
commit 27bd5ce1a4
3 changed files with 22 additions and 5 deletions

View file

@ -32,7 +32,7 @@ class ConfigurationManager
$this->WriteConfig($config);
}
public function GetSecret(string $secretId) : string {
public function GetAndGenerateSecret(string $secretId) : string {
$config = $this->GetConfig();
if(!isset($config['secrets'][$secretId])) {
$config['secrets'][$secretId] = bin2hex(random_bytes(24));
@ -46,6 +46,15 @@ class ConfigurationManager
return $config['secrets'][$secretId];
}
public function GetSecret(string $secretId) : string {
$config = $this->GetConfig();
if(!isset($config['secrets'][$secretId])) {
$config['secrets'][$secretId] = "";
}
return $config['secrets'][$secretId];
}
private function DoubleSafeBackupSecret(string $borgBackupPassword) : void {
file_put_contents(DataConst::GetBackupSecretFile(), $borgBackupPassword);
}
@ -269,7 +278,7 @@ class ConfigurationManager
}
// Get Instance ID
$instanceID = $this->GetSecret('INSTANCE_ID');
$instanceID = $this->GetAndGenerateSecret('INSTANCE_ID');
// set protocol
if ($port !== '443') {