-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
keep "haproxy_password" encrypted in the database
Signed-off-by: Oleksander Piskun <[email protected]>
- Loading branch information
1 parent
cc15ac1
commit 00556a4
Showing
4 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\AppAPI\Migration; | ||
|
||
use Closure; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\IDBConnection; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
use OCP\Security\ICrypto; | ||
|
||
class Version5000Date20241120135411 extends SimpleMigrationStep { | ||
|
||
public function __construct( | ||
private IDBConnection $connection, | ||
private ICrypto $crypto, | ||
) { | ||
} | ||
|
||
/** | ||
* @param IOutput $output | ||
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` | ||
* @param array $options | ||
* | ||
* @return null|ISchemaWrapper | ||
*/ | ||
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { | ||
// encrypt "haproxy_password" in the "ex_apps_daemons" table | ||
$qbSelect = $this->connection->getQueryBuilder(); | ||
$qbSelect->select(['id', 'deploy_config']) | ||
->from('ex_apps_daemons') | ||
->where(1); | ||
$req = $qbSelect->executeQuery(); | ||
|
||
while ($row = $req->fetch()) { | ||
$deployConfig = $row['deploy_config']; | ||
$deployConfig = json_decode($deployConfig, true); | ||
if (!empty($deployConfig['haproxy_password'])) { | ||
$deployConfig['haproxy_password'] = $this->crypto->encrypt($deployConfig['haproxy_password']); | ||
$encodedDeployConfig = json_encode($deployConfig); | ||
$qbUpdate = $this->connection->getQueryBuilder(); | ||
$qbUpdate->update('ex_apps_daemons') | ||
->set('deploy_config', $qbUpdate->createNamedParameter($encodedDeployConfig)) | ||
->where( | ||
$qbUpdate->expr()->eq('id', $qbUpdate->createNamedParameter($row['id'])) | ||
); | ||
$qbUpdate->executeStatement(); | ||
} | ||
} | ||
$req->closeCursor(); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters