Skip to content

Commit 1487034

Browse files
committed
fix(ci): Use commands to setup accounts
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent ee1c17d commit 1487034

4 files changed

Lines changed: 126 additions & 16 deletions

File tree

.github/workflows/integration-test.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,6 @@ jobs:
6464
git submodule update --init
6565
php occ maintenance:install --verbose --admin-user admin --admin-pass admin
6666
67-
- name: Prepare config (will be encrypted by migration)
68-
working-directory: server/
69-
env:
70-
DROPBOX_CONFIG: ${{ secrets.DROPBOX_CONFIG }}
71-
OAUTH_CLIENT_ID: ${{ secrets.OAUTH_CLIENT_ID }}
72-
OAUTH_CLIENT_SECRET: ${{ secrets.OAUTH_CLIENT_SECRET }}
73-
run: |
74-
echo $DROPBOX_CONFIG > config.json
75-
sudo apt install jq sqlite3
76-
sqlite3 data/owncloud.db "INSERT INTO oc_preferences ( userid, appid, configkey, configvalue, type) VALUES ('admin', 'integration_dropbox', 'account_id', $(cat config.json | jq '.config.account_id'), 1);"
77-
sqlite3 data/owncloud.db "INSERT INTO oc_preferences ( userid, appid, configkey, configvalue, type) VALUES ('admin', 'integration_dropbox', 'token', $(cat config.json | jq '.config.token'), 1);"
78-
sqlite3 data/owncloud.db "INSERT INTO oc_preferences ( userid, appid, configkey, configvalue, type) VALUES ('admin', 'integration_dropbox', 'refresh_token', $(cat config.json | jq '.config.refresh_token'), 1);"
79-
sqlite3 data/owncloud.db "INSERT INTO oc_preferences ( userid, appid, configkey, configvalue, type) VALUES ('admin', 'integration_dropbox', 'importing_dropbox', '1', 1);"
80-
sqlite3 data/owncloud.db "INSERT INTO oc_appconfig ( appid, configkey, configvalue, type) VALUES ('integration_dropbox', 'client_id', '$OAUTH_CLIENT_ID', 4);"
81-
sqlite3 data/owncloud.db "INSERT INTO oc_appconfig ( appid, configkey, configvalue, type) VALUES ('integration_dropbox', 'client_secret', '$OAUTH_CLIENT_SECRET', 4);"
82-
8367
- name: Checkout app
8468
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
8569
with:
@@ -104,7 +88,14 @@ jobs:
10488

10589
- name: Run import
10690
working-directory: server/
91+
env:
92+
DROPBOX_CONFIG: ${{ secrets.DROPBOX_CONFIG }}
93+
OAUTH_CLIENT_ID: ${{ secrets.OAUTH_CLIENT_ID }}
94+
OAUTH_CLIENT_SECRET: ${{ secrets.OAUTH_CLIENT_SECRET }}
10795
run: |
96+
echo $DROPBOX_CONFIG > config.json
97+
php occ integration_dropbox:setup $OAUTH_CLIENT_ID $OAUTH_CLIENT_SECRET
98+
php occ integration_dropbox:setup-user admin "$(cat config.json | jq '.config.account_id' | sed 's/["'\'']//g')" "$(cat config.json | jq '.config.refresh_token' | sed 's/["'\'']//g')"
10899
php occ integration_dropbox:start-import admin
109100
for run in {1..10}; do date; echo "run $run starting"; php cron.php; ls -lh data/admin/files/Dropbox\ import/ ; echo "run $run done"; done
110101
date

appinfo/info.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
</dependencies>
2525
<commands>
2626
<command>OCA\Dropbox\Command\StartImport</command>
27+
<command>OCA\Dropbox\Command\Setup</command>
28+
<command>OCA\Dropbox\Command\SetupUser</command>
2729
</commands>
2830
<settings>
2931
<admin>OCA\Dropbox\Settings\Admin</admin>

lib/Command/Setup.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
namespace OCA\Dropbox\Command;
9+
10+
use OCA\Dropbox\Service\DropboxStorageAPIService;
11+
use OCA\Dropbox\Service\SecretService;
12+
use Symfony\Component\Console\Command\Command;
13+
use Symfony\Component\Console\Input\InputArgument;
14+
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
17+
class Setup extends Command {
18+
public function __construct(
19+
private SecretService $secretService,
20+
) {
21+
parent::__construct();
22+
}
23+
24+
/**
25+
* Configure the command
26+
*
27+
* @return void
28+
*/
29+
protected function configure() {
30+
$this->setName('integration_dropbox:setup')
31+
->addArgument('client_id', InputArgument::REQUIRED)
32+
->addArgument('client_secret', InputArgument::REQUIRED)
33+
->setDescription('Setup the client credentials');
34+
}
35+
36+
/**
37+
* Execute the command
38+
*
39+
* @param InputInterface $input
40+
* @param OutputInterface $output
41+
*
42+
* @return int
43+
*/
44+
protected function execute(InputInterface $input, OutputInterface $output): int {
45+
try {
46+
$this->secretService->setEncryptedAppValue('client_id', $input->getArgument('client_id'));
47+
$this->secretService->setEncryptedAppValue('client_secret', $input->getArgument('client_secret'));
48+
} catch (\Exception $ex) {
49+
$output->writeln('<error>Failed to setup client credentials</error>');
50+
$output->writeln($ex->getMessage());
51+
return 1;
52+
}
53+
54+
return 0;
55+
}
56+
}

lib/Command/SetupUser.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
namespace OCA\Dropbox\Command;
9+
10+
use OCA\Dropbox\AppInfo\Application;
11+
use OCA\Dropbox\Service\DropboxStorageAPIService;
12+
use OCA\Dropbox\Service\SecretService;
13+
use OCP\Config\IUserConfig;
14+
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Input\InputArgument;
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Output\OutputInterface;
18+
19+
class SetupUser extends Command {
20+
public function __construct(
21+
private SecretService $secretService,
22+
private IUserConfig $userConfig,
23+
) {
24+
parent::__construct();
25+
}
26+
27+
/**
28+
* Configure the command
29+
*
30+
* @return void
31+
*/
32+
protected function configure() {
33+
$this->setName('integration_dropbox:setup-user')
34+
->addArgument('userId', InputArgument::REQUIRED)
35+
->addArgument('accountId', InputArgument::REQUIRED)
36+
->addArgument('refresh_token', InputArgument::REQUIRED)
37+
->setDescription('Setup the client credentials');
38+
}
39+
40+
/**
41+
* Execute the command
42+
*
43+
* @param InputInterface $input
44+
* @param OutputInterface $output
45+
*
46+
* @return int
47+
*/
48+
protected function execute(InputInterface $input, OutputInterface $output): int {
49+
try {
50+
$this->userConfig->setValueString($input->getArgument('userId'), Application::APP_ID, 'account_id', $input->getArgument('accountId'), lazy: true);
51+
$this->secretService->setEncryptedUserValue($input->getArgument('userId'), 'refresh_token', $input->getArgument('refresh_token'));
52+
$this->secretService->setEncryptedUserValue($input->getArgument('userId'), 'token', 'abc');
53+
} catch (\Exception $ex) {
54+
$output->writeln('<error>Failed to setup client credentials</error>');
55+
$output->writeln($ex->getMessage());
56+
return 1;
57+
}
58+
59+
return 0;
60+
}
61+
}

0 commit comments

Comments
 (0)