Skip to content

Commit b8142ab

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

4 files changed

Lines changed: 124 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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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\SecretService;
11+
use Symfony\Component\Console\Command\Command;
12+
use Symfony\Component\Console\Input\InputArgument;
13+
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Output\OutputInterface;
15+
16+
class Setup extends Command {
17+
public function __construct(
18+
private SecretService $secretService,
19+
) {
20+
parent::__construct();
21+
}
22+
23+
/**
24+
* Configure the command
25+
*
26+
* @return void
27+
*/
28+
protected function configure() {
29+
$this->setName('integration_dropbox:setup')
30+
->addArgument('client_id', InputArgument::REQUIRED)
31+
->addArgument('client_secret', InputArgument::REQUIRED)
32+
->setDescription('Setup the client credentials');
33+
}
34+
35+
/**
36+
* Execute the command
37+
*
38+
* @param InputInterface $input
39+
* @param OutputInterface $output
40+
*
41+
* @return int
42+
*/
43+
protected function execute(InputInterface $input, OutputInterface $output): int {
44+
try {
45+
$this->secretService->setEncryptedAppValue('client_id', $input->getArgument('client_id'));
46+
$this->secretService->setEncryptedAppValue('client_secret', $input->getArgument('client_secret'));
47+
} catch (\Exception $ex) {
48+
$output->writeln('<error>Failed to setup client credentials</error>');
49+
$output->writeln($ex->getMessage());
50+
return 1;
51+
}
52+
53+
return 0;
54+
}
55+
}

lib/Command/SetupUser.php

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

0 commit comments

Comments
 (0)