mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 01:22:54 +00:00
feat: copy connector
This commit is contained in:
50
backend/copy-connector/src/cli.ts
Normal file
50
backend/copy-connector/src/cli.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2018, 2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {Command} from 'commander';
|
||||
import {version} from '../package.json';
|
||||
import {copy} from './copy.js';
|
||||
import {SCThingType, STAPPS_CORE_VERSION} from '@openstapps/core';
|
||||
import {Client, ConnectorClient, HttpClient} from '@openstapps/api';
|
||||
|
||||
new Command()
|
||||
.command('run <backendURL> <origin> <licensePlate>')
|
||||
.argument('<backendUrl>', 'The URL of the StApps deployment', 'http://localhost:3000')
|
||||
.argument(
|
||||
'<foreignBackendUrl>',
|
||||
'The URL of the backend to copy the data from',
|
||||
'https://mobile.server.uni-frankfurt.de',
|
||||
)
|
||||
.argument('<types>', 'The type (RegExp full match)', '.*')
|
||||
.argument('<batchSize>', 'Batch Size', 100)
|
||||
.version(version)
|
||||
.action(async (backendUrl: string, foreignBackendUrl: string, types: string, batchSize: number) => {
|
||||
const client = new HttpClient();
|
||||
const apiIn = new Client(client, foreignBackendUrl, STAPPS_CORE_VERSION);
|
||||
const apiOut = new ConnectorClient(client, backendUrl);
|
||||
|
||||
const indexResponse = await apiIn.handshake(STAPPS_CORE_VERSION);
|
||||
const origin = new URL(foreignBackendUrl).host.replaceAll(/[^a-zA-Z0-9-]/g, '-');
|
||||
const licensePlate = indexResponse.backend.namespace;
|
||||
const source = `${licensePlate}-${origin}`;
|
||||
|
||||
for (const type of Object.values(SCThingType)) {
|
||||
if (!new RegExp(`^${types}$`).test(type)) continue;
|
||||
await copy(apiIn, apiOut, source, type, batchSize);
|
||||
}
|
||||
Logger.ok('Done');
|
||||
})
|
||||
.addHelpCommand()
|
||||
.parse(process.argv);
|
||||
Reference in New Issue
Block a user