@grafana/sign-plugin 2.3.0-canary.529.ea99045.0 → 2.3.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.
- package/README.md +1 -1
- package/dist/bin/run.js +6 -6
- package/dist/commands/sign.command.js +34 -85
- package/dist/commands/version.command.js +10 -49
- package/dist/utils/getVersion.js +7 -7
- package/dist/utils/manifest.js +70 -251
- package/dist/utils/pluginValidation.js +7 -7
- package/dist/utils/pluginValidation.test.js +8 -8
- package/dist/utils/request.js +33 -82
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -64,4 +64,4 @@ yarn dlx @grafana/sign-plugin@latest
|
|
|
64
64
|
|
|
65
65
|
## Contributing
|
|
66
66
|
|
|
67
|
-
We are always grateful for contribution! See the [CONTRIBUTING.md](
|
|
67
|
+
We are always grateful for contribution! See the [CONTRIBUTING.md](../../CONTRIBUTING.md) for more information.
|
package/dist/bin/run.js
CHANGED
|
@@ -4,13 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const minimist_1 = __importDefault(require("minimist"));
|
|
8
|
+
const commands_1 = require("../commands");
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
const argv = (0, minimist_1.default)(args);
|
|
11
|
+
const commands = {
|
|
12
12
|
sign: commands_1.sign,
|
|
13
13
|
version: commands_1.version,
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
const command = commands[argv._[0]] || commands.sign;
|
|
16
16
|
command(argv);
|
|
@@ -1,93 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.sign = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
case 1:
|
|
63
|
-
_d.trys.push([1, 4, , 5]);
|
|
64
|
-
console.log('Building manifest...');
|
|
65
|
-
return [4, (0, manifest_1.buildManifest)(pluginDistDir)];
|
|
66
|
-
case 2:
|
|
67
|
-
manifest = _d.sent();
|
|
68
|
-
console.log('Signing manifest...');
|
|
69
|
-
if (signatureType) {
|
|
70
|
-
manifest.signatureType = signatureType;
|
|
71
|
-
}
|
|
72
|
-
if (rootUrls && rootUrls.length > 0) {
|
|
73
|
-
rootUrls.forEach(pluginValidation_1.assertRootUrlIsValid);
|
|
74
|
-
manifest.rootUrls = rootUrls;
|
|
75
|
-
}
|
|
76
|
-
manifest.signPlugin = { version: (0, getVersion_1.getVersion)() };
|
|
77
|
-
return [4, (0, manifest_1.signManifest)(manifest)];
|
|
78
|
-
case 3:
|
|
79
|
-
signedManifest = _d.sent();
|
|
80
|
-
console.log('Saving signed manifest...');
|
|
81
|
-
(0, manifest_1.saveManifest)(pluginDistDir, signedManifest);
|
|
82
|
-
console.log('Signed successfully');
|
|
83
|
-
return [3, 5];
|
|
84
|
-
case 4:
|
|
85
|
-
err_1 = _d.sent();
|
|
86
|
-
console.warn(err_1);
|
|
87
|
-
process.exitCode = 1;
|
|
88
|
-
return [3, 5];
|
|
89
|
-
case 5: return [2];
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const pluginValidation_1 = require("../utils/pluginValidation");
|
|
10
|
+
const manifest_1 = require("../utils/manifest");
|
|
11
|
+
const getVersion_1 = require("../utils/getVersion");
|
|
12
|
+
const sign = async (argv) => {
|
|
13
|
+
const distDir = argv.distDir ?? 'dist';
|
|
14
|
+
const pluginDistDir = path_1.default.resolve(distDir);
|
|
15
|
+
const signatureType = argv.signatureType;
|
|
16
|
+
const rootUrls = argv.rootUrls?.split(',') ?? [];
|
|
17
|
+
if (!(0, fs_1.existsSync)(pluginDistDir)) {
|
|
18
|
+
throw new Error(`Plugin \`${distDir}\` directory is missing. Did you build the plugin before attempting to sign?`);
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
console.log('Building manifest...');
|
|
22
|
+
const manifest = await (0, manifest_1.buildManifest)(pluginDistDir);
|
|
23
|
+
console.log('Signing manifest...');
|
|
24
|
+
if (signatureType) {
|
|
25
|
+
manifest.signatureType = signatureType;
|
|
90
26
|
}
|
|
91
|
-
|
|
92
|
-
|
|
27
|
+
if (rootUrls && rootUrls.length > 0) {
|
|
28
|
+
rootUrls.forEach(pluginValidation_1.assertRootUrlIsValid);
|
|
29
|
+
manifest.rootUrls = rootUrls;
|
|
30
|
+
}
|
|
31
|
+
manifest.signPlugin = { version: (0, getVersion_1.getVersion)() };
|
|
32
|
+
const signedManifest = await (0, manifest_1.signManifest)(manifest);
|
|
33
|
+
console.log('Saving signed manifest...');
|
|
34
|
+
(0, manifest_1.saveManifest)(pluginDistDir, signedManifest);
|
|
35
|
+
console.log('Signed successfully');
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
console.warn(err);
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
93
42
|
exports.sign = sign;
|
|
@@ -1,53 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.version = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return [2];
|
|
51
|
-
});
|
|
52
|
-
}); };
|
|
4
|
+
const getVersion_1 = require("../utils/getVersion");
|
|
5
|
+
const version = async () => {
|
|
6
|
+
try {
|
|
7
|
+
console.log((0, getVersion_1.getVersion)());
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
console.error(error);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
53
14
|
exports.version = version;
|
package/dist/utils/getVersion.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getVersion = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const getVersion = () => {
|
|
7
|
+
const packageJsonPath = (0, path_1.resolve)(__dirname, '..', '..', 'package.json');
|
|
8
|
+
const pkg = (0, fs_1.readFileSync)(packageJsonPath, 'utf8');
|
|
9
|
+
const { version } = JSON.parse(pkg);
|
|
10
10
|
if (!version) {
|
|
11
|
-
throw
|
|
11
|
+
throw `Could not find the version of sign-plugin`;
|
|
12
12
|
}
|
|
13
13
|
return version;
|
|
14
14
|
};
|
package/dist/utils/manifest.js
CHANGED
|
@@ -1,265 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
39
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
40
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
41
|
-
var m = o[Symbol.asyncIterator], i;
|
|
42
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
43
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
44
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
45
|
-
};
|
|
46
|
-
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
|
47
|
-
var i, p;
|
|
48
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
49
|
-
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
|
|
50
|
-
};
|
|
51
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
52
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
53
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
54
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
55
|
-
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
56
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
57
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
58
|
-
function fulfill(value) { resume("next", value); }
|
|
59
|
-
function reject(value) { resume("throw", value); }
|
|
60
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
61
|
-
};
|
|
62
|
-
var __values = (this && this.__values) || function(o) {
|
|
63
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
64
|
-
if (m) return m.call(o);
|
|
65
|
-
if (o && typeof o.length === "number") return {
|
|
66
|
-
next: function () {
|
|
67
|
-
if (o && i >= o.length) o = void 0;
|
|
68
|
-
return { value: o && o[i++], done: !o };
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
72
|
-
};
|
|
73
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
74
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
75
4
|
};
|
|
76
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
77
6
|
exports.saveManifest = exports.signManifest = exports.buildManifest = void 0;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
function walk(dir, baseDir) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
case 2: return [4, __await(_b.next())];
|
|
98
|
-
case 3:
|
|
99
|
-
if (!(_c = _g.sent(), _d = _c.done, !_d)) return [3, 16];
|
|
100
|
-
_f = _c.value;
|
|
101
|
-
_a = false;
|
|
102
|
-
d = _f;
|
|
103
|
-
entry = path_1.default.join(dir, d.name);
|
|
104
|
-
if (!d.isDirectory()) return [3, 7];
|
|
105
|
-
return [4, __await(walk(entry, baseDir))];
|
|
106
|
-
case 4: return [5, __values(__asyncDelegator.apply(void 0, [__asyncValues.apply(void 0, [_g.sent()])]))];
|
|
107
|
-
case 5: return [4, __await.apply(void 0, [_g.sent()])];
|
|
108
|
-
case 6:
|
|
109
|
-
_g.sent();
|
|
110
|
-
return [3, 15];
|
|
111
|
-
case 7:
|
|
112
|
-
if (!d.isFile()) return [3, 10];
|
|
113
|
-
return [4, __await(path_1.default.relative(baseDir, entry))];
|
|
114
|
-
case 8: return [4, _g.sent()];
|
|
115
|
-
case 9:
|
|
116
|
-
_g.sent();
|
|
117
|
-
return [3, 15];
|
|
118
|
-
case 10:
|
|
119
|
-
if (!d.isSymbolicLink()) return [3, 15];
|
|
120
|
-
return [4, __await(promises_1.default.realpath(entry))];
|
|
121
|
-
case 11:
|
|
122
|
-
realPath = _g.sent();
|
|
123
|
-
if (!realPath.startsWith(baseDir)) {
|
|
124
|
-
throw new Error("symbolic link ".concat(path_1.default.relative(baseDir, entry), " targets a file outside of the base directory: ").concat(baseDir));
|
|
125
|
-
}
|
|
126
|
-
return [4, __await(promises_1.default.stat(realPath))];
|
|
127
|
-
case 12:
|
|
128
|
-
stats = _g.sent();
|
|
129
|
-
if (!stats.isFile()) return [3, 15];
|
|
130
|
-
return [4, __await(path_1.default.relative(baseDir, entry))];
|
|
131
|
-
case 13: return [4, _g.sent()];
|
|
132
|
-
case 14:
|
|
133
|
-
_g.sent();
|
|
134
|
-
_g.label = 15;
|
|
135
|
-
case 15:
|
|
136
|
-
_a = true;
|
|
137
|
-
return [3, 2];
|
|
138
|
-
case 16: return [3, 23];
|
|
139
|
-
case 17:
|
|
140
|
-
e_1_1 = _g.sent();
|
|
141
|
-
e_1 = { error: e_1_1 };
|
|
142
|
-
return [3, 23];
|
|
143
|
-
case 18:
|
|
144
|
-
_g.trys.push([18, , 21, 22]);
|
|
145
|
-
if (!(!_a && !_d && (_e = _b.return))) return [3, 20];
|
|
146
|
-
return [4, __await(_e.call(_b))];
|
|
147
|
-
case 19:
|
|
148
|
-
_g.sent();
|
|
149
|
-
_g.label = 20;
|
|
150
|
-
case 20: return [3, 22];
|
|
151
|
-
case 21:
|
|
152
|
-
if (e_1) throw e_1.error;
|
|
153
|
-
return [7];
|
|
154
|
-
case 22: return [7];
|
|
155
|
-
case 23: return [2];
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const request_1 = require("./request");
|
|
12
|
+
const MANIFEST_FILE = 'MANIFEST.txt';
|
|
13
|
+
async function* walk(dir, baseDir) {
|
|
14
|
+
for await (const d of await promises_1.default.opendir(dir)) {
|
|
15
|
+
const entry = path_1.default.join(dir, d.name);
|
|
16
|
+
if (d.isDirectory()) {
|
|
17
|
+
yield* await walk(entry, baseDir);
|
|
18
|
+
}
|
|
19
|
+
else if (d.isFile()) {
|
|
20
|
+
yield path_1.default.relative(baseDir, entry);
|
|
21
|
+
}
|
|
22
|
+
else if (d.isSymbolicLink()) {
|
|
23
|
+
const realPath = await promises_1.default.realpath(entry);
|
|
24
|
+
if (!realPath.startsWith(baseDir)) {
|
|
25
|
+
throw new Error(`symbolic link ${path_1.default.relative(baseDir, entry)} targets a file outside of the base directory: ${baseDir}`);
|
|
156
26
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
function buildManifest(dir) {
|
|
161
|
-
var _a, e_2, _b, _c;
|
|
162
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
163
|
-
var pluginJson, manifest, _d, _e, _f, filePath, sanitisedFilePath, e_2_1;
|
|
164
|
-
return __generator(this, function (_g) {
|
|
165
|
-
switch (_g.label) {
|
|
166
|
-
case 0:
|
|
167
|
-
pluginJson = JSON.parse((0, fs_1.readFileSync)(path_1.default.join(dir, 'plugin.json'), { encoding: 'utf8' }));
|
|
168
|
-
manifest = {
|
|
169
|
-
plugin: pluginJson.id,
|
|
170
|
-
version: pluginJson.info.version,
|
|
171
|
-
files: {},
|
|
172
|
-
};
|
|
173
|
-
_g.label = 1;
|
|
174
|
-
case 1:
|
|
175
|
-
_g.trys.push([1, 7, 8, 13]);
|
|
176
|
-
_d = true;
|
|
177
|
-
return [4, walk(dir, dir)];
|
|
178
|
-
case 2:
|
|
179
|
-
_e = __asyncValues.apply(void 0, [_g.sent()]);
|
|
180
|
-
_g.label = 3;
|
|
181
|
-
case 3: return [4, _e.next()];
|
|
182
|
-
case 4:
|
|
183
|
-
if (!(_f = _g.sent(), _a = _f.done, !_a)) return [3, 6];
|
|
184
|
-
_c = _f.value;
|
|
185
|
-
_d = false;
|
|
186
|
-
filePath = _c;
|
|
187
|
-
if (filePath === MANIFEST_FILE) {
|
|
188
|
-
return [3, 5];
|
|
189
|
-
}
|
|
190
|
-
sanitisedFilePath = filePath.split(path_1.default.sep).join(path_1.default.posix.sep);
|
|
191
|
-
manifest.files[sanitisedFilePath] = crypto_1.default
|
|
192
|
-
.createHash('sha256')
|
|
193
|
-
.update((0, fs_1.readFileSync)(path_1.default.join(dir, filePath)))
|
|
194
|
-
.digest('hex');
|
|
195
|
-
_g.label = 5;
|
|
196
|
-
case 5:
|
|
197
|
-
_d = true;
|
|
198
|
-
return [3, 3];
|
|
199
|
-
case 6: return [3, 13];
|
|
200
|
-
case 7:
|
|
201
|
-
e_2_1 = _g.sent();
|
|
202
|
-
e_2 = { error: e_2_1 };
|
|
203
|
-
return [3, 13];
|
|
204
|
-
case 8:
|
|
205
|
-
_g.trys.push([8, , 11, 12]);
|
|
206
|
-
if (!(!_d && !_a && (_b = _e.return))) return [3, 10];
|
|
207
|
-
return [4, _b.call(_e)];
|
|
208
|
-
case 9:
|
|
209
|
-
_g.sent();
|
|
210
|
-
_g.label = 10;
|
|
211
|
-
case 10: return [3, 12];
|
|
212
|
-
case 11:
|
|
213
|
-
if (e_2) throw e_2.error;
|
|
214
|
-
return [7];
|
|
215
|
-
case 12: return [7];
|
|
216
|
-
case 13: return [2, manifest];
|
|
27
|
+
const stats = await promises_1.default.stat(realPath);
|
|
28
|
+
if (stats.isFile()) {
|
|
29
|
+
yield path_1.default.relative(baseDir, entry);
|
|
217
30
|
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function buildManifest(dir) {
|
|
35
|
+
const pluginJson = JSON.parse((0, fs_1.readFileSync)(path_1.default.join(dir, 'plugin.json'), { encoding: 'utf8' }));
|
|
36
|
+
const manifest = {
|
|
37
|
+
plugin: pluginJson.id,
|
|
38
|
+
version: pluginJson.info.version,
|
|
39
|
+
files: {},
|
|
40
|
+
};
|
|
41
|
+
for await (const filePath of await walk(dir, dir)) {
|
|
42
|
+
if (filePath === MANIFEST_FILE) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const sanitisedFilePath = filePath.split(path_1.default.sep).join(path_1.default.posix.sep);
|
|
46
|
+
manifest.files[sanitisedFilePath] = crypto_1.default
|
|
47
|
+
.createHash('sha256')
|
|
48
|
+
.update((0, fs_1.readFileSync)(path_1.default.join(dir, filePath)))
|
|
49
|
+
.digest('hex');
|
|
50
|
+
}
|
|
51
|
+
return manifest;
|
|
220
52
|
}
|
|
221
53
|
exports.buildManifest = buildManifest;
|
|
222
|
-
function signManifest(manifest) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
GRAFANA_COM_URL = process.env.GRAFANA_COM_URL || 'https://grafana.com/api';
|
|
238
|
-
url = GRAFANA_COM_URL + '/plugins/ci/sign';
|
|
239
|
-
token = GRAFANA_ACCESS_POLICY_TOKEN ? GRAFANA_ACCESS_POLICY_TOKEN : GRAFANA_API_KEY;
|
|
240
|
-
_c.label = 1;
|
|
241
|
-
case 1:
|
|
242
|
-
_c.trys.push([1, 3, , 4]);
|
|
243
|
-
return [4, (0, request_1.postData)(url, manifest, {
|
|
244
|
-
Authorization: 'Bearer ' + token,
|
|
245
|
-
})];
|
|
246
|
-
case 2:
|
|
247
|
-
info = _c.sent();
|
|
248
|
-
if (info.status !== 200) {
|
|
249
|
-
console.error('Error: ', info);
|
|
250
|
-
throw new Error('Error signing manifest');
|
|
251
|
-
}
|
|
252
|
-
return [2, info.data];
|
|
253
|
-
case 3:
|
|
254
|
-
err_1 = _c.sent();
|
|
255
|
-
if ((_b = (_a = err_1.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) {
|
|
256
|
-
throw new Error('Error signing manifest: ' + err_1.response.data.message);
|
|
257
|
-
}
|
|
258
|
-
throw new Error('Error signing manifest: ' + err_1.message);
|
|
259
|
-
case 4: return [2];
|
|
260
|
-
}
|
|
54
|
+
async function signManifest(manifest) {
|
|
55
|
+
const GRAFANA_API_KEY = process.env.GRAFANA_API_KEY;
|
|
56
|
+
const GRAFANA_ACCESS_POLICY_TOKEN = process.env.GRAFANA_ACCESS_POLICY_TOKEN;
|
|
57
|
+
if (!GRAFANA_ACCESS_POLICY_TOKEN && !GRAFANA_API_KEY) {
|
|
58
|
+
throw new Error('You must create a GRAFANA_ACCESS_POLICY_TOKEN env variable to sign plugins. Please see: https://grafana.com/developers/plugin-tools/publish-a-plugin/sign-a-plugin#generate-an-access-policy-token for instructions.');
|
|
59
|
+
}
|
|
60
|
+
if (GRAFANA_API_KEY) {
|
|
61
|
+
console.warn(`\x1b[33m%s\x1b[0m`, 'The usage of GRAFANA_API_KEY is deprecated, please consider using GRAFANA_ACCESS_POLICY_TOKEN instead. For more info visit https://grafana.com/developers/plugin-tools/publish-a-plugin/sign-a-plugin');
|
|
62
|
+
}
|
|
63
|
+
const GRAFANA_COM_URL = process.env.GRAFANA_COM_URL || 'https://grafana.com/api';
|
|
64
|
+
const url = GRAFANA_COM_URL + '/plugins/ci/sign';
|
|
65
|
+
const token = GRAFANA_ACCESS_POLICY_TOKEN ? GRAFANA_ACCESS_POLICY_TOKEN : GRAFANA_API_KEY;
|
|
66
|
+
try {
|
|
67
|
+
const info = await (0, request_1.postData)(url, manifest, {
|
|
68
|
+
Authorization: 'Bearer ' + token,
|
|
261
69
|
});
|
|
262
|
-
|
|
70
|
+
if (info.status !== 200) {
|
|
71
|
+
console.error('Error: ', info);
|
|
72
|
+
throw new Error('Error signing manifest');
|
|
73
|
+
}
|
|
74
|
+
return info.data;
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (err.response?.data?.message) {
|
|
78
|
+
throw new Error('Error signing manifest: ' + err.response.data.message);
|
|
79
|
+
}
|
|
80
|
+
throw new Error('Error signing manifest: ' + err.message);
|
|
81
|
+
}
|
|
263
82
|
}
|
|
264
83
|
exports.signManifest = signManifest;
|
|
265
84
|
function saveManifest(dir, signedManifest) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.assertRootUrlIsValid = exports.getPluginJson = exports.validatePluginJson = void 0;
|
|
4
|
-
|
|
4
|
+
const validatePluginJson = (pluginJson) => {
|
|
5
5
|
if (!pluginJson.id) {
|
|
6
6
|
throw new Error('Plugin id is missing in plugin.json');
|
|
7
7
|
}
|
|
@@ -11,8 +11,8 @@ var validatePluginJson = function (pluginJson) {
|
|
|
11
11
|
if (!pluginJson.info.version) {
|
|
12
12
|
throw new Error('Plugin info.version is missing in plugin.json');
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const types = ['panel', 'datasource', 'app'];
|
|
15
|
+
const type = pluginJson.type;
|
|
16
16
|
if (!types.includes(type)) {
|
|
17
17
|
throw new Error('Invalid plugin type in plugin.json: ' + type);
|
|
18
18
|
}
|
|
@@ -21,8 +21,8 @@ var validatePluginJson = function (pluginJson) {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
exports.validatePluginJson = validatePluginJson;
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const getPluginJson = (path) => {
|
|
25
|
+
let pluginJson;
|
|
26
26
|
try {
|
|
27
27
|
pluginJson = require(path);
|
|
28
28
|
}
|
|
@@ -33,12 +33,12 @@ var getPluginJson = function (path) {
|
|
|
33
33
|
return pluginJson;
|
|
34
34
|
};
|
|
35
35
|
exports.getPluginJson = getPluginJson;
|
|
36
|
-
|
|
36
|
+
const assertRootUrlIsValid = (rootUrl) => {
|
|
37
37
|
try {
|
|
38
38
|
new URL(rootUrl);
|
|
39
39
|
}
|
|
40
40
|
catch (err) {
|
|
41
|
-
throw new Error(
|
|
41
|
+
throw new Error(`${rootUrl} is not a valid URL`);
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
exports.assertRootUrlIsValid = assertRootUrlIsValid;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
describe('pluginValidation',
|
|
5
|
-
describe('plugin.json',
|
|
6
|
-
test('missing plugin.json file',
|
|
7
|
-
expect(
|
|
3
|
+
const pluginValidation_1 = require("./pluginValidation");
|
|
4
|
+
describe('pluginValidation', () => {
|
|
5
|
+
describe('plugin.json', () => {
|
|
6
|
+
test('missing plugin.json file', () => {
|
|
7
|
+
expect(() => (0, pluginValidation_1.getPluginJson)(`${__dirname}/mocks/missing-plugin.json`)).toThrowError();
|
|
8
8
|
});
|
|
9
9
|
});
|
|
10
|
-
describe('validatePluginJson',
|
|
11
|
-
test('missing "id" field in the plugin.json file',
|
|
12
|
-
expect(
|
|
10
|
+
describe('validatePluginJson', () => {
|
|
11
|
+
test('missing "id" field in the plugin.json file', () => {
|
|
12
|
+
expect(() => (0, pluginValidation_1.validatePluginJson)({})).toThrow('Plugin id is missing in plugin.json');
|
|
13
13
|
});
|
|
14
14
|
});
|
|
15
15
|
});
|
package/dist/utils/request.js
CHANGED
|
@@ -1,92 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
4
|
};
|
|
52
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
6
|
exports.postData = void 0;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
function postData(urlString, data, headers) {
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
85
|
-
req.on('error', reject);
|
|
86
|
-
req.write(postData);
|
|
87
|
-
req.end();
|
|
88
|
-
})];
|
|
7
|
+
const https_1 = __importDefault(require("https"));
|
|
8
|
+
const proxy_agent_1 = require("proxy-agent");
|
|
9
|
+
const url_1 = require("url");
|
|
10
|
+
const agent = new proxy_agent_1.ProxyAgent();
|
|
11
|
+
async function postData(urlString, data, headers) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const url = new url_1.URL(urlString);
|
|
14
|
+
const postData = JSON.stringify(data);
|
|
15
|
+
const options = {
|
|
16
|
+
hostname: url.hostname,
|
|
17
|
+
port: url.port || 443,
|
|
18
|
+
path: url.pathname,
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: {
|
|
21
|
+
...headers,
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
},
|
|
24
|
+
agent,
|
|
25
|
+
};
|
|
26
|
+
const req = https_1.default.request(options, (res) => {
|
|
27
|
+
const chunks = [];
|
|
28
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
|
29
|
+
res.on('end', () => {
|
|
30
|
+
const results = Buffer.concat(chunks);
|
|
31
|
+
resolve({
|
|
32
|
+
data: results.toString(),
|
|
33
|
+
status: res.statusCode ?? 200,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
res.on('error', reject);
|
|
89
37
|
});
|
|
38
|
+
req.on('error', reject);
|
|
39
|
+
req.write(postData);
|
|
40
|
+
req.end();
|
|
90
41
|
});
|
|
91
42
|
}
|
|
92
43
|
exports.postData = postData;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/sign-plugin",
|
|
3
|
-
"version": "2.3.0
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "packages/sign-plugin",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=20"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "46aa5ac9a89a7246435e2ea9f85becb4fc3bc708"
|
|
45
45
|
}
|