legispro-cli 1.0.7
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/LICENSE +21 -0
- package/README.md +696 -0
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/dist/commands/backup/create.d.ts +7 -0
- package/dist/commands/backup/create.js +26 -0
- package/dist/commands/backup/list.d.ts +7 -0
- package/dist/commands/backup/list.js +38 -0
- package/dist/commands/collection/add.d.ts +12 -0
- package/dist/commands/collection/add.js +108 -0
- package/dist/commands/collection/create.d.ts +14 -0
- package/dist/commands/collection/create.js +132 -0
- package/dist/commands/collection/delete.d.ts +10 -0
- package/dist/commands/collection/delete.js +53 -0
- package/dist/commands/collection/download.d.ts +11 -0
- package/dist/commands/collection/download.js +87 -0
- package/dist/commands/collection/get.d.ts +10 -0
- package/dist/commands/collection/get.js +54 -0
- package/dist/commands/collection/list.d.ts +7 -0
- package/dist/commands/collection/list.js +25 -0
- package/dist/commands/collection/perms.d.ts +12 -0
- package/dist/commands/collection/perms.js +82 -0
- package/dist/commands/collection/update.d.ts +16 -0
- package/dist/commands/collection/update.js +174 -0
- package/dist/commands/collection/upload.d.ts +12 -0
- package/dist/commands/collection/upload.js +127 -0
- package/dist/commands/config/get.d.ts +1 -0
- package/dist/commands/config/get.js +19 -0
- package/dist/commands/config/set.d.ts +1 -0
- package/dist/commands/config/set.js +125 -0
- package/dist/commands/db/init.d.ts +7 -0
- package/dist/commands/db/init.js +90 -0
- package/dist/commands/db/memory.d.ts +7 -0
- package/dist/commands/db/memory.js +27 -0
- package/dist/commands/db/uptime.d.ts +7 -0
- package/dist/commands/db/uptime.js +17 -0
- package/dist/commands/db/version.d.ts +7 -0
- package/dist/commands/db/version.js +17 -0
- package/dist/commands/document/copy.d.ts +7 -0
- package/dist/commands/document/copy.js +35 -0
- package/dist/commands/document/list.d.ts +7 -0
- package/dist/commands/document/list.js +34 -0
- package/dist/commands/group/create.d.ts +14 -0
- package/dist/commands/group/create.js +132 -0
- package/dist/commands/group/delete.d.ts +10 -0
- package/dist/commands/group/delete.js +50 -0
- package/dist/commands/group/get.d.ts +10 -0
- package/dist/commands/group/get.js +51 -0
- package/dist/commands/group/list.d.ts +7 -0
- package/dist/commands/group/list.js +20 -0
- package/dist/commands/group/update.d.ts +14 -0
- package/dist/commands/group/update.js +132 -0
- package/dist/commands/locks/add.d.ts +7 -0
- package/dist/commands/locks/add.js +80 -0
- package/dist/commands/locks/clear.d.ts +7 -0
- package/dist/commands/locks/clear.js +23 -0
- package/dist/commands/locks/list.d.ts +7 -0
- package/dist/commands/locks/list.js +86 -0
- package/dist/commands/services/health.d.ts +8 -0
- package/dist/commands/services/health.js +66 -0
- package/dist/commands/user/create.d.ts +26 -0
- package/dist/commands/user/create.js +374 -0
- package/dist/commands/user/delete.d.ts +10 -0
- package/dist/commands/user/delete.js +58 -0
- package/dist/commands/user/get.d.ts +10 -0
- package/dist/commands/user/get.js +53 -0
- package/dist/commands/user/list.d.ts +7 -0
- package/dist/commands/user/list.js +24 -0
- package/dist/commands/user/login.d.ts +13 -0
- package/dist/commands/user/login.js +93 -0
- package/dist/commands/user/update.d.ts +25 -0
- package/dist/commands/user/update.js +267 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/lib/fusiondb-client.d.ts +52 -0
- package/dist/lib/fusiondb-client.js +655 -0
- package/dist/lib/rclone-client.d.ts +11 -0
- package/dist/lib/rclone-client.js +41 -0
- package/dist/lib/types.d.ts +79 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.js +7 -0
- package/dist/lib/xml-templates.d.ts +6 -0
- package/dist/lib/xml-templates.js +66 -0
- package/oclif.manifest.json +1063 -0
- package/package.json +98 -0
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const utils_1 = require("../../lib/utils");
|
|
6
|
+
const xml_templates_1 = require("../../lib/xml-templates");
|
|
7
|
+
const enquirer_1 = require("enquirer");
|
|
8
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
9
|
+
const ora_1 = tslib_1.__importDefault(require("ora"));
|
|
10
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
|
+
class UserCreate extends core_1.Command {
|
|
12
|
+
async run() {
|
|
13
|
+
const configFile = path_1.default.join(this.config.configDir, 'config.json');
|
|
14
|
+
const env = require(configFile);
|
|
15
|
+
utils_1.client.setConfig(this);
|
|
16
|
+
const { flags } = await this.parse(UserCreate);
|
|
17
|
+
// prompts
|
|
18
|
+
if (!flags.username) {
|
|
19
|
+
const name_answer = await (0, enquirer_1.prompt)([
|
|
20
|
+
{
|
|
21
|
+
type: 'input',
|
|
22
|
+
name: 'username',
|
|
23
|
+
message: 'Username',
|
|
24
|
+
required: true
|
|
25
|
+
},
|
|
26
|
+
]);
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
flags.username = name_answer['username'];
|
|
29
|
+
const res = await (0, enquirer_1.prompt)([
|
|
30
|
+
{
|
|
31
|
+
type: 'password',
|
|
32
|
+
name: 'password',
|
|
33
|
+
message: 'Password',
|
|
34
|
+
required: true
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'input',
|
|
38
|
+
name: 'groups',
|
|
39
|
+
message: 'Group membership',
|
|
40
|
+
initial: `users,${flags.username},${env.group}`,
|
|
41
|
+
required: true
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: 'input',
|
|
45
|
+
name: 'primaryGroup',
|
|
46
|
+
message: 'Primary group',
|
|
47
|
+
initial: flags.username,
|
|
48
|
+
required: true
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: 'confirm',
|
|
52
|
+
name: 'enabled',
|
|
53
|
+
message: 'Enabled',
|
|
54
|
+
initial: 'Y',
|
|
55
|
+
required: true
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: 'confirm',
|
|
59
|
+
name: 'expired',
|
|
60
|
+
message: 'Expired',
|
|
61
|
+
initial: 'N',
|
|
62
|
+
required: true
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'confirm',
|
|
66
|
+
name: 'scratchpad',
|
|
67
|
+
message: 'Add scratchpad',
|
|
68
|
+
initial: 'Y',
|
|
69
|
+
required: true
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: 'input',
|
|
73
|
+
name: 'firstName',
|
|
74
|
+
message: 'First name',
|
|
75
|
+
required: false,
|
|
76
|
+
skip: true
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: 'input',
|
|
80
|
+
name: 'lastName',
|
|
81
|
+
message: 'Last name',
|
|
82
|
+
required: false,
|
|
83
|
+
skip: true
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: 'input',
|
|
87
|
+
name: 'fullName',
|
|
88
|
+
message: 'Full name',
|
|
89
|
+
required: false,
|
|
90
|
+
skip: true
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
type: 'input',
|
|
94
|
+
name: 'alias',
|
|
95
|
+
message: 'Alias',
|
|
96
|
+
required: false,
|
|
97
|
+
skip: true
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
type: 'input',
|
|
101
|
+
name: 'email',
|
|
102
|
+
message: 'Email',
|
|
103
|
+
required: false,
|
|
104
|
+
skip: true
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
type: 'input',
|
|
108
|
+
name: 'country',
|
|
109
|
+
message: 'Country',
|
|
110
|
+
required: false,
|
|
111
|
+
skip: true
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
type: 'input',
|
|
115
|
+
name: 'language',
|
|
116
|
+
message: 'Language',
|
|
117
|
+
required: false,
|
|
118
|
+
skip: true
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
type: 'input',
|
|
122
|
+
name: 'timezone',
|
|
123
|
+
message: 'Timezone',
|
|
124
|
+
required: false,
|
|
125
|
+
skip: true
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
type: 'input',
|
|
129
|
+
name: 'description',
|
|
130
|
+
message: 'Description',
|
|
131
|
+
required: false,
|
|
132
|
+
skip: true
|
|
133
|
+
},
|
|
134
|
+
]);
|
|
135
|
+
for (const key in res) {
|
|
136
|
+
if (res.hasOwnProperty(key)) {
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
flags[key] = res[key];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (flags.username && flags.password) {
|
|
143
|
+
const Spinner = (0, ora_1.default)({
|
|
144
|
+
text: `${chalk_1.default.bold.blue('Creating user...')}`
|
|
145
|
+
}).start();
|
|
146
|
+
let scratchpad_uri = "/db/repository/" + flags.username + "/akn-" + env.group + "-data-scratchpad.xml";
|
|
147
|
+
let isEnabled = true;
|
|
148
|
+
let isExpired = false;
|
|
149
|
+
let umask = 18;
|
|
150
|
+
let password = 'changeme';
|
|
151
|
+
let primaryGroup = env.group;
|
|
152
|
+
let group_list = ['users', flags.username, env.group];
|
|
153
|
+
if (flags.groups) {
|
|
154
|
+
group_list = `${flags.groups}`.split(",");
|
|
155
|
+
}
|
|
156
|
+
let meta = [];
|
|
157
|
+
if (flags.alias) {
|
|
158
|
+
meta.push({
|
|
159
|
+
key: "http://axschema.org/namePerson/friendly",
|
|
160
|
+
value: flags.alias
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (flags.timezone) {
|
|
164
|
+
meta.push({
|
|
165
|
+
key: "http://axschema.org/pref/timezone",
|
|
166
|
+
value: flags.timezone
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (flags.firstName) {
|
|
170
|
+
meta.push({
|
|
171
|
+
key: "http://axschema.org/namePerson/first",
|
|
172
|
+
value: flags.firstName
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
if (flags.lastName) {
|
|
176
|
+
meta.push({
|
|
177
|
+
key: "http://axschema.org/namePerson/last",
|
|
178
|
+
value: flags.lastName
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (flags.fullName) {
|
|
182
|
+
meta.push({
|
|
183
|
+
key: "http://axschema.org/namePerson",
|
|
184
|
+
value: flags.fullName
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
if (flags.email) {
|
|
188
|
+
meta.push({
|
|
189
|
+
key: "http://axschema.org/contact/email",
|
|
190
|
+
value: flags.email
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (flags.description) {
|
|
194
|
+
meta.push({
|
|
195
|
+
key: "http://exist-db.org/security/description",
|
|
196
|
+
value: flags.description
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (flags.language) {
|
|
200
|
+
meta.push({
|
|
201
|
+
key: "http://axschema.org/pref/language",
|
|
202
|
+
value: flags.language
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if (flags.country) {
|
|
206
|
+
meta.push({
|
|
207
|
+
key: "http://axschema.org/contact/country/home",
|
|
208
|
+
value: flags.country
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
if (flags.enabled) {
|
|
212
|
+
isEnabled = flags.enabled;
|
|
213
|
+
}
|
|
214
|
+
if (flags.expired) {
|
|
215
|
+
isExpired = flags.expired;
|
|
216
|
+
}
|
|
217
|
+
if (flags.umask) {
|
|
218
|
+
umask = flags.umask;
|
|
219
|
+
}
|
|
220
|
+
if (flags.password) {
|
|
221
|
+
password = flags.password;
|
|
222
|
+
}
|
|
223
|
+
if (flags.primaryGroup) {
|
|
224
|
+
primaryGroup = flags.primaryGroup;
|
|
225
|
+
}
|
|
226
|
+
let userGroup = {
|
|
227
|
+
groupName: flags.username,
|
|
228
|
+
managers: [flags.username],
|
|
229
|
+
metadata: []
|
|
230
|
+
};
|
|
231
|
+
let RIPEMD160 = require('ripemd160');
|
|
232
|
+
password = new RIPEMD160().update(password).digest('base64');
|
|
233
|
+
let user = {
|
|
234
|
+
userName: flags.username,
|
|
235
|
+
password: password,
|
|
236
|
+
primaryGroup: primaryGroup,
|
|
237
|
+
groups: group_list,
|
|
238
|
+
metadata: meta,
|
|
239
|
+
expired: isExpired,
|
|
240
|
+
enabled: isEnabled,
|
|
241
|
+
umask: umask
|
|
242
|
+
};
|
|
243
|
+
let check_user_response = await utils_1.client.getUser(flags.username);
|
|
244
|
+
if (check_user_response.status === 200) {
|
|
245
|
+
Spinner.stopAndPersist({
|
|
246
|
+
symbol: "✨",
|
|
247
|
+
text: `${chalk_1.default.bold(chalk_1.default.red(`User '${flags.username}' exists already.`))}`
|
|
248
|
+
});
|
|
249
|
+
this.exit();
|
|
250
|
+
}
|
|
251
|
+
// 1. create user
|
|
252
|
+
let create_user_response = await utils_1.client.createUser(user);
|
|
253
|
+
// 2. create user group (need user first)
|
|
254
|
+
let create_user_group_response = await utils_1.client.createGroup(userGroup);
|
|
255
|
+
// 3. update user with new user group
|
|
256
|
+
let update_user_response = await utils_1.client.createUser(user);
|
|
257
|
+
// 4. create user collection
|
|
258
|
+
let user_collection = {
|
|
259
|
+
uri: '/db/repository/' + flags.username,
|
|
260
|
+
owner: flags.username,
|
|
261
|
+
group: primaryGroup,
|
|
262
|
+
mode: 'rwxrwsr-T',
|
|
263
|
+
};
|
|
264
|
+
let create_response = await utils_1.client.createCollection(user_collection);
|
|
265
|
+
let modify_response = await utils_1.client.modifyCollection(user_collection);
|
|
266
|
+
// todo: add a .project.xml
|
|
267
|
+
// 5. create scratchpad xml in user's collection
|
|
268
|
+
if (flags.scratchpad) {
|
|
269
|
+
const buffer = Buffer.from(xml_templates_1.XmlTemplates.scratchpad.replace(/{{username}}/gmi, flags.username), "utf-8");
|
|
270
|
+
let scratchpad_document = {
|
|
271
|
+
uri: scratchpad_uri,
|
|
272
|
+
mediaType: "application/xml",
|
|
273
|
+
binaryDoc: false,
|
|
274
|
+
owner: flags.username,
|
|
275
|
+
group: env.group,
|
|
276
|
+
mode: "rw-r--r--"
|
|
277
|
+
};
|
|
278
|
+
let scratchpad_response = await utils_1.client.createDocument(scratchpad_uri, buffer);
|
|
279
|
+
let update_doc_props_response = await utils_1.client.updateDocumentProperties(scratchpad_document);
|
|
280
|
+
}
|
|
281
|
+
// 6. user list
|
|
282
|
+
let get_user_response = await utils_1.client.getUser(flags.username);
|
|
283
|
+
Spinner.stopAndPersist({
|
|
284
|
+
symbol: "✨",
|
|
285
|
+
text: `${chalk_1.default.bold(chalk_1.default.green('User created'))}`
|
|
286
|
+
});
|
|
287
|
+
if (get_user_response.status == 200) {
|
|
288
|
+
this.log(JSON.stringify(get_user_response.data, null, 2));
|
|
289
|
+
this.exit();
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
this.log(`${chalk_1.default.red("Error:")} user ${flags.username} doesn't exist.`);
|
|
293
|
+
this.exit();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
UserCreate.flags = {
|
|
299
|
+
username: core_1.Flags.string({
|
|
300
|
+
description: 'Username to create',
|
|
301
|
+
required: false
|
|
302
|
+
}),
|
|
303
|
+
groups: core_1.Flags.string({
|
|
304
|
+
description: 'Group memberships',
|
|
305
|
+
required: false
|
|
306
|
+
}),
|
|
307
|
+
email: core_1.Flags.string({
|
|
308
|
+
description: 'email',
|
|
309
|
+
required: false
|
|
310
|
+
}),
|
|
311
|
+
language: core_1.Flags.string({
|
|
312
|
+
description: 'language',
|
|
313
|
+
required: false
|
|
314
|
+
}),
|
|
315
|
+
description: core_1.Flags.string({
|
|
316
|
+
description: 'description',
|
|
317
|
+
required: false
|
|
318
|
+
}),
|
|
319
|
+
password: core_1.Flags.string({
|
|
320
|
+
description: 'password',
|
|
321
|
+
required: false
|
|
322
|
+
}),
|
|
323
|
+
primaryGroup: core_1.Flags.string({
|
|
324
|
+
description: 'primary group',
|
|
325
|
+
required: false
|
|
326
|
+
}),
|
|
327
|
+
alias: core_1.Flags.string({
|
|
328
|
+
description: 'alias',
|
|
329
|
+
required: false
|
|
330
|
+
}),
|
|
331
|
+
timezone: core_1.Flags.string({
|
|
332
|
+
description: 'timezone',
|
|
333
|
+
required: false
|
|
334
|
+
}),
|
|
335
|
+
firstName: core_1.Flags.string({
|
|
336
|
+
description: 'first name',
|
|
337
|
+
required: false
|
|
338
|
+
}),
|
|
339
|
+
lastName: core_1.Flags.string({
|
|
340
|
+
description: 'last name',
|
|
341
|
+
required: false
|
|
342
|
+
}),
|
|
343
|
+
country: core_1.Flags.string({
|
|
344
|
+
description: 'country',
|
|
345
|
+
required: false
|
|
346
|
+
}),
|
|
347
|
+
fullName: core_1.Flags.string({
|
|
348
|
+
description: 'full name',
|
|
349
|
+
required: false
|
|
350
|
+
}),
|
|
351
|
+
enabled: core_1.Flags.boolean({
|
|
352
|
+
description: 'User enabled?',
|
|
353
|
+
required: false,
|
|
354
|
+
default: true
|
|
355
|
+
}),
|
|
356
|
+
expired: core_1.Flags.boolean({
|
|
357
|
+
description: 'User expired?',
|
|
358
|
+
required: false,
|
|
359
|
+
default: false
|
|
360
|
+
}),
|
|
361
|
+
umask: core_1.Flags.integer({
|
|
362
|
+
description: 'User umask',
|
|
363
|
+
required: false,
|
|
364
|
+
default: 18
|
|
365
|
+
}),
|
|
366
|
+
scratchpad: core_1.Flags.boolean({
|
|
367
|
+
description: 'Add scratchpad xml',
|
|
368
|
+
required: false,
|
|
369
|
+
default: true
|
|
370
|
+
}),
|
|
371
|
+
};
|
|
372
|
+
UserCreate.description = "Create, delete and update users";
|
|
373
|
+
UserCreate.examples = [`$ legispro user:create --name demo --password secret`,];
|
|
374
|
+
exports.default = UserCreate;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
declare class UserDelete extends Command {
|
|
3
|
+
run(): Promise<void>;
|
|
4
|
+
static flags: {
|
|
5
|
+
username: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
6
|
+
};
|
|
7
|
+
static description: string;
|
|
8
|
+
static examples: string[];
|
|
9
|
+
}
|
|
10
|
+
export default UserDelete;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const utils_1 = require("../../lib/utils");
|
|
6
|
+
const enquirer_1 = require("enquirer");
|
|
7
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
8
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
|
+
class UserDelete extends core_1.Command {
|
|
10
|
+
async run() {
|
|
11
|
+
const configFile = path_1.default.join(this.config.configDir, 'config.json');
|
|
12
|
+
const env = require(configFile);
|
|
13
|
+
utils_1.client.setConfig(this);
|
|
14
|
+
const { flags } = await this.parse(UserDelete);
|
|
15
|
+
// prompts
|
|
16
|
+
if (!flags.username) {
|
|
17
|
+
const res = await (0, enquirer_1.prompt)([
|
|
18
|
+
{
|
|
19
|
+
type: 'input',
|
|
20
|
+
name: 'username',
|
|
21
|
+
message: 'What user would you like to delete?',
|
|
22
|
+
required: true
|
|
23
|
+
}
|
|
24
|
+
]);
|
|
25
|
+
for (const key in res) {
|
|
26
|
+
if (res.hasOwnProperty(key)) {
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
flags[key] = res[key];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (flags.username) {
|
|
33
|
+
let delete_user_response = await utils_1.client.deleteUser(flags.username);
|
|
34
|
+
// console.log(delete_user_response);
|
|
35
|
+
if (delete_user_response.status == 204) {
|
|
36
|
+
let delete_user_group_response = await utils_1.client.deleteGroup(flags.username);
|
|
37
|
+
let delete_user_collection_response = await utils_1.client.deleteCollection(`/db/repository/${flags.username}`);
|
|
38
|
+
this.log(`The user ${chalk_1.default.green(flags.username)} has been deleted.`);
|
|
39
|
+
this.exit();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// this.log(delete_user_response);
|
|
43
|
+
this.log(`Error deleting ${chalk_1.default.green(flags.username)}: (${delete_user_response.statusText})`);
|
|
44
|
+
this.exit();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
UserDelete.flags = {
|
|
50
|
+
username: core_1.Flags.string({
|
|
51
|
+
char: 'u',
|
|
52
|
+
description: 'Username to delete',
|
|
53
|
+
required: false
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
UserDelete.description = "Delete a user";
|
|
57
|
+
UserDelete.examples = [`$ legispro user:delete --username demo`,];
|
|
58
|
+
exports.default = UserDelete;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
declare class UserGet extends Command {
|
|
3
|
+
run(): Promise<void>;
|
|
4
|
+
static flags: {
|
|
5
|
+
username: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
6
|
+
};
|
|
7
|
+
static description: string;
|
|
8
|
+
static examples: string[];
|
|
9
|
+
}
|
|
10
|
+
export default UserGet;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const utils_1 = require("../../lib/utils");
|
|
6
|
+
const enquirer_1 = require("enquirer");
|
|
7
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
8
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
|
+
class UserGet extends core_1.Command {
|
|
10
|
+
async run() {
|
|
11
|
+
const configFile = path_1.default.join(this.config.configDir, 'config.json');
|
|
12
|
+
const env = require(configFile);
|
|
13
|
+
utils_1.client.setConfig(this);
|
|
14
|
+
const { flags } = await this.parse(UserGet);
|
|
15
|
+
// prompts
|
|
16
|
+
if (!flags.username) {
|
|
17
|
+
const res = await (0, enquirer_1.prompt)([
|
|
18
|
+
{
|
|
19
|
+
type: 'input',
|
|
20
|
+
name: 'username',
|
|
21
|
+
message: 'Username',
|
|
22
|
+
required: true
|
|
23
|
+
}
|
|
24
|
+
]);
|
|
25
|
+
for (const key in res) {
|
|
26
|
+
if (res.hasOwnProperty(key)) {
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
flags[key] = res[key];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (flags.username) {
|
|
33
|
+
let res = await utils_1.client.getUser(flags.username);
|
|
34
|
+
if (res.status == 200) {
|
|
35
|
+
this.log(JSON.stringify(res.data, null, 2));
|
|
36
|
+
this.exit();
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.log(`${chalk_1.default.red("Error:")} user ${flags.username} doesn't exist.`);
|
|
40
|
+
this.exit();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
UserGet.flags = {
|
|
46
|
+
username: core_1.Flags.string({
|
|
47
|
+
description: 'Username to fetch',
|
|
48
|
+
required: false
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
UserGet.description = "Get user information";
|
|
52
|
+
UserGet.examples = [`$ legispro user:get --username demo`,];
|
|
53
|
+
exports.default = UserGet;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const utils_1 = require("../../lib/utils");
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
class UserList extends core_1.Command {
|
|
8
|
+
async run() {
|
|
9
|
+
const configFile = path_1.default.join(this.config.configDir, 'config.json');
|
|
10
|
+
const env = require(configFile);
|
|
11
|
+
utils_1.client.setConfig(this);
|
|
12
|
+
let names = await utils_1.client.getUsers();
|
|
13
|
+
// const users: User[] = [];
|
|
14
|
+
// for (let name of names) {
|
|
15
|
+
// users.push({userName: name})
|
|
16
|
+
// }
|
|
17
|
+
// this.log(JSON.stringify(users, null, 2));
|
|
18
|
+
this.log(names);
|
|
19
|
+
this.exit();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
UserList.description = "Get list of all users";
|
|
23
|
+
UserList.examples = [`$ legispro user:list`,];
|
|
24
|
+
exports.default = UserList;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
declare class UserLogin extends Command {
|
|
3
|
+
get(baseUrl: string, url: string, headers: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
4
|
+
getCollection(baseUrl: string, uri: string, headers: any): Promise<unknown>;
|
|
5
|
+
run(): Promise<void>;
|
|
6
|
+
static flags: {
|
|
7
|
+
username: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
|
+
password: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
|
+
};
|
|
10
|
+
static description: string;
|
|
11
|
+
static examples: string[];
|
|
12
|
+
}
|
|
13
|
+
export default UserLogin;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const enquirer_1 = require("enquirer");
|
|
6
|
+
const utils_1 = require("../../lib/utils");
|
|
7
|
+
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
8
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
9
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
|
+
const treeify = require('treeify');
|
|
11
|
+
class UserLogin extends core_1.Command {
|
|
12
|
+
get(baseUrl, url, headers) {
|
|
13
|
+
return (0, axios_1.default)({
|
|
14
|
+
method: 'GET',
|
|
15
|
+
url: baseUrl + "/exist/restxq/fusiondb" + url,
|
|
16
|
+
headers: headers
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async getCollection(baseUrl, uri, headers) {
|
|
20
|
+
try {
|
|
21
|
+
const response = await this.get(baseUrl, "/explorer?uri=" + uri, headers);
|
|
22
|
+
return response.data;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error.response.status !== 200) {
|
|
26
|
+
this.log(`${chalk_1.default.red("Login failed: bad password.")}`);
|
|
27
|
+
this.exit();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async run() {
|
|
32
|
+
const configFile = path_1.default.join(this.config.configDir, 'config.json');
|
|
33
|
+
const env = require(configFile);
|
|
34
|
+
utils_1.client.setConfig(this);
|
|
35
|
+
const { flags } = await this.parse(UserLogin);
|
|
36
|
+
// prompts
|
|
37
|
+
if (!flags.username || !flags.password) {
|
|
38
|
+
const res = await (0, enquirer_1.prompt)([
|
|
39
|
+
{
|
|
40
|
+
type: 'input',
|
|
41
|
+
name: 'username',
|
|
42
|
+
message: 'Username',
|
|
43
|
+
required: true
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: 'password',
|
|
47
|
+
name: 'password',
|
|
48
|
+
message: 'Password',
|
|
49
|
+
required: true
|
|
50
|
+
}
|
|
51
|
+
]);
|
|
52
|
+
for (const key in res) {
|
|
53
|
+
if (res.hasOwnProperty(key)) {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
flags[key] = res[key];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (flags.username && flags.password) {
|
|
60
|
+
// check if user exists first
|
|
61
|
+
let user_exists_response = await utils_1.client.getUser(flags.username);
|
|
62
|
+
if (user_exists_response.data.userName != flags.username) {
|
|
63
|
+
this.log(`${chalk_1.default.red("Login failed: user doesn't exist.")}`);
|
|
64
|
+
this.exit();
|
|
65
|
+
}
|
|
66
|
+
// login with user credentials and list user collection contents
|
|
67
|
+
const auth = Buffer.from(`${flags.username}:${flags.password}`).toString('base64');
|
|
68
|
+
const headers = {
|
|
69
|
+
"Authorization": "Basic " + auth,
|
|
70
|
+
"content-type": "application/json",
|
|
71
|
+
};
|
|
72
|
+
let user_collection_uri = `/db/repository/${flags.username}`;
|
|
73
|
+
let base_url = env.protocol + "://" + env.hostname + ":" + env.port;
|
|
74
|
+
let response = await this.getCollection(base_url, user_collection_uri, headers);
|
|
75
|
+
this.log(treeify.asTree(response, true));
|
|
76
|
+
this.log(`Login for ${chalk_1.default.green(flags.username)} succeeded.`);
|
|
77
|
+
this.exit();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
UserLogin.flags = {
|
|
82
|
+
username: core_1.Flags.string({
|
|
83
|
+
description: 'Username to create',
|
|
84
|
+
required: false
|
|
85
|
+
}),
|
|
86
|
+
password: core_1.Flags.string({
|
|
87
|
+
description: 'password',
|
|
88
|
+
required: false
|
|
89
|
+
}),
|
|
90
|
+
};
|
|
91
|
+
UserLogin.description = "Test a user login";
|
|
92
|
+
UserLogin.examples = [`$ legispro user:login --username=demo --password=secret`,];
|
|
93
|
+
exports.default = UserLogin;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
declare class UserUpdate extends Command {
|
|
3
|
+
run(): Promise<void>;
|
|
4
|
+
static flags: {
|
|
5
|
+
username: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
6
|
+
groups: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
|
+
email: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
|
+
language: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
|
+
description: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
|
+
password: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
|
+
primaryGroup: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
|
+
alias: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
|
+
timezone: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
14
|
+
firstName: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
15
|
+
lastName: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
16
|
+
country: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
17
|
+
fullName: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
18
|
+
enabled: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
19
|
+
expired: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
20
|
+
umask: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
21
|
+
};
|
|
22
|
+
static description: string;
|
|
23
|
+
static examples: string[];
|
|
24
|
+
}
|
|
25
|
+
export default UserUpdate;
|