forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed-sign
executable file
·31 lines (22 loc) · 961 Bytes
/
embed-sign
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env node
/*eslint-env node */
/*eslint-disable import/no-commonjs */
var jwt = require("jsonwebtoken");
var BASE_URL = "http://localhost:3000";
var METABASE_EMBED_SECRET_KEY = process.env["MB_EMBEDDING_SECRET_KEY"];
var resourceType = process.argv[2];
var resourceId = parseFloat(process.argv[3]);
var params = process.argv[4] ? JSON.parse(process.argv[4]) : {};
if (!METABASE_EMBED_SECRET_KEY || !resourceType || typeof resourceId !== "number" || isNaN(resourceId)) {
process.stderr.write("USAGE: MB_EMBEDDING_SECRET_KEY=ABCD embed-sign <resource_type> <resource_id> [<params_json>]\n");
process.exit(1);
}
var resource = {};
resource[resourceType] = resourceId;
var unsignedToken = {
resource: resource,
params: params
};
process.stderr.write(JSON.stringify(unsignedToken, null, 2) + "\n");
var signedToken = jwt.sign(unsignedToken, METABASE_EMBED_SECRET_KEY);
console.log(BASE_URL + "/embed/" + resourceType + "/" + signedToken);