@magda/acs-cmd 2.3.3 → 3.0.0-alpha.0

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.
Files changed (43) hide show
  1. package/bin/acs-cmd-admin-set.js +129 -0
  2. package/bin/acs-cmd-admin-unset.js +129 -0
  3. package/bin/acs-cmd-admin.js +63 -0
  4. package/bin/acs-cmd-assign-permission.js +132 -0
  5. package/bin/acs-cmd-assign-role.js +130 -0
  6. package/bin/acs-cmd-assign.js +65 -0
  7. package/bin/acs-cmd-create-operation.js +112 -0
  8. package/bin/acs-cmd-create-permission.js +93 -0
  9. package/bin/acs-cmd-create.js +62 -0
  10. package/bin/acs-cmd-jwt.js +80 -0
  11. package/bin/acs-cmd-list-permissions.js +139 -0
  12. package/bin/acs-cmd-list-resources.js +111 -0
  13. package/bin/acs-cmd-list-roles.js +136 -0
  14. package/bin/acs-cmd-list-users.js +147 -0
  15. package/bin/acs-cmd-list.js +62 -0
  16. package/bin/acs-cmd-remove-permission.js +132 -0
  17. package/bin/acs-cmd-remove-role.js +130 -0
  18. package/bin/acs-cmd-remove.js +65 -0
  19. package/bin/acs-cmd.js +77 -0
  20. package/bin/utils.js +24 -0
  21. package/package.json +17 -13
  22. package/bin/acs-cmd/acs-cmd-admin-set.js +0 -251
  23. package/bin/acs-cmd/acs-cmd-admin-unset.js +0 -252
  24. package/bin/acs-cmd/acs-cmd-admin.js +0 -158
  25. package/bin/acs-cmd/acs-cmd-assign-permission.js +0 -260
  26. package/bin/acs-cmd/acs-cmd-assign-role.js +0 -257
  27. package/bin/acs-cmd/acs-cmd-assign.js +0 -157
  28. package/bin/acs-cmd/acs-cmd-create-operation.js +0 -234
  29. package/bin/acs-cmd/acs-cmd-create-permission.js +0 -241
  30. package/bin/acs-cmd/acs-cmd-create.js +0 -154
  31. package/bin/acs-cmd/acs-cmd-jwt.js +0 -192
  32. package/bin/acs-cmd/acs-cmd-list-permissions.js +0 -267
  33. package/bin/acs-cmd/acs-cmd-list-resources.js +0 -241
  34. package/bin/acs-cmd/acs-cmd-list-roles.js +0 -267
  35. package/bin/acs-cmd/acs-cmd-list-users.js +0 -271
  36. package/bin/acs-cmd/acs-cmd-list.js +0 -155
  37. package/bin/acs-cmd/acs-cmd-remove-permission.js +0 -264
  38. package/bin/acs-cmd/acs-cmd-remove-role.js +0 -260
  39. package/bin/acs-cmd/acs-cmd-remove.js +0 -157
  40. package/bin/acs-cmd/acs-cmd.js +0 -174
  41. package/bin/acs-cmd/utils.js +0 -133
  42. package/bin/db/getDBConfig.js +0 -19
  43. package/bin/db/getDBPool.js +0 -13
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../../node_modules/@magda/esm-utils/dist/esmUtils.js
4
+ import { createRequire } from "module";
5
+ function callsites() {
6
+ const _prepareStackTrace = Error.prepareStackTrace;
7
+ try {
8
+ let result = [];
9
+ Error.prepareStackTrace = (_, callSites) => {
10
+ const callSitesWithoutCurrent = callSites.slice(1);
11
+ result = callSitesWithoutCurrent;
12
+ return callSitesWithoutCurrent;
13
+ };
14
+ new Error().stack;
15
+ return result;
16
+ } finally {
17
+ Error.prepareStackTrace = _prepareStackTrace;
18
+ }
19
+ }
20
+ function callerCallsite({ depth = 0 } = {}) {
21
+ const callers = [];
22
+ const callerFileSet = /* @__PURE__ */ new Set();
23
+ for (const callsite of callsites()) {
24
+ const fileName = callsite.getFileName();
25
+ const hasReceiver = callsite.getTypeName() !== null && fileName !== null;
26
+ if (!callerFileSet.has(fileName)) {
27
+ callerFileSet.add(fileName);
28
+ callers.unshift(callsite);
29
+ }
30
+ if (hasReceiver) {
31
+ return callers[depth];
32
+ }
33
+ }
34
+ }
35
+ function callerpath({ depth = 0 } = {}) {
36
+ const callsite = callerCallsite({ depth });
37
+ return callsite && callsite.getFileName();
38
+ }
39
+ function require2(id) {
40
+ const requireFrom = createRequire(callerpath({ depth: 1 }));
41
+ return requireFrom(id);
42
+ }
43
+
44
+ // ../../scripts/acs-cmd/acs-cmd-create-operation.js
45
+ import { program } from "commander";
46
+ import chalk from "chalk";
47
+
48
+ // ../../scripts/db/getDBPool.js
49
+ import pg from "pg";
50
+
51
+ // ../../scripts/db/getDBConfig.js
52
+ function getDBConfig() {
53
+ const {
54
+ POSTGRES_HOST: host,
55
+ POSTGRES_DB: database,
56
+ POSTGRES_USER: user,
57
+ POSTGRES_PASSWORD: password,
58
+ POSTGRES_PORT: port
59
+ } = process.env;
60
+ return {
61
+ host: host ? host : "localhost",
62
+ database: database ? database : "auth",
63
+ port: port ? port : 5432,
64
+ user: user ? user : "postgres",
65
+ password: password ? password : ""
66
+ };
67
+ }
68
+
69
+ // ../../scripts/db/getDBPool.js
70
+ var pool = new pg.Pool(getDBConfig());
71
+ pool.on("error", function(err, client) {
72
+ console.error("DB Pool Error: ", err.message, err.stack);
73
+ });
74
+ function getDBPool() {
75
+ return pool;
76
+ }
77
+ var getDBPool_default = getDBPool;
78
+
79
+ // ../../scripts/acs-cmd/acs-cmd-create-operation.js
80
+ var pkg = require2("../package.json");
81
+ var pool2 = getDBPool_default();
82
+ program.version(pkg.version).description(`A tool for creating operations. Version: ${pkg.version}`).option("<permission>", "Permission name").option("<uri>", "Operation uri").option("<name>", "Operation name").option("<description>", "Operation description").action(async (permissionName, uri, name, description) => {
83
+ try {
84
+ await pool2.query("BEGIN TRANSACTION");
85
+ const permissionResult = await pool2.query(
86
+ `SELECT id FROM permissions WHERE name = $1`,
87
+ [permissionName]
88
+ );
89
+ if (permissionResult.rows.length === 0) {
90
+ console.log(
91
+ chalk.red("No permission found with name " + permissionName)
92
+ );
93
+ process.exit(1);
94
+ }
95
+ const permissionId = permissionResult.rows[0].id;
96
+ const operationResult = await pool2.query(
97
+ `INSERT INTO operations (uri, name, description) VALUES ($1, $2, $3) RETURNING id`,
98
+ [uri, name, description]
99
+ );
100
+ const operationId = operationResult.rows[0].id;
101
+ await pool2.query(
102
+ `INSERT INTO permission_operations (permission_id, operation_id) VALUES ($1, $2)`,
103
+ [permissionId, operationId]
104
+ );
105
+ await pool2.query("COMMIT");
106
+ console.log(chalk.green("Operation Completed!"));
107
+ } catch (e) {
108
+ await pool2.query("ROLLBACK");
109
+ console.error(chalk.red(`Error: ${e}`));
110
+ }
111
+ process.exit(0);
112
+ }).parse(process.argv);
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../../node_modules/@magda/esm-utils/dist/esmUtils.js
4
+ import { createRequire } from "module";
5
+ function callsites() {
6
+ const _prepareStackTrace = Error.prepareStackTrace;
7
+ try {
8
+ let result = [];
9
+ Error.prepareStackTrace = (_, callSites) => {
10
+ const callSitesWithoutCurrent = callSites.slice(1);
11
+ result = callSitesWithoutCurrent;
12
+ return callSitesWithoutCurrent;
13
+ };
14
+ new Error().stack;
15
+ return result;
16
+ } finally {
17
+ Error.prepareStackTrace = _prepareStackTrace;
18
+ }
19
+ }
20
+ function callerCallsite({ depth = 0 } = {}) {
21
+ const callers = [];
22
+ const callerFileSet = /* @__PURE__ */ new Set();
23
+ for (const callsite of callsites()) {
24
+ const fileName = callsite.getFileName();
25
+ const hasReceiver = callsite.getTypeName() !== null && fileName !== null;
26
+ if (!callerFileSet.has(fileName)) {
27
+ callerFileSet.add(fileName);
28
+ callers.unshift(callsite);
29
+ }
30
+ if (hasReceiver) {
31
+ return callers[depth];
32
+ }
33
+ }
34
+ }
35
+ function callerpath({ depth = 0 } = {}) {
36
+ const callsite = callerCallsite({ depth });
37
+ return callsite && callsite.getFileName();
38
+ }
39
+ function require2(id) {
40
+ const requireFrom = createRequire(callerpath({ depth: 1 }));
41
+ return requireFrom(id);
42
+ }
43
+
44
+ // ../../scripts/acs-cmd/acs-cmd-create-permission.js
45
+ import { program } from "commander";
46
+ import chalk from "chalk";
47
+
48
+ // ../../scripts/db/getDBPool.js
49
+ import pg from "pg";
50
+
51
+ // ../../scripts/db/getDBConfig.js
52
+ function getDBConfig() {
53
+ const {
54
+ POSTGRES_HOST: host,
55
+ POSTGRES_DB: database,
56
+ POSTGRES_USER: user,
57
+ POSTGRES_PASSWORD: password,
58
+ POSTGRES_PORT: port
59
+ } = process.env;
60
+ return {
61
+ host: host ? host : "localhost",
62
+ database: database ? database : "auth",
63
+ port: port ? port : 5432,
64
+ user: user ? user : "postgres",
65
+ password: password ? password : ""
66
+ };
67
+ }
68
+
69
+ // ../../scripts/db/getDBPool.js
70
+ var pool = new pg.Pool(getDBConfig());
71
+ pool.on("error", function(err, client) {
72
+ console.error("DB Pool Error: ", err.message, err.stack);
73
+ });
74
+ function getDBPool() {
75
+ return pool;
76
+ }
77
+ var getDBPool_default = getDBPool;
78
+
79
+ // ../../scripts/acs-cmd/acs-cmd-create-permission.js
80
+ var pkg = require2("../package.json");
81
+ var pool2 = getDBPool_default();
82
+ program.version(pkg.version).description(`A tool for creating permissions. Version: ${pkg.version}`).option("<name>", "Permission name").option("<description>", "Permission description").action(async (name, description) => {
83
+ try {
84
+ await pool2.query(
85
+ `INSERT INTO permissions (name, description) VALUES ($1, $2)`,
86
+ [name, description]
87
+ );
88
+ console.log(chalk.green("Operation Completed!"));
89
+ } catch (e) {
90
+ console.error(chalk.red(`Error: ${e}`));
91
+ }
92
+ process.exit(0);
93
+ }).parse(process.argv);
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../../node_modules/@magda/esm-utils/dist/esmUtils.js
4
+ import { createRequire } from "module";
5
+ function callsites() {
6
+ const _prepareStackTrace = Error.prepareStackTrace;
7
+ try {
8
+ let result = [];
9
+ Error.prepareStackTrace = (_, callSites) => {
10
+ const callSitesWithoutCurrent = callSites.slice(1);
11
+ result = callSitesWithoutCurrent;
12
+ return callSitesWithoutCurrent;
13
+ };
14
+ new Error().stack;
15
+ return result;
16
+ } finally {
17
+ Error.prepareStackTrace = _prepareStackTrace;
18
+ }
19
+ }
20
+ function callerCallsite({ depth = 0 } = {}) {
21
+ const callers = [];
22
+ const callerFileSet = /* @__PURE__ */ new Set();
23
+ for (const callsite of callsites()) {
24
+ const fileName = callsite.getFileName();
25
+ const hasReceiver = callsite.getTypeName() !== null && fileName !== null;
26
+ if (!callerFileSet.has(fileName)) {
27
+ callerFileSet.add(fileName);
28
+ callers.unshift(callsite);
29
+ }
30
+ if (hasReceiver) {
31
+ return callers[depth];
32
+ }
33
+ }
34
+ }
35
+ function callerpath({ depth = 0 } = {}) {
36
+ const callsite = callerCallsite({ depth });
37
+ return callsite && callsite.getFileName();
38
+ }
39
+ function require2(id) {
40
+ const requireFrom = createRequire(callerpath({ depth: 1 }));
41
+ return requireFrom(id);
42
+ }
43
+
44
+ // ../../scripts/acs-cmd/acs-cmd-create.js
45
+ import { program } from "commander";
46
+ import chalk from "chalk";
47
+ var pkg = require2("../package.json");
48
+ program.version(pkg.version).description(
49
+ `A tool for creating magda access control data. Version: ${pkg.version}`
50
+ ).command("permission", "Create permission").command("operation", "Create operation").on("command:*", function(cmds) {
51
+ if (["permission", "operation"].indexOf(cmds[0]) === -1) {
52
+ console.error(
53
+ chalk.red(
54
+ `Invalid command: ${program.args.join(
55
+ " "
56
+ )}
57
+ See --help for a list of available commands.`
58
+ )
59
+ );
60
+ process.exit(1);
61
+ }
62
+ }).parse(process.argv);
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../../node_modules/@magda/esm-utils/dist/esmUtils.js
4
+ import { createRequire } from "module";
5
+ function callsites() {
6
+ const _prepareStackTrace = Error.prepareStackTrace;
7
+ try {
8
+ let result = [];
9
+ Error.prepareStackTrace = (_, callSites) => {
10
+ const callSitesWithoutCurrent = callSites.slice(1);
11
+ result = callSitesWithoutCurrent;
12
+ return callSitesWithoutCurrent;
13
+ };
14
+ new Error().stack;
15
+ return result;
16
+ } finally {
17
+ Error.prepareStackTrace = _prepareStackTrace;
18
+ }
19
+ }
20
+ function callerCallsite({ depth = 0 } = {}) {
21
+ const callers = [];
22
+ const callerFileSet = /* @__PURE__ */ new Set();
23
+ for (const callsite of callsites()) {
24
+ const fileName = callsite.getFileName();
25
+ const hasReceiver = callsite.getTypeName() !== null && fileName !== null;
26
+ if (!callerFileSet.has(fileName)) {
27
+ callerFileSet.add(fileName);
28
+ callers.unshift(callsite);
29
+ }
30
+ if (hasReceiver) {
31
+ return callers[depth];
32
+ }
33
+ }
34
+ }
35
+ function callerpath({ depth = 0 } = {}) {
36
+ const callsite = callerCallsite({ depth });
37
+ return callsite && callsite.getFileName();
38
+ }
39
+ function require2(id) {
40
+ const requireFrom = createRequire(callerpath({ depth: 1 }));
41
+ return requireFrom(id);
42
+ }
43
+
44
+ // ../../scripts/acs-cmd/acs-cmd-jwt.js
45
+ import { program } from "commander";
46
+ import chalk from "chalk";
47
+
48
+ // ../../magda-typescript-common/dist/session/buildJwt.js
49
+ import jwt from "jsonwebtoken";
50
+ function buildJwt(jwtSecret, userId, session = {}) {
51
+ return jwt.sign({ userId, session }, jwtSecret);
52
+ }
53
+
54
+ // ../../scripts/acs-cmd/acs-cmd-jwt.js
55
+ var pkg = require2("../package.json");
56
+ var DEFAULT_JWT_SECRET = "squirrel";
57
+ program.description(
58
+ `calculate JWT token (only for testing purpose). Version: ${pkg.version}`
59
+ ).option("<userId>", "User ID").option(
60
+ "[jwtSecret]",
61
+ "Optional JWT secret. Default value: `" + DEFAULT_JWT_SECRET + "`"
62
+ ).version(pkg.version).action(async (userId, jwtSecret) => {
63
+ try {
64
+ if (process.argv.slice(2).length < 1) {
65
+ program.help();
66
+ }
67
+ console.log(`JWT token for user ${userId} is: `);
68
+ console.log(
69
+ chalk.yellow(
70
+ buildJwt(
71
+ typeof jwtSecret === "string" ? jwtSecret : DEFAULT_JWT_SECRET,
72
+ userId
73
+ )
74
+ )
75
+ );
76
+ } catch (e) {
77
+ console.error(chalk.red(`Error: ${e}`));
78
+ }
79
+ process.exit(0);
80
+ }).parse(process.argv);
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../../node_modules/@magda/esm-utils/dist/esmUtils.js
4
+ import { createRequire } from "module";
5
+ function callsites() {
6
+ const _prepareStackTrace = Error.prepareStackTrace;
7
+ try {
8
+ let result = [];
9
+ Error.prepareStackTrace = (_, callSites) => {
10
+ const callSitesWithoutCurrent = callSites.slice(1);
11
+ result = callSitesWithoutCurrent;
12
+ return callSitesWithoutCurrent;
13
+ };
14
+ new Error().stack;
15
+ return result;
16
+ } finally {
17
+ Error.prepareStackTrace = _prepareStackTrace;
18
+ }
19
+ }
20
+ function callerCallsite({ depth = 0 } = {}) {
21
+ const callers = [];
22
+ const callerFileSet = /* @__PURE__ */ new Set();
23
+ for (const callsite of callsites()) {
24
+ const fileName = callsite.getFileName();
25
+ const hasReceiver = callsite.getTypeName() !== null && fileName !== null;
26
+ if (!callerFileSet.has(fileName)) {
27
+ callerFileSet.add(fileName);
28
+ callers.unshift(callsite);
29
+ }
30
+ if (hasReceiver) {
31
+ return callers[depth];
32
+ }
33
+ }
34
+ }
35
+ function callerpath({ depth = 0 } = {}) {
36
+ const callsite = callerCallsite({ depth });
37
+ return callsite && callsite.getFileName();
38
+ }
39
+ function require2(id) {
40
+ const requireFrom = createRequire(callerpath({ depth: 1 }));
41
+ return requireFrom(id);
42
+ }
43
+
44
+ // ../../scripts/acs-cmd/acs-cmd-list-permissions.js
45
+ import { program } from "commander";
46
+ import chalk from "chalk";
47
+
48
+ // ../../scripts/db/getDBPool.js
49
+ import pg from "pg";
50
+
51
+ // ../../scripts/db/getDBConfig.js
52
+ function getDBConfig() {
53
+ const {
54
+ POSTGRES_HOST: host,
55
+ POSTGRES_DB: database,
56
+ POSTGRES_USER: user,
57
+ POSTGRES_PASSWORD: password,
58
+ POSTGRES_PORT: port
59
+ } = process.env;
60
+ return {
61
+ host: host ? host : "localhost",
62
+ database: database ? database : "auth",
63
+ port: port ? port : 5432,
64
+ user: user ? user : "postgres",
65
+ password: password ? password : ""
66
+ };
67
+ }
68
+
69
+ // ../../scripts/db/getDBPool.js
70
+ var pool = new pg.Pool(getDBConfig());
71
+ pool.on("error", function(err, client) {
72
+ console.error("DB Pool Error: ", err.message, err.stack);
73
+ });
74
+ function getDBPool() {
75
+ return pool;
76
+ }
77
+ var getDBPool_default = getDBPool;
78
+
79
+ // ../../scripts/acs-cmd/acs-cmd-list-permissions.js
80
+ import { table } from "table";
81
+ var pkg = require2("../package.json");
82
+ var pool2 = getDBPool_default();
83
+ program.description("List all permissions").version(pkg.version).action(async () => {
84
+ try {
85
+ const selectFields = ["id", "name", "description"];
86
+ const result = await pool2.query(
87
+ `SELECT ${selectFields.join(", ")} FROM permissions`
88
+ );
89
+ if (!result || !result.rows || !result.rows.length) {
90
+ throw new Error("Cannot find any records!");
91
+ }
92
+ const data = [["ID", "Name", "Description", "Operations"]];
93
+ const options = {
94
+ columns: {
95
+ 0: {
96
+ width: 36
97
+ },
98
+ 1: {
99
+ width: 10
100
+ },
101
+ 2: {
102
+ width: 11
103
+ },
104
+ 3: {
105
+ width: 10
106
+ },
107
+ 4: {
108
+ width: 10
109
+ },
110
+ 5: {
111
+ width: 10
112
+ }
113
+ }
114
+ };
115
+ for (let i = 0; i < result.rows.length; i++) {
116
+ const res = result.rows[i];
117
+ const operations = await getOperationsByPermissionId(res["id"]);
118
+ data.push(
119
+ selectFields.map((k) => res[k]).concat([operations.map((op) => op.uri).join("\n")])
120
+ );
121
+ }
122
+ console.log(table(data, options));
123
+ } catch (e) {
124
+ console.error(chalk.red(`Error: ${e}`));
125
+ }
126
+ process.exit(0);
127
+ }).parse(process.argv);
128
+ async function getOperationsByPermissionId(permissionId) {
129
+ const result = await pool2.query(
130
+ `SELECT op.*
131
+ FROM permission_operations AS pop
132
+ LEFT JOIN operations op ON op.id = pop.operation_id
133
+ WHERE pop.permission_id = $1`,
134
+ [permissionId]
135
+ );
136
+ if (!result || !result.rows || !result.rows.length)
137
+ return [];
138
+ return result.rows;
139
+ }
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../../node_modules/@magda/esm-utils/dist/esmUtils.js
4
+ import { createRequire } from "module";
5
+ function callsites() {
6
+ const _prepareStackTrace = Error.prepareStackTrace;
7
+ try {
8
+ let result = [];
9
+ Error.prepareStackTrace = (_, callSites) => {
10
+ const callSitesWithoutCurrent = callSites.slice(1);
11
+ result = callSitesWithoutCurrent;
12
+ return callSitesWithoutCurrent;
13
+ };
14
+ new Error().stack;
15
+ return result;
16
+ } finally {
17
+ Error.prepareStackTrace = _prepareStackTrace;
18
+ }
19
+ }
20
+ function callerCallsite({ depth = 0 } = {}) {
21
+ const callers = [];
22
+ const callerFileSet = /* @__PURE__ */ new Set();
23
+ for (const callsite of callsites()) {
24
+ const fileName = callsite.getFileName();
25
+ const hasReceiver = callsite.getTypeName() !== null && fileName !== null;
26
+ if (!callerFileSet.has(fileName)) {
27
+ callerFileSet.add(fileName);
28
+ callers.unshift(callsite);
29
+ }
30
+ if (hasReceiver) {
31
+ return callers[depth];
32
+ }
33
+ }
34
+ }
35
+ function callerpath({ depth = 0 } = {}) {
36
+ const callsite = callerCallsite({ depth });
37
+ return callsite && callsite.getFileName();
38
+ }
39
+ function require2(id) {
40
+ const requireFrom = createRequire(callerpath({ depth: 1 }));
41
+ return requireFrom(id);
42
+ }
43
+
44
+ // ../../scripts/acs-cmd/acs-cmd-list-resources.js
45
+ import { program } from "commander";
46
+ import chalk from "chalk";
47
+
48
+ // ../../scripts/db/getDBPool.js
49
+ import pg from "pg";
50
+
51
+ // ../../scripts/db/getDBConfig.js
52
+ function getDBConfig() {
53
+ const {
54
+ POSTGRES_HOST: host,
55
+ POSTGRES_DB: database,
56
+ POSTGRES_USER: user,
57
+ POSTGRES_PASSWORD: password,
58
+ POSTGRES_PORT: port
59
+ } = process.env;
60
+ return {
61
+ host: host ? host : "localhost",
62
+ database: database ? database : "auth",
63
+ port: port ? port : 5432,
64
+ user: user ? user : "postgres",
65
+ password: password ? password : ""
66
+ };
67
+ }
68
+
69
+ // ../../scripts/db/getDBPool.js
70
+ var pool = new pg.Pool(getDBConfig());
71
+ pool.on("error", function(err, client) {
72
+ console.error("DB Pool Error: ", err.message, err.stack);
73
+ });
74
+ function getDBPool() {
75
+ return pool;
76
+ }
77
+ var getDBPool_default = getDBPool;
78
+
79
+ // ../../scripts/acs-cmd/acs-cmd-list-resources.js
80
+ import { table } from "table";
81
+ var pkg = require2("../package.json");
82
+ var pool2 = getDBPool_default();
83
+ program.description("List all resources").version(pkg.version).action(async () => {
84
+ try {
85
+ const result = await pool2.query(`SELECT * FROM resources`);
86
+ if (!result || !result.rows || !result.rows.length) {
87
+ throw new Error("Cannot find any records!");
88
+ }
89
+ const data = [["URI", "Name", "Description", "Operations"]];
90
+ for (let i = 0; i < result.rows.length; i++) {
91
+ const res = result.rows[i];
92
+ res["operations"] = await getOperationsByResourceId(res["id"]);
93
+ res["operations"] = res["operations"].map((op) => op.uri).join("\n");
94
+ delete res["id"];
95
+ data.push(Object.values(res));
96
+ }
97
+ console.log(table(data));
98
+ } catch (e) {
99
+ console.error(chalk.red(`Error: ${e}`));
100
+ }
101
+ process.exit(0);
102
+ }).parse(process.argv);
103
+ async function getOperationsByResourceId(resourceId) {
104
+ const result = await pool2.query(
105
+ `SELECT * FROM operations WHERE resource_id = $1`,
106
+ [resourceId]
107
+ );
108
+ if (!result || !result.rows || !result.rows.length)
109
+ return [];
110
+ return result.rows;
111
+ }