Skip to content

Commit

Permalink
Add logic to migrate users' credentials
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Oct 4, 2023
1 parent 30c7c47 commit ef2bb90
Showing 1 changed file with 53 additions and 11 deletions.
64 changes: 53 additions & 11 deletions apps/files_external/lib/Command/MigrateOc.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln("Successfully migrated");
}

$passwords = $this->getV2StoragePasswords();

if (count($passwords)) {
$output->writeln("Found <info>" . count($passwords) . "</info> stored passwords that need re-encoding");
foreach ($passwords as $id => $password) {
$decoded = $this->decodePassword($password);
if (!$dryRun) {
$this->setStorageConfig($id, $this->encryptPassword($decoded));
}
}
}
$this->migrateV2StoragePasswords()
$this->migrateUserCredentials()

Check failure on line 108 in apps/files_external/lib/Command/MigrateOc.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParseError

apps/files_external/lib/Command/MigrateOc.php:108:3: ParseError: Syntax error, unexpected T_VARIABLE on line 108 (see https://psalm.dev/173)

Check failure

Code scanning / Psalm

ParseError Error

Syntax error, unexpected T_VARIABLE on line 108

return 0;

Check failure on line 110 in apps/files_external/lib/Command/MigrateOc.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParseError

apps/files_external/lib/Command/MigrateOc.php:110:3: ParseError: Syntax error, unexpected T_RETURN on line 110 (see https://psalm.dev/173)

Check failure

Code scanning / Psalm

ParseError Error

Syntax error, unexpected T_RETURN on line 110
}
Expand Down Expand Up @@ -167,6 +158,20 @@ private function getV2StoragePasswords(): array {
return $configs;
}

private function migrateV2StoragePasswords(): void {
$passwords = $this->getV2StoragePasswords();

if (count($passwords)) {
$output->writeln("Found <info>" . count($passwords) . "</info> stored passwords that need re-encoding");

Check failure on line 165 in apps/files_external/lib/Command/MigrateOc.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedVariable

apps/files_external/lib/Command/MigrateOc.php:165:4: UndefinedVariable: Cannot find referenced variable $output (see https://psalm.dev/024)

Check failure

Code scanning / Psalm

UndefinedVariable Error

Cannot find referenced variable $output
foreach ($passwords as $id => $password) {
$decoded = $this->decodePassword($password);
if (!$dryRun) {

Check failure on line 168 in apps/files_external/lib/Command/MigrateOc.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedVariable

apps/files_external/lib/Command/MigrateOc.php:168:10: UndefinedVariable: Cannot find referenced variable $dryRun (see https://psalm.dev/024)

Check failure

Code scanning / Psalm

UndefinedVariable Error

Cannot find referenced variable $dryRun
$this->setStorageConfig($id, $this->encryptPassword($decoded));
}
}
}
}

private function setStorageConfig(int $id, string $value) {

Check notice

Code scanning / Psalm

MissingReturnType Note

Method OCA\Files_External\Command\MigrateOc::setStorageConfig does not have a return type, expecting void
$query = $this->connection->getQueryBuilder();
$query->update('external_config')
Expand All @@ -175,6 +180,43 @@ private function setStorageConfig(int $id, string $value) {
$query->executeStatement();
}

/**
* @return array<int, string>
*/
private function getUserCredentials(): array {
$query = $this->connection->getQueryBuilder();
$query->select('user', 'identifier', 'credentials')
->from('credentials');

return $query->executeQuery()->fetchAll();
}

private function migrateUserCredentials(): void {
$passwords = $this->getV2StoragePasswords();

if (count($passwords)) {
$output->writeln("Found <info>" . count($passwords) . "</info> stored user credentials that need re-encoding");

Check failure on line 198 in apps/files_external/lib/Command/MigrateOc.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedVariable

apps/files_external/lib/Command/MigrateOc.php:198:4: UndefinedVariable: Cannot find referenced variable $output (see https://psalm.dev/024)

Check failure

Code scanning / Psalm

UndefinedVariable Error

Cannot find referenced variable $output
foreach ($passwords as $passwordRow) {
$decoded = $this->decodePassword($passwordRow["credentials"]);

Check failure on line 200 in apps/files_external/lib/Command/MigrateOc.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArrayOffset

apps/files_external/lib/Command/MigrateOc.php:200:38: InvalidArrayOffset: Cannot access value on variable $passwordRow using offset value of 'credentials', expecting int (see https://psalm.dev/115)

Check failure

Code scanning / Psalm

InvalidArrayOffset Error

Cannot access value on variable $passwordRow using offset value of 'credentials', expecting int
if (!$dryRun) {

Check failure on line 201 in apps/files_external/lib/Command/MigrateOc.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedVariable

apps/files_external/lib/Command/MigrateOc.php:201:10: UndefinedVariable: Cannot find referenced variable $dryRun (see https://psalm.dev/024)

Check failure

Code scanning / Psalm

UndefinedVariable Error

Cannot find referenced variable $dryRun
$this->setStorageCredentials($passwordRow, $this->encryptPassword($decoded));

Check failure on line 202 in apps/files_external/lib/Command/MigrateOc.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

apps/files_external/lib/Command/MigrateOc.php:202:35: InvalidArgument: Argument 1 of OCA\Files_External\Command\MigrateOc::setStorageCredentials expects array<array-key, mixed>, but string provided (see https://psalm.dev/004)

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 1 of OCA\Files_External\Command\MigrateOc::setStorageCredentials expects array<array-key, mixed>, but string provided
}
}
}
}

private function setStorageCredentials(array $row, string $encryptedPassword) {

Check notice

Code scanning / Psalm

MissingReturnType Note

Method OCA\Files_External\Command\MigrateOc::setStorageCredentials does not have a return type, expecting void
$query = $this->connection->getQueryBuilder();

$query->insert('storages_credentials')
->values([
'user' => $query->createNamedParameter($row['user']),
'identifier' => $query->createNamedParameter($row['identifier']),
'credentials' => $query->createNamedParameter($encryptedPassword),
])
->executeStatement();
}

private function setStorageId(string $old, string $new): bool {
$query = $this->connection->getQueryBuilder();
$query->update('storages')
Expand Down

0 comments on commit ef2bb90

Please sign in to comment.