feat: Add full SSL support to MongoDB

This commit is contained in:
peaklabs-dev
2025-02-05 22:56:29 +01:00
parent 844f40188a
commit 367eebc9fc
4 changed files with 260 additions and 21 deletions

View File

@@ -243,7 +243,20 @@ class StandaloneMongodb extends BaseModel
protected function internalDbUrl(): Attribute
{
return new Attribute(
get: fn () => "mongodb://{$this->mongo_initdb_root_username}:{$this->mongo_initdb_root_password}@{$this->uuid}:27017/?directConnection=true",
get: function () {
$url = "mongodb://{$this->mongo_initdb_root_username}:{$this->mongo_initdb_root_password}@{$this->uuid}:27017/?directConnection=true";
if ($this->enable_ssl) {
$url .= '&ssl=true';
if (in_array($this->ssl_mode, ['verifyCA', 'verifyFull'])) {
$url .= '&tlsAllowInvalidCertificates=false';
}
if ($this->ssl_mode === 'verifyFull') {
$url .= '&tlsAllowInvalidHostnames=false';
}
}
return $url;
},
);
}
@@ -252,7 +265,18 @@ class StandaloneMongodb extends BaseModel
return new Attribute(
get: function () {
if ($this->is_public && $this->public_port) {
return "mongodb://{$this->mongo_initdb_root_username}:{$this->mongo_initdb_root_password}@{$this->destination->server->getIp}:{$this->public_port}/?directConnection=true";
$url = "mongodb://{$this->mongo_initdb_root_username}:{$this->mongo_initdb_root_password}@{$this->destination->server->getIp}:{$this->public_port}/?directConnection=true";
if ($this->enable_ssl) {
$url .= '&ssl=true';
if (in_array($this->ssl_mode, ['verifyCA', 'verifyFull'])) {
$url .= '&tlsAllowInvalidCertificates=false';
}
if ($this->ssl_mode === 'verifyFull') {
$url .= '&tlsAllowInvalidHostnames=false';
}
}
return $url;
}
return null;