@sap/cds-dk
Version:
Command line client and development toolkit for the SAP Cloud Application Programming Model
82 lines (57 loc) • 2.43 kB
JavaScript
module.exports = Object.assign(subscribe, {
init: cmd => new (require('../lib/mtx/tenant_action'))(cmd),
options: ['--to', '--user', '--body'],
flags: ['--local', '--resolve-bindings'],
shortcuts: ['-2', '-u', '-l', '-b'],
help: `
# SYNOPSIS
*cds subscribe* <tenant>
Subscribe a tenant to a multitenant SaaS app.
Running *cds subscribe* with a URL is intended for non-productive use only,
including against SaaS apps running on localhost with mock authentication.
# OPTIONS
*-2* | *--to* <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*.
--body
JSON object to be sent as the body of the subscription request.
# 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 subscribe([tenant], options = {}) {
const { getMessage } = require('../lib/mtx/util/logging');
if (!tenant) {
throw getMessage('Tenant not given.', { command: 'subscribe' });
}
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.to) {
throw getMessage('URL cannot be specified when running @sap/cds-mtxs locally.', { command: 'subscribe' });
}
}
const [username, password] = options.user?.split(':') ?? [];
delete options.user;
delete options['resolve-bindings'];
await subscribe.init('subscribe').run({
...options,
username,
password
}, libOptions);
}