@magda/acs-cmd 2.3.2 → 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
@@ -1,271 +0,0 @@
1
- #!/usr/bin/env node
2
- (function webpackUniversalModuleDefinition(root, factory) {
3
- if(typeof exports === 'object' && typeof module === 'object')
4
- module.exports = factory();
5
- else if(typeof define === 'function' && define.amd)
6
- define([], factory);
7
- else {
8
- var a = factory();
9
- for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
10
- }
11
- })(global, function() {
12
- return /******/ (function(modules) { // webpackBootstrap
13
- /******/ // The module cache
14
- /******/ var installedModules = {};
15
- /******/
16
- /******/ // The require function
17
- /******/ function __webpack_require__(moduleId) {
18
- /******/
19
- /******/ // Check if module is in cache
20
- /******/ if(installedModules[moduleId]) {
21
- /******/ return installedModules[moduleId].exports;
22
- /******/ }
23
- /******/ // Create a new module (and put it into the cache)
24
- /******/ var module = installedModules[moduleId] = {
25
- /******/ i: moduleId,
26
- /******/ l: false,
27
- /******/ exports: {}
28
- /******/ };
29
- /******/
30
- /******/ // Execute the module function
31
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
32
- /******/
33
- /******/ // Flag the module as loaded
34
- /******/ module.l = true;
35
- /******/
36
- /******/ // Return the exports of the module
37
- /******/ return module.exports;
38
- /******/ }
39
- /******/
40
- /******/
41
- /******/ // expose the modules object (__webpack_modules__)
42
- /******/ __webpack_require__.m = modules;
43
- /******/
44
- /******/ // expose the module cache
45
- /******/ __webpack_require__.c = installedModules;
46
- /******/
47
- /******/ // define getter function for harmony exports
48
- /******/ __webpack_require__.d = function(exports, name, getter) {
49
- /******/ if(!__webpack_require__.o(exports, name)) {
50
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
51
- /******/ }
52
- /******/ };
53
- /******/
54
- /******/ // define __esModule on exports
55
- /******/ __webpack_require__.r = function(exports) {
56
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
57
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
58
- /******/ }
59
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
60
- /******/ };
61
- /******/
62
- /******/ // create a fake namespace object
63
- /******/ // mode & 1: value is a module id, require it
64
- /******/ // mode & 2: merge all properties of value into the ns
65
- /******/ // mode & 4: return value when already ns object
66
- /******/ // mode & 8|1: behave like require
67
- /******/ __webpack_require__.t = function(value, mode) {
68
- /******/ if(mode & 1) value = __webpack_require__(value);
69
- /******/ if(mode & 8) return value;
70
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
71
- /******/ var ns = Object.create(null);
72
- /******/ __webpack_require__.r(ns);
73
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
74
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
75
- /******/ return ns;
76
- /******/ };
77
- /******/
78
- /******/ // getDefaultExport function for compatibility with non-harmony modules
79
- /******/ __webpack_require__.n = function(module) {
80
- /******/ var getter = module && module.__esModule ?
81
- /******/ function getDefault() { return module['default']; } :
82
- /******/ function getModuleExports() { return module; };
83
- /******/ __webpack_require__.d(getter, 'a', getter);
84
- /******/ return getter;
85
- /******/ };
86
- /******/
87
- /******/ // Object.prototype.hasOwnProperty.call
88
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
89
- /******/
90
- /******/ // __webpack_public_path__
91
- /******/ __webpack_require__.p = "";
92
- /******/
93
- /******/
94
- /******/ // Load entry module and return exports
95
- /******/ return __webpack_require__(__webpack_require__.s = 24);
96
- /******/ })
97
- /************************************************************************/
98
- /******/ ({
99
-
100
- /***/ 0:
101
- /***/ (function(module, exports) {
102
-
103
- module.exports = require("../../package.json");
104
-
105
- /***/ }),
106
-
107
- /***/ 1:
108
- /***/ (function(module, exports) {
109
-
110
- module.exports = require("commander");
111
-
112
- /***/ }),
113
-
114
- /***/ 2:
115
- /***/ (function(module, exports) {
116
-
117
- module.exports = require("chalk");
118
-
119
- /***/ }),
120
-
121
- /***/ 24:
122
- /***/ (function(module, exports, __webpack_require__) {
123
-
124
-
125
- const pkg = __webpack_require__(0);
126
- const program = __webpack_require__(1);
127
- const chalk = __webpack_require__(2);
128
- const getDBPool = __webpack_require__(3);
129
- const { table } = __webpack_require__(7);
130
-
131
- const pool = getDBPool();
132
-
133
- program
134
- .description("List all users")
135
- .version(pkg.version)
136
- .action(async () => {
137
- try {
138
- const selectFields = ["id", "displayName", "orgUnitId"];
139
- const result = await pool.query(
140
- `SELECT ${selectFields
141
- .map((n) => `"${n}"`)
142
- .join(", ")} FROM users`
143
- );
144
- if (!result || !result.rows || !result.rows.length) {
145
- throw new Error("Cannot find any records!");
146
- }
147
-
148
- const data = [["ID", "Name", "Org Unit", "Roles"]];
149
- const options = {
150
- columns: {
151
- 0: {
152
- width: 36
153
- },
154
- 1: {
155
- width: 15
156
- },
157
- 2: {
158
- width: 20
159
- },
160
- 3: {
161
- width: 37
162
- }
163
- }
164
- };
165
- for (let i = 0; i < result.rows.length; i++) {
166
- const user = result.rows[i];
167
- const roles = await getRolesByUserId(user["id"]);
168
- const row = selectFields
169
- .map((k) => user[k])
170
- .concat([
171
- roles.map((r) => `${r.id}:\n${r.name}`).join("\n\n")
172
- ]);
173
- row[2] = await getOrgUnitNameById(row[2]);
174
- data.push(row);
175
- }
176
- console.log(table(data, options));
177
- } catch (e) {
178
- console.error(chalk.red(`Error: ${e}`));
179
- }
180
- process.exit(0);
181
- })
182
- .parse(process.argv);
183
-
184
- async function getRolesByUserId(userId) {
185
- const result = await pool.query(
186
- `SELECT r.*
187
- FROM user_roles AS ur
188
- LEFT JOIN roles r ON r.id = ur.role_id
189
- WHERE ur.user_id = $1`,
190
- [userId]
191
- );
192
- if (!result || !result.rows || !result.rows.length) return [];
193
- return result.rows;
194
- }
195
-
196
- async function getOrgUnitNameById(id) {
197
- const result = await pool.query(
198
- `SELECT name
199
- FROM org_units
200
- WHERE id = $1`,
201
- [id]
202
- );
203
- if (!result || !result.rows || !result.rows.length) return null;
204
- return result.rows[0]["name"];
205
- }
206
-
207
-
208
- /***/ }),
209
-
210
- /***/ 3:
211
- /***/ (function(module, exports, __webpack_require__) {
212
-
213
- const pg = __webpack_require__(4);
214
- const getDBConfig = __webpack_require__(5);
215
-
216
- const pool = new pg.Pool(getDBConfig());
217
- pool.on("error", function (err, client) {
218
- console.error("DB Pool Error: ", err.message, err.stack);
219
- });
220
-
221
- function getDBPool() {
222
- return pool;
223
- }
224
-
225
- module.exports = getDBPool;
226
-
227
-
228
- /***/ }),
229
-
230
- /***/ 4:
231
- /***/ (function(module, exports) {
232
-
233
- module.exports = require("pg");
234
-
235
- /***/ }),
236
-
237
- /***/ 5:
238
- /***/ (function(module, exports) {
239
-
240
- function getDBConfig() {
241
- const {
242
- POSTGRES_HOST: host,
243
- POSTGRES_DB: database,
244
- POSTGRES_USER: user,
245
- POSTGRES_PASSWORD: password,
246
- POSTGRES_PORT: port
247
- } = process.env;
248
-
249
- return {
250
- host: host ? host : "localhost",
251
- database: database ? database : "auth",
252
- port: port ? port : 5432,
253
- user: user ? user : "postgres",
254
- password: password ? password : ""
255
- };
256
- }
257
-
258
- module.exports = getDBConfig;
259
-
260
-
261
- /***/ }),
262
-
263
- /***/ 7:
264
- /***/ (function(module, exports) {
265
-
266
- module.exports = require("table");
267
-
268
- /***/ })
269
-
270
- /******/ });
271
- });
@@ -1,155 +0,0 @@
1
- #!/usr/bin/env node
2
- (function webpackUniversalModuleDefinition(root, factory) {
3
- if(typeof exports === 'object' && typeof module === 'object')
4
- module.exports = factory();
5
- else if(typeof define === 'function' && define.amd)
6
- define([], factory);
7
- else {
8
- var a = factory();
9
- for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
10
- }
11
- })(global, function() {
12
- return /******/ (function(modules) { // webpackBootstrap
13
- /******/ // The module cache
14
- /******/ var installedModules = {};
15
- /******/
16
- /******/ // The require function
17
- /******/ function __webpack_require__(moduleId) {
18
- /******/
19
- /******/ // Check if module is in cache
20
- /******/ if(installedModules[moduleId]) {
21
- /******/ return installedModules[moduleId].exports;
22
- /******/ }
23
- /******/ // Create a new module (and put it into the cache)
24
- /******/ var module = installedModules[moduleId] = {
25
- /******/ i: moduleId,
26
- /******/ l: false,
27
- /******/ exports: {}
28
- /******/ };
29
- /******/
30
- /******/ // Execute the module function
31
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
32
- /******/
33
- /******/ // Flag the module as loaded
34
- /******/ module.l = true;
35
- /******/
36
- /******/ // Return the exports of the module
37
- /******/ return module.exports;
38
- /******/ }
39
- /******/
40
- /******/
41
- /******/ // expose the modules object (__webpack_modules__)
42
- /******/ __webpack_require__.m = modules;
43
- /******/
44
- /******/ // expose the module cache
45
- /******/ __webpack_require__.c = installedModules;
46
- /******/
47
- /******/ // define getter function for harmony exports
48
- /******/ __webpack_require__.d = function(exports, name, getter) {
49
- /******/ if(!__webpack_require__.o(exports, name)) {
50
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
51
- /******/ }
52
- /******/ };
53
- /******/
54
- /******/ // define __esModule on exports
55
- /******/ __webpack_require__.r = function(exports) {
56
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
57
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
58
- /******/ }
59
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
60
- /******/ };
61
- /******/
62
- /******/ // create a fake namespace object
63
- /******/ // mode & 1: value is a module id, require it
64
- /******/ // mode & 2: merge all properties of value into the ns
65
- /******/ // mode & 4: return value when already ns object
66
- /******/ // mode & 8|1: behave like require
67
- /******/ __webpack_require__.t = function(value, mode) {
68
- /******/ if(mode & 1) value = __webpack_require__(value);
69
- /******/ if(mode & 8) return value;
70
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
71
- /******/ var ns = Object.create(null);
72
- /******/ __webpack_require__.r(ns);
73
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
74
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
75
- /******/ return ns;
76
- /******/ };
77
- /******/
78
- /******/ // getDefaultExport function for compatibility with non-harmony modules
79
- /******/ __webpack_require__.n = function(module) {
80
- /******/ var getter = module && module.__esModule ?
81
- /******/ function getDefault() { return module['default']; } :
82
- /******/ function getModuleExports() { return module; };
83
- /******/ __webpack_require__.d(getter, 'a', getter);
84
- /******/ return getter;
85
- /******/ };
86
- /******/
87
- /******/ // Object.prototype.hasOwnProperty.call
88
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
89
- /******/
90
- /******/ // __webpack_public_path__
91
- /******/ __webpack_require__.p = "";
92
- /******/
93
- /******/
94
- /******/ // Load entry module and return exports
95
- /******/ return __webpack_require__(__webpack_require__.s = 25);
96
- /******/ })
97
- /************************************************************************/
98
- /******/ ({
99
-
100
- /***/ 0:
101
- /***/ (function(module, exports) {
102
-
103
- module.exports = require("../../package.json");
104
-
105
- /***/ }),
106
-
107
- /***/ 1:
108
- /***/ (function(module, exports) {
109
-
110
- module.exports = require("commander");
111
-
112
- /***/ }),
113
-
114
- /***/ 2:
115
- /***/ (function(module, exports) {
116
-
117
- module.exports = require("chalk");
118
-
119
- /***/ }),
120
-
121
- /***/ 25:
122
- /***/ (function(module, exports, __webpack_require__) {
123
-
124
-
125
- const pkg = __webpack_require__(0);
126
- const program = __webpack_require__(1);
127
- const chalk = __webpack_require__(2);
128
-
129
- program
130
- .version(pkg.version)
131
- .description(
132
- `A tool for viewing magda access control data. Version: ${pkg.version}`
133
- )
134
- .command("permissions", "List all permissions")
135
- .command("roles", "List all roles")
136
- .command("users", "List all users")
137
- .on("command:*", function (cmds) {
138
- if (["permissions", "roles", "users"].indexOf(cmds[0]) === -1) {
139
- console.error(
140
- chalk.red(
141
- `Invalid command: ${program.args.join(
142
- " "
143
- )}\nSee --help for a list of available commands.`
144
- )
145
- );
146
- process.exit(1);
147
- }
148
- })
149
- .parse(process.argv);
150
-
151
-
152
- /***/ })
153
-
154
- /******/ });
155
- });
@@ -1,264 +0,0 @@
1
- #!/usr/bin/env node
2
- (function webpackUniversalModuleDefinition(root, factory) {
3
- if(typeof exports === 'object' && typeof module === 'object')
4
- module.exports = factory();
5
- else if(typeof define === 'function' && define.amd)
6
- define([], factory);
7
- else {
8
- var a = factory();
9
- for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
10
- }
11
- })(global, function() {
12
- return /******/ (function(modules) { // webpackBootstrap
13
- /******/ // The module cache
14
- /******/ var installedModules = {};
15
- /******/
16
- /******/ // The require function
17
- /******/ function __webpack_require__(moduleId) {
18
- /******/
19
- /******/ // Check if module is in cache
20
- /******/ if(installedModules[moduleId]) {
21
- /******/ return installedModules[moduleId].exports;
22
- /******/ }
23
- /******/ // Create a new module (and put it into the cache)
24
- /******/ var module = installedModules[moduleId] = {
25
- /******/ i: moduleId,
26
- /******/ l: false,
27
- /******/ exports: {}
28
- /******/ };
29
- /******/
30
- /******/ // Execute the module function
31
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
32
- /******/
33
- /******/ // Flag the module as loaded
34
- /******/ module.l = true;
35
- /******/
36
- /******/ // Return the exports of the module
37
- /******/ return module.exports;
38
- /******/ }
39
- /******/
40
- /******/
41
- /******/ // expose the modules object (__webpack_modules__)
42
- /******/ __webpack_require__.m = modules;
43
- /******/
44
- /******/ // expose the module cache
45
- /******/ __webpack_require__.c = installedModules;
46
- /******/
47
- /******/ // define getter function for harmony exports
48
- /******/ __webpack_require__.d = function(exports, name, getter) {
49
- /******/ if(!__webpack_require__.o(exports, name)) {
50
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
51
- /******/ }
52
- /******/ };
53
- /******/
54
- /******/ // define __esModule on exports
55
- /******/ __webpack_require__.r = function(exports) {
56
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
57
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
58
- /******/ }
59
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
60
- /******/ };
61
- /******/
62
- /******/ // create a fake namespace object
63
- /******/ // mode & 1: value is a module id, require it
64
- /******/ // mode & 2: merge all properties of value into the ns
65
- /******/ // mode & 4: return value when already ns object
66
- /******/ // mode & 8|1: behave like require
67
- /******/ __webpack_require__.t = function(value, mode) {
68
- /******/ if(mode & 1) value = __webpack_require__(value);
69
- /******/ if(mode & 8) return value;
70
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
71
- /******/ var ns = Object.create(null);
72
- /******/ __webpack_require__.r(ns);
73
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
74
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
75
- /******/ return ns;
76
- /******/ };
77
- /******/
78
- /******/ // getDefaultExport function for compatibility with non-harmony modules
79
- /******/ __webpack_require__.n = function(module) {
80
- /******/ var getter = module && module.__esModule ?
81
- /******/ function getDefault() { return module['default']; } :
82
- /******/ function getModuleExports() { return module; };
83
- /******/ __webpack_require__.d(getter, 'a', getter);
84
- /******/ return getter;
85
- /******/ };
86
- /******/
87
- /******/ // Object.prototype.hasOwnProperty.call
88
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
89
- /******/
90
- /******/ // __webpack_public_path__
91
- /******/ __webpack_require__.p = "";
92
- /******/
93
- /******/
94
- /******/ // Load entry module and return exports
95
- /******/ return __webpack_require__(__webpack_require__.s = 26);
96
- /******/ })
97
- /************************************************************************/
98
- /******/ ({
99
-
100
- /***/ 0:
101
- /***/ (function(module, exports) {
102
-
103
- module.exports = require("../../package.json");
104
-
105
- /***/ }),
106
-
107
- /***/ 1:
108
- /***/ (function(module, exports) {
109
-
110
- module.exports = require("commander");
111
-
112
- /***/ }),
113
-
114
- /***/ 2:
115
- /***/ (function(module, exports) {
116
-
117
- module.exports = require("chalk");
118
-
119
- /***/ }),
120
-
121
- /***/ 26:
122
- /***/ (function(module, exports, __webpack_require__) {
123
-
124
-
125
- const pkg = __webpack_require__(0);
126
- const program = __webpack_require__(1);
127
- const chalk = __webpack_require__(2);
128
- const getDBPool = __webpack_require__(3);
129
- const { recordExist } = __webpack_require__(6);
130
-
131
- const pool = getDBPool();
132
-
133
- program
134
- .description("Remove a permission from a role")
135
- .option("<permissionId>", "Permission ID")
136
- .option("<roleId>", "Role ID")
137
- .version(pkg.version)
138
- .action(async (permissionId, roleId) => {
139
- try {
140
- if (process.argv.slice(2).length < 2) {
141
- program.help();
142
- }
143
- if (
144
- !(await recordExist(pool, "permissions", { id: permissionId }))
145
- ) {
146
- throw new Error(
147
- `Supplied permissionId: ${permissionId} doesn't exist`
148
- );
149
- }
150
- if (!(await recordExist(pool, "roles", { id: roleId }))) {
151
- throw new Error(`Supplied roleId: ${roleId} doesn't exist`);
152
- }
153
- if (
154
- !(await recordExist(pool, "role_permissions", {
155
- role_id: roleId,
156
- permission_id: permissionId
157
- }))
158
- ) {
159
- throw new Error(
160
- `Cannot remove the permission: Role (id: ${roleId}) has no permission with id: ${ropermissionIdleId}!`
161
- );
162
- }
163
- await pool.query(
164
- `DELETE FROM role_permissions WHERE role_id = $1 AND permission_id = $2`,
165
- [roleId, permissionId]
166
- );
167
- console.log(chalk.green("Operation Completed!"));
168
- } catch (e) {
169
- console.error(chalk.red(`Error: ${e}`));
170
- }
171
- process.exit(0);
172
- })
173
- .parse(process.argv);
174
-
175
-
176
- /***/ }),
177
-
178
- /***/ 3:
179
- /***/ (function(module, exports, __webpack_require__) {
180
-
181
- const pg = __webpack_require__(4);
182
- const getDBConfig = __webpack_require__(5);
183
-
184
- const pool = new pg.Pool(getDBConfig());
185
- pool.on("error", function (err, client) {
186
- console.error("DB Pool Error: ", err.message, err.stack);
187
- });
188
-
189
- function getDBPool() {
190
- return pool;
191
- }
192
-
193
- module.exports = getDBPool;
194
-
195
-
196
- /***/ }),
197
-
198
- /***/ 4:
199
- /***/ (function(module, exports) {
200
-
201
- module.exports = require("pg");
202
-
203
- /***/ }),
204
-
205
- /***/ 5:
206
- /***/ (function(module, exports) {
207
-
208
- function getDBConfig() {
209
- const {
210
- POSTGRES_HOST: host,
211
- POSTGRES_DB: database,
212
- POSTGRES_USER: user,
213
- POSTGRES_PASSWORD: password,
214
- POSTGRES_PORT: port
215
- } = process.env;
216
-
217
- return {
218
- host: host ? host : "localhost",
219
- database: database ? database : "auth",
220
- port: port ? port : 5432,
221
- user: user ? user : "postgres",
222
- password: password ? password : ""
223
- };
224
- }
225
-
226
- module.exports = getDBConfig;
227
-
228
-
229
- /***/ }),
230
-
231
- /***/ 6:
232
- /***/ (function(module, exports) {
233
-
234
- async function recordExist(pool, table, record) {
235
- if (!Object.keys(record).length) {
236
- throw new Error("record cannot be an empty object!");
237
- }
238
- const sqlValues = [];
239
- const where = Object.keys(record)
240
- .map((key) => {
241
- sqlValues.push(record[key]);
242
- return `"${key}" = $${sqlValues.length}`;
243
- })
244
- .join(" AND ");
245
- const result = await pool.query(
246
- `SELECT id FROM "${table}" WHERE ${where}`,
247
- sqlValues
248
- );
249
- if (!result || !result.rows || !result.rows.length) {
250
- return false;
251
- }
252
- return true;
253
- }
254
-
255
- const ADMIN_ROLE_ID = "00000000-0000-0003-0000-000000000000";
256
-
257
- module.exports.recordExist = recordExist;
258
- module.exports.ADMIN_ROLE_ID = ADMIN_ROLE_ID;
259
-
260
-
261
- /***/ })
262
-
263
- /******/ });
264
- });