@magda/scripts 1.2.1-alpha.0 → 2.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.
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ const pkg = require("./package.json");
3
+ const program = require("commander");
4
+ const chalk = require("chalk");
5
+ const isUuid = require("isuuid");
6
+ const buildJwt = require("@magda/typescript-common/dist/session/buildJwt")
7
+ .default;
8
+
9
+ program
10
+ .version(pkg.version)
11
+ .usage("[options]")
12
+ .description(
13
+ `A tool for creating Magda internal JWT token. Version: ${pkg.version}\n` +
14
+ `Please note: this tool is for debug & testing purpose only.`
15
+ )
16
+ .option(
17
+ "-s, --secret [JWT Token Secret]",
18
+ "Specify JWT token secret that used to create the JWT token"
19
+ )
20
+ .option(
21
+ "-u, --userId [User ID]",
22
+ "set the user id that the JWT token carries"
23
+ )
24
+ .parse(process.argv);
25
+
26
+ (async () => {
27
+ const options = program.opts();
28
+
29
+ if (!options || (!options.userId && !options.secret)) {
30
+ program.help();
31
+ return;
32
+ }
33
+
34
+ if (options.userId) {
35
+ if (!isUuid(options.userId)) {
36
+ throw new Error("Invalid user id: should be in UUID format.");
37
+ }
38
+ }
39
+ const jwt = buildJwt(options.secret, options.userId);
40
+ console.log(chalk.green(`JWT Token: `));
41
+ console.log(jwt);
42
+ process.exit();
43
+ })().catch((e) => {
44
+ console.error(chalk.red(`${e}`));
45
+ process.exit(1);
46
+ });
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@magda/scripts",
3
- "version": "1.2.1-alpha.0",
3
+ "version": "2.0.0-alpha.0",
4
4
  "description": "Scripts for building, running, and deploying MAGDA",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
7
7
  "generate-registry-typescript": "generate-registry-typescript.js",
8
+ "create-jwt-token": "create-jwt-token.js",
8
9
  "create-docker-context-for-node-component": "create-docker-context-for-node-component.js",
9
10
  "generate-connector-jobs": "generate-connector-jobs.js",
10
11
  "run-typescript-in-nodemon": "run-typescript-in-nodemon.js",