@sap/cds-dk
Version:
Command line client and development toolkit for the SAP Cloud Application Programming Model
79 lines (56 loc) • 2.36 kB
JavaScript
module.exports = Object.assign(unsubscribe, {
init: cmd => new (require('../lib/mtx/tenant_action'))(cmd),
options: ['--from', '--user'],
flags: ['--local', '--resolve-bindings'],
shortcuts: ['-f', '-u', '-l', '-b'],
help: `
# SYNOPSIS
*cds unsubscribe* <tenant>
Unsubscribe a tenant from a multitenant SaaS app.
Running *cds unsubscribe* with a URL is intended for non-productive use
only, including against SaaS apps running on localhost with mock
authentication.
# OPTIONS
*-f* | *--from* <url>
Specify the URL of the SaaS app. Determined from the current user's
active CDS or Cloud Foundry login by default.
*-u* | *--user* <name>[:[<password>]]
Username and optionally password for authentication with Basic Auth in
test scenarios.
Only relevant if <url> is given. May be omitted in case of dummy
authentication.
Tokens saved with *cds login* are not used for this command.
*-l* | *--local*
Run a locally-installed @sap/cds-mtxs and connect to it instead of a
URL. Ignore settings saved with *cds login*.
*-b* | *--resolve-bindings*
Resolve remote service bindings configured via *cds bind*.
# SEE ALSO
*cds login* for more information on authentication options.
*cds login* to save project settings and Basic-Auth data, simplifying multiple runs of this command.
`});
async function unsubscribe([tenant], options = {}) {
const { getMessage } = require('../lib/mtx/util/logging');
if (!tenant) {
throw getMessage('Tenant not given.', { command: 'unsubscribe' });
}
const libOptions = { tenant };
if (options.local) {
libOptions.local = true;
delete options.local;
if (options.user) {
throw getMessage('Username cannot be specified when running @sap/cds-mtxs locally.', { command: 'subscribe' });
}
if (options.from) {
throw getMessage('URL cannot be specified when running @sap/cds-mtxs locally.', { command: 'unsubscribe' });
}
}
const [username, password] = options.user?.split(':') ?? [];
delete options.user;
delete options['resolve-bindings'];
await unsubscribe.init('unsubscribe').run({
...options,
username,
password
}, libOptions);
}