@c8y/toolkit 1022.9.2 → 1022.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -0
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/delete-tenants.d.ts +2 -0
- package/dist/commands/delete-tenants.js +29 -0
- package/dist/commands/delete-tenants.js.map +1 -0
- package/dist/utils/delete-tenants.d.ts +9 -0
- package/dist/utils/delete-tenants.js +57 -0
- package/dist/utils/delete-tenants.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,6 +20,8 @@ Options:
|
|
|
20
20
|
|
|
21
21
|
Commands:
|
|
22
22
|
deploy [options] <zipFile> Deploy application to Cumulocity
|
|
23
|
+
create-tenant [options] Creates a new subtenant.
|
|
24
|
+
delete-tenants [options] Deletes existing subtenants.
|
|
23
25
|
help [command] display help for command
|
|
24
26
|
```
|
|
25
27
|
|
|
@@ -52,3 +54,54 @@ Options:
|
|
|
52
54
|
|
|
53
55
|
To e.g. deploy a previously built zip file of a plugin package, you could e.g. execute:
|
|
54
56
|
`npx @c8y/toolkit deploy -u "https://demos.cumulocity.com" -U "dummyUser" -P "dummyPassword" -t "t123456" --tags "latest" --rolling-tags --add-web-sdk-stable-tag ./sample-plugin.zip`
|
|
57
|
+
|
|
58
|
+
## Create tenant
|
|
59
|
+
|
|
60
|
+
This cli can be used to create tenants. This might be used inside of CI workflows in order to create tenants to run tests against.
|
|
61
|
+
To get all of the options available simply execute `npx @c8y/toolkit create-tenant -h`.
|
|
62
|
+
This should give you and output like:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
Usage: @c8y/toolkit create-tenant [options]
|
|
66
|
+
|
|
67
|
+
Creates a new subtenant.
|
|
68
|
+
|
|
69
|
+
Options:
|
|
70
|
+
-u, --url <URL> The url of the remote instance. Can also be passed via the "C8Y_URL" environment variable.
|
|
71
|
+
-U, --user <user> Username of the Cumulocity instance. Can also be passed via the "C8Y_USER" environment variable.
|
|
72
|
+
-P, --password <password> Password of the Cumulocity instance. Can also be passed via the "C8Y_PASSWORD" environment variable.
|
|
73
|
+
-t, --tenant <tenant> Tenant of the Cumulocity instance. Can also be passed via the "C8Y_TENANT" environment variable.
|
|
74
|
+
--tenantsNumber <n> The number of tenants to be created, default to 1.
|
|
75
|
+
--tenantUser [value] Username of the created tenant(s).
|
|
76
|
+
--tenantPassword [value] Password of the created tenant(s).
|
|
77
|
+
--domainNamePrefix [value] The tenant name value
|
|
78
|
+
--allowCreateTenants [value] If the created tenant(s) should be allowed to create subtenants (default: true)
|
|
79
|
+
--companyName [value] A scope is added as the company name (default: "e2eTesting tenant")
|
|
80
|
+
--noTenantSuffix [value] If set to true, there will be no number attached to the tenant name (default: false)
|
|
81
|
+
--contactName [value] The tenants contact name. (default: "Mr. Smith")
|
|
82
|
+
--contactPhone [value] The tenants contact phone. (default: "+48123456789")
|
|
83
|
+
--applicationsToBeSubscribed [value] A comma separated list of applications names to be subscribed (default: "")
|
|
84
|
+
-h, --help display help for command
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Delete tenants
|
|
88
|
+
|
|
89
|
+
This cli can be used to delete tenants. This might be used inside of CI workflows in order to delete tenants that have been previously used to run tests against.
|
|
90
|
+
To get all of the options available simply execute `npx @c8y/toolkit delete-tenants -h`.
|
|
91
|
+
This should give you and output like:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
Usage: @c8y/toolkit delete-tenants [options]
|
|
95
|
+
|
|
96
|
+
Deletes existing subtenants.
|
|
97
|
+
|
|
98
|
+
Options:
|
|
99
|
+
-u, --url <URL> The url of the remote instance. Can also be passed via the "C8Y_URL" environment variable.
|
|
100
|
+
-U, --user <user> Username of the Cumulocity instance. Can also be passed via the "C8Y_USER" environment variable.
|
|
101
|
+
-P, --password <password> Password of the Cumulocity instance. Can also be passed via the "C8Y_PASSWORD" environment variable.
|
|
102
|
+
-t, --tenant <tenant> Tenant of the Cumulocity instance. Can also be passed via the "C8Y_TENANT" environment variable.
|
|
103
|
+
-a, --age <age> The age of the tenant in hours since it's creation time
|
|
104
|
+
--companyName <value> A scope is added as the company name. All tenants where the company name includes the provided string, will be deleted. (default: "e2eTesting tenant")
|
|
105
|
+
--includeChildren If set, all subtenants will be deleted as well
|
|
106
|
+
-h, --help display help for command
|
|
107
|
+
```
|
package/dist/cli.js
CHANGED
|
@@ -5,9 +5,11 @@ const commander_1 = require("commander");
|
|
|
5
5
|
const deploy_1 = require("./commands/deploy");
|
|
6
6
|
const package_json_1 = require("./../package.json");
|
|
7
7
|
const create_tenant_1 = require("./commands/create-tenant");
|
|
8
|
+
const delete_tenants_1 = require("./commands/delete-tenants");
|
|
8
9
|
const program = new commander_1.Command();
|
|
9
10
|
program.name(package_json_1.name).description(package_json_1.description).version(package_json_1.version);
|
|
10
11
|
(0, deploy_1.registerDeployCommand)(program);
|
|
11
12
|
(0, create_tenant_1.registerCreateTenantCommand)(program);
|
|
13
|
+
(0, delete_tenants_1.registerDeleteTenantsCommand)(program);
|
|
12
14
|
program.parseAsync(process.argv);
|
|
13
15
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,yCAAoC;AACpC,8CAA0D;AAC1D,oDAA+D;AAC/D,4DAAuE;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,yCAAoC;AACpC,8CAA0D;AAC1D,oDAA+D;AAC/D,4DAAuE;AACvE,8DAAyE;AAEzE,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAC9B,OAAO,CAAC,IAAI,CAAC,mBAAI,CAAC,CAAC,WAAW,CAAC,0BAAW,CAAC,CAAC,OAAO,CAAC,sBAAO,CAAC,CAAC;AAC7D,IAAA,8BAAqB,EAAC,OAAO,CAAC,CAAC;AAC/B,IAAA,2CAA2B,EAAC,OAAO,CAAC,CAAC;AACrC,IAAA,6CAA4B,EAAC,OAAO,CAAC,CAAC;AAEtC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerDeleteTenantsCommand = registerDeleteTenantsCommand;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const helpers_1 = require("../utils/helpers");
|
|
6
|
+
const delete_tenants_1 = require("../utils/delete-tenants");
|
|
7
|
+
function registerDeleteTenantsCommand(program) {
|
|
8
|
+
program
|
|
9
|
+
.command('delete-tenants')
|
|
10
|
+
.description('Deletes existing subtenants.')
|
|
11
|
+
.requiredOption('-u, --url <URL>', constants_1.OPTIONS_CONSTANTS['TXT.URL'], (0, helpers_1.getFromEnvVar)('C8Y_URL'))
|
|
12
|
+
.requiredOption('-U, --user <user>', constants_1.OPTIONS_CONSTANTS['TXT.USERNAME'], (0, helpers_1.getFromEnvVar)('C8Y_USER'))
|
|
13
|
+
.requiredOption('-P, --password <password>', constants_1.OPTIONS_CONSTANTS['TXT.PASSWORD'], (0, helpers_1.getFromEnvVar)('C8Y_PASSWORD'))
|
|
14
|
+
.option('-t, --tenant <tenant>', constants_1.OPTIONS_CONSTANTS['TXT.TENANT'], (0, helpers_1.getFromEnvVar)('C8Y_TENANT'))
|
|
15
|
+
.option('-a, --age <age>', "The age of the tenant in hours since it's creation time", parseInt)
|
|
16
|
+
.requiredOption('--companyName <value>', 'A scope is added as the company name. All tenants where the company name includes the provided string, will be deleted.', 'e2eTesting tenant')
|
|
17
|
+
.option('--includeChildren', 'If set, all subtenants will be deleted as well')
|
|
18
|
+
.action(async (options) => {
|
|
19
|
+
try {
|
|
20
|
+
await (0, delete_tenants_1.deleteTenants)(options);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
console.error('Failed to delete tenants');
|
|
24
|
+
console.error(e);
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=delete-tenants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-tenants.js","sourceRoot":"","sources":["../../src/commands/delete-tenants.ts"],"names":[],"mappings":";;AAKA,oEAiCC;AArCD,4CAAiD;AACjD,8CAAiD;AACjD,4DAAwD;AAExD,SAAgB,4BAA4B,CAAC,OAAgB;IAC3D,OAAO;SACJ,OAAO,CAAC,gBAAgB,CAAC;SACzB,WAAW,CAAC,8BAA8B,CAAC;SAC3C,cAAc,CAAC,iBAAiB,EAAE,6BAAiB,CAAC,SAAS,CAAC,EAAE,IAAA,uBAAa,EAAC,SAAS,CAAC,CAAC;SACzF,cAAc,CACb,mBAAmB,EACnB,6BAAiB,CAAC,cAAc,CAAC,EACjC,IAAA,uBAAa,EAAC,UAAU,CAAC,CAC1B;SACA,cAAc,CACb,2BAA2B,EAC3B,6BAAiB,CAAC,cAAc,CAAC,EACjC,IAAA,uBAAa,EAAC,cAAc,CAAC,CAC9B;SACA,MAAM,CAAC,uBAAuB,EAAE,6BAAiB,CAAC,YAAY,CAAC,EAAE,IAAA,uBAAa,EAAC,YAAY,CAAC,CAAC;SAC7F,MAAM,CAAC,iBAAiB,EAAE,yDAAyD,EAAE,QAAQ,CAAC;SAC9F,cAAc,CACb,uBAAuB,EACvB,yHAAyH,EACzH,mBAAmB,CACpB;SACA,MAAM,CAAC,mBAAmB,EAAE,gDAAgD,CAAC;SAE7E,MAAM,CAAC,KAAK,EAAC,OAAO,EAAC,EAAE;QACtB,IAAI,CAAC;YACH,MAAM,IAAA,8BAAa,EAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAC1C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjB,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deleteTenants = deleteTenants;
|
|
7
|
+
const client_1 = require("./client");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
async function deleteTenants(options) {
|
|
10
|
+
const { user, password, url, tenant } = options;
|
|
11
|
+
const client = await (0, client_1.createClient)({ user, password, url, tenant });
|
|
12
|
+
console.log(chalk_1.default.green('Provided credentials are valid.'));
|
|
13
|
+
const { data: allTenants } = await client.tenant.list({
|
|
14
|
+
pageSize: 2000,
|
|
15
|
+
withApps: false,
|
|
16
|
+
withParents: true
|
|
17
|
+
});
|
|
18
|
+
const { companyName, age, includeChildren } = options;
|
|
19
|
+
const tenantsWithMatchingCompany = allTenants.filter((t) => {
|
|
20
|
+
return t.company && t.company.includes(companyName);
|
|
21
|
+
});
|
|
22
|
+
const milisecondsAgeOffset = age ? age * 60 * 60 * 1000 : 0;
|
|
23
|
+
const minimumAge = new Date(Date.now() - milisecondsAgeOffset);
|
|
24
|
+
const tenantsWithCorrectAge = tenantsWithMatchingCompany.filter((t) => {
|
|
25
|
+
return t.creationTime && new Date(t.creationTime) < minimumAge;
|
|
26
|
+
});
|
|
27
|
+
console.log(chalk_1.default.blue(`Found ${tenantsWithCorrectAge.length} tenants where the company name includes "${companyName}" and which are older than "${minimumAge.toISOString()}"`));
|
|
28
|
+
const childTenantsToRemove = [];
|
|
29
|
+
if (includeChildren) {
|
|
30
|
+
for (const tenant of tenantsWithCorrectAge) {
|
|
31
|
+
const tenantsWhereParentMatches = allTenants.filter(t => t.parent === tenant.id);
|
|
32
|
+
childTenantsToRemove.push(...tenantsWhereParentMatches);
|
|
33
|
+
}
|
|
34
|
+
console.log(chalk_1.default.blue(`Including ${childTenantsToRemove.length} child tenants for deletion...`));
|
|
35
|
+
}
|
|
36
|
+
const allTenantsToDelete = [...childTenantsToRemove, ...tenantsWithCorrectAge];
|
|
37
|
+
let deletionFailures = 0;
|
|
38
|
+
for (const tenant of allTenantsToDelete) {
|
|
39
|
+
console.log(chalk_1.default.blue(`Deleting tenant ${tenant.domain} (${tenant.id})...`));
|
|
40
|
+
try {
|
|
41
|
+
await client.tenant.delete(tenant.id);
|
|
42
|
+
console.log(chalk_1.default.green(`Tenant ${tenant.domain} (${tenant.id}) deleted successfully.`));
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
console.error(chalk_1.default.red(`Failed to delete tenant ${tenant.domain} (${tenant.id}):`), e);
|
|
46
|
+
deletionFailures++;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (deletionFailures > 0) {
|
|
50
|
+
console.error(chalk_1.default.red(`Failed to delete ${deletionFailures} tenants.`));
|
|
51
|
+
throw new Error('Some tenants could not be deleted.');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.log(chalk_1.default.green('All specified tenants deleted successfully.'));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=delete-tenants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-tenants.js","sourceRoot":"","sources":["../../src/utils/delete-tenants.ts"],"names":[],"mappings":";;;;;AAIA,sCAqEC;AAxED,qCAAwC;AACxC,kDAA0B;AAEnB,KAAK,UAAU,aAAa,CAAC,OAQnC;IACC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAEhD,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAY,EAAC,EAAE,IAAI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,CAAC,CAAC;QAC1E,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c8y/toolkit",
|
|
3
|
-
"version": "1022.
|
|
3
|
+
"version": "1022.10.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "Cumulocity GmbH",
|
|
6
6
|
"description": "Toolkit for Cumulocity applications, allows to e.g. deploy an application to an instance of Cumulocity.",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"m2m"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@c8y/client": "1022.
|
|
21
|
+
"@c8y/client": "1022.10.1",
|
|
22
22
|
"chalk": "^4.1.2",
|
|
23
23
|
"commander": "13.1.0",
|
|
24
24
|
"lodash": "4.17.21",
|