fix: encrypt mongodb password

This commit is contained in:
Andras Bacsai 2023-10-24 15:40:29 +02:00
parent 72421d692b
commit 6e73f7f2e4

View File

@ -42,6 +42,20 @@ protected static function booted()
}); });
} }
public function mongoInitdbRootPassword(): Attribute
{
return Attribute::make(
get: function ($value) {
try {
return decrypt($value);
} catch (\Throwable $th) {
$this->mongo_initdb_root_password = encrypt($value);
$this->save();
return $value;
}
}
);
}
public function portsMappings(): Attribute public function portsMappings(): Attribute
{ {
return Attribute::make( return Attribute::make(
@ -63,7 +77,8 @@ public function type(): string
{ {
return 'standalone-mongodb'; return 'standalone-mongodb';
} }
public function getDbUrl(bool $useInternal = false) { public function getDbUrl(bool $useInternal = false)
{
if ($this->is_public && !$useInternal) { if ($this->is_public && !$useInternal) {
return "mongodb://{$this->mongo_initdb_root_username}:{$this->mongo_initdb_root_password}@{$this->destination->server->getIp}:{$this->public_port}/?directConnection=true"; return "mongodb://{$this->mongo_initdb_root_username}:{$this->mongo_initdb_root_password}@{$this->destination->server->getIp}:{$this->public_port}/?directConnection=true";
} else { } else {