@grafana/sign-plugin 0.0.1-canary.127.7d9f230.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/CONTRIBUTING.md +56 -0
- package/LICENSE +201 -0
- package/README.md +60 -0
- package/dist/bin/run.js +11 -0
- package/dist/commands/index.js +17 -0
- package/dist/commands/sign.command.js +90 -0
- package/dist/utils/getVersion.js +15 -0
- package/dist/utils/manifest.js +260 -0
- package/dist/utils/pluginValidation.js +44 -0
- package/dist/utils/pluginValidation.test.js +15 -0
- package/jest.config.js +3 -0
- package/package.json +45 -0
- package/src/bin/run.ts +9 -0
- package/src/commands/index.ts +1 -0
- package/src/commands/sign.command.ts +40 -0
- package/src/utils/getVersion.ts +12 -0
- package/src/utils/manifest.ts +115 -0
- package/src/utils/pluginValidation.test.ts +15 -0
- package/src/utils/pluginValidation.ts +44 -0
- package/tsconfig.json +8 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Contributing to Grafana / Sign Plugin
|
|
2
|
+
|
|
3
|
+
We are always grateful to receive contributions!<br />
|
|
4
|
+
The following guidelines help you on how to start with the codebase and how to submit your work.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
### Prerequisites
|
|
9
|
+
|
|
10
|
+
You need to have `npm` or `yarn` installed.
|
|
11
|
+
|
|
12
|
+
### Installing
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
git clone git@github.com:grafana/plugin-tools.git
|
|
16
|
+
cd plugin-tools
|
|
17
|
+
yarn install
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Overview
|
|
21
|
+
|
|
22
|
+
### Technologies
|
|
23
|
+
|
|
24
|
+
- [**`minimist`**](https://github.com/minimistjs/minimist) - used for parsing argument options
|
|
25
|
+
|
|
26
|
+
### Folder structure
|
|
27
|
+
|
|
28
|
+
_Work in progress._
|
|
29
|
+
|
|
30
|
+
## Development
|
|
31
|
+
|
|
32
|
+
There are a collection of [commands](#commmands) to assist with developing `sign-plugin`. Please read the main [contributing guide](../../CONTRIBUTING.md) before contributing any code changes to the project.
|
|
33
|
+
|
|
34
|
+
### Commmands
|
|
35
|
+
|
|
36
|
+
Below are the main commands used for developing `sign-plugin`. They can be run by either `yarn workspace @grafana/sign-plugin run <name_of_command>` or navigating to `packages/sign-plugin` and running the command directly as detailed below.
|
|
37
|
+
|
|
38
|
+
```shell
|
|
39
|
+
yarn build # used to build @grafana/sign-plugin
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```shell
|
|
43
|
+
yarn dev # watches for changes to files and rebuilds @grafana/sign-plugin automatically
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Conventions
|
|
47
|
+
|
|
48
|
+
_Work in progress._
|
|
49
|
+
|
|
50
|
+
### Developing the templates
|
|
51
|
+
|
|
52
|
+
_Work in progress._
|
|
53
|
+
|
|
54
|
+
### Submitting a Pull Request
|
|
55
|
+
|
|
56
|
+
_Work in progress._
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Grafana / Sign Plugin
|
|
2
|
+
|
|
3
|
+
Sign Grafana plugins with ease.
|
|
4
|
+
|
|
5
|
+
**ToC**
|
|
6
|
+
|
|
7
|
+
- [Grafana / Sign Plugin](#grafana--sign-plugin)
|
|
8
|
+
- [Signing a plugin](#signing-a-plugin)
|
|
9
|
+
- [Sign a public plugin](#sign-a-public-plugin)
|
|
10
|
+
- [Sign a private plugin](#sign-a-private-plugin)
|
|
11
|
+
- [`npx`](#npx)
|
|
12
|
+
- [`yarn` (> 2.x)](#yarn--2x)
|
|
13
|
+
- [Contributing](#contributing)
|
|
14
|
+
|
|
15
|
+
**`@grafana/sign-plugin`** works on macOS, Windows and Linux.<br />
|
|
16
|
+
If something doesn’t work, please [file an issue](https://github.com/grafana/plugin-tools/issues/new).<br />
|
|
17
|
+
If you have questions or need help, please ask in [GitHub Discussions](https://github.com/grafana/plugin-tools/discussions).
|
|
18
|
+
|
|
19
|
+
## Signing a plugin
|
|
20
|
+
|
|
21
|
+
Signing a plugin allows Grafana to verify the authenticity of the plugin with signature verification. This gives users a way to make sure plugins haven’t been tampered with. All Grafana Labs-authored plugins, including Enterprise plugins, are signed.
|
|
22
|
+
|
|
23
|
+
All plugins require a signature since Grafana 7.0.
|
|
24
|
+
|
|
25
|
+
Please refer to [Signing plugins documentation](https://grafana.com/docs/grafana/latest/developers/plugins/sign-a-plugin/) to understand how to sign a Grafana plugin. The following commands are mentioned here for development purposes.
|
|
26
|
+
|
|
27
|
+
### Sign a public plugin
|
|
28
|
+
|
|
29
|
+
In your plugin directory, sign the plugin with your Grafana API key. Grafana sign-plugin creates a MANIFEST.txt file in the dist directory of your plugin.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
export GRAFANA_API_KEY=<YOUR_API_KEY>
|
|
33
|
+
npx @grafana/sign-plugin
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Sign a private plugin
|
|
37
|
+
|
|
38
|
+
In your plugin directory, run the following to create a MANIFEST.txt file in the dist directory of your plugin.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx @grafana/sign-plugin --rootUrls https://example.com/grafana
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Alterntives:
|
|
45
|
+
|
|
46
|
+
#### [`npx`](https://github.com/npm/npx)
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx @grafana/sign-plugin
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### [`yarn`](https://yarnpkg.com/cli/dlx) (> 2.x)
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
yarn dlx @grafana/sign-plugin
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Contributing
|
|
59
|
+
|
|
60
|
+
We are always grateful for contribution! See the [CONTRIBUTING.md](../CONTRIBUTING.md) for more information.
|
package/dist/bin/run.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
exports.__esModule = true;
|
|
7
|
+
var minimist_1 = __importDefault(require("minimist"));
|
|
8
|
+
var commands_1 = require("../commands");
|
|
9
|
+
var args = process.argv.slice(2);
|
|
10
|
+
var argv = (0, minimist_1["default"])(args);
|
|
11
|
+
(0, commands_1.sign)(argv);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
exports.__esModule = true;
|
|
17
|
+
__exportStar(require("./sign.command"), exports);
|
|
@@ -0,0 +1,90 @@
|
|
|
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 (_) 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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
exports.__esModule = true;
|
|
42
|
+
exports.sign = void 0;
|
|
43
|
+
var path_1 = __importDefault(require("path"));
|
|
44
|
+
var fs_1 = require("fs");
|
|
45
|
+
var pluginValidation_1 = require("../utils/pluginValidation");
|
|
46
|
+
var manifest_1 = require("../utils/manifest");
|
|
47
|
+
var getVersion_1 = require("../utils/getVersion");
|
|
48
|
+
var sign = function (argv) { return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
+
var pluginDistDir, signatureType, rootUrls, manifest, signedManifest, err_1;
|
|
50
|
+
return __generator(this, function (_a) {
|
|
51
|
+
switch (_a.label) {
|
|
52
|
+
case 0:
|
|
53
|
+
pluginDistDir = path_1["default"].resolve('dist');
|
|
54
|
+
signatureType = argv.signatureType;
|
|
55
|
+
rootUrls = argv.rootUrls.split(',');
|
|
56
|
+
if (!(0, fs_1.existsSync)(pluginDistDir)) {
|
|
57
|
+
throw new Error('Plugin `dist` directory is missing. Did you build the plugin before attempting to sign?');
|
|
58
|
+
}
|
|
59
|
+
_a.label = 1;
|
|
60
|
+
case 1:
|
|
61
|
+
_a.trys.push([1, 4, , 5]);
|
|
62
|
+
console.log('Building manifest...');
|
|
63
|
+
return [4, (0, manifest_1.buildManifest)(pluginDistDir)];
|
|
64
|
+
case 2:
|
|
65
|
+
manifest = _a.sent();
|
|
66
|
+
console.log('Signing manifest...');
|
|
67
|
+
if (signatureType) {
|
|
68
|
+
manifest.signatureType = signatureType;
|
|
69
|
+
}
|
|
70
|
+
if (rootUrls && rootUrls.length > 0) {
|
|
71
|
+
rootUrls.forEach(pluginValidation_1.assertRootUrlIsValid);
|
|
72
|
+
manifest.rootUrls = rootUrls;
|
|
73
|
+
}
|
|
74
|
+
manifest.signPlugin = { version: (0, getVersion_1.getVersion)() };
|
|
75
|
+
return [4, (0, manifest_1.signManifest)(manifest)];
|
|
76
|
+
case 3:
|
|
77
|
+
signedManifest = _a.sent();
|
|
78
|
+
console.log('Saving signed manifest...');
|
|
79
|
+
(0, manifest_1.saveManifest)(pluginDistDir, signedManifest);
|
|
80
|
+
console.log('Signed successfully');
|
|
81
|
+
return [3, 5];
|
|
82
|
+
case 4:
|
|
83
|
+
err_1 = _a.sent();
|
|
84
|
+
console.warn(err_1);
|
|
85
|
+
return [3, 5];
|
|
86
|
+
case 5: return [2];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}); };
|
|
90
|
+
exports.sign = sign;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.getVersion = void 0;
|
|
4
|
+
var fs_1 = require("fs");
|
|
5
|
+
var path_1 = require("path");
|
|
6
|
+
var getVersion = function () {
|
|
7
|
+
var packageJsonPath = (0, path_1.resolve)(__dirname, '..', '..', 'package.json');
|
|
8
|
+
var pkg = (0, fs_1.readFileSync)(packageJsonPath, 'utf8');
|
|
9
|
+
var version = JSON.parse(pkg).version;
|
|
10
|
+
if (!version) {
|
|
11
|
+
throw "Could not find the version of sign-plugin";
|
|
12
|
+
}
|
|
13
|
+
return version;
|
|
14
|
+
};
|
|
15
|
+
exports.getVersion = getVersion;
|
|
@@ -0,0 +1,260 @@
|
|
|
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 (_) 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: n === "return" } : 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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
74
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
75
|
+
};
|
|
76
|
+
exports.__esModule = true;
|
|
77
|
+
exports.saveManifest = exports.signManifest = exports.buildManifest = void 0;
|
|
78
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
79
|
+
var promises_1 = __importDefault(require("fs/promises"));
|
|
80
|
+
var fs_1 = require("fs");
|
|
81
|
+
var path_1 = __importDefault(require("path"));
|
|
82
|
+
var axios_1 = __importDefault(require("axios"));
|
|
83
|
+
var MANIFEST_FILE = 'MANIFEST.txt';
|
|
84
|
+
function walk(dir, baseDir) {
|
|
85
|
+
return __asyncGenerator(this, arguments, function walk_1() {
|
|
86
|
+
var _a, _b, d, entry, realPath, stats, e_1_1;
|
|
87
|
+
var e_1, _c;
|
|
88
|
+
return __generator(this, function (_d) {
|
|
89
|
+
switch (_d.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
_d.trys.push([0, 17, 18, 23]);
|
|
92
|
+
return [4, __await(promises_1["default"].opendir(dir))];
|
|
93
|
+
case 1:
|
|
94
|
+
_a = __asyncValues.apply(void 0, [_d.sent()]);
|
|
95
|
+
_d.label = 2;
|
|
96
|
+
case 2: return [4, __await(_a.next())];
|
|
97
|
+
case 3:
|
|
98
|
+
if (!(_b = _d.sent(), !_b.done)) return [3, 16];
|
|
99
|
+
d = _b.value;
|
|
100
|
+
entry = path_1["default"].join(dir, d.name);
|
|
101
|
+
if (!d.isDirectory()) return [3, 7];
|
|
102
|
+
return [4, __await(walk(entry, baseDir))];
|
|
103
|
+
case 4: return [5, __values(__asyncDelegator.apply(void 0, [__asyncValues.apply(void 0, [_d.sent()])]))];
|
|
104
|
+
case 5: return [4, __await.apply(void 0, [_d.sent()])];
|
|
105
|
+
case 6:
|
|
106
|
+
_d.sent();
|
|
107
|
+
return [3, 15];
|
|
108
|
+
case 7:
|
|
109
|
+
if (!d.isFile()) return [3, 10];
|
|
110
|
+
return [4, __await(path_1["default"].relative(baseDir, entry))];
|
|
111
|
+
case 8: return [4, _d.sent()];
|
|
112
|
+
case 9:
|
|
113
|
+
_d.sent();
|
|
114
|
+
return [3, 15];
|
|
115
|
+
case 10:
|
|
116
|
+
if (!d.isSymbolicLink()) return [3, 15];
|
|
117
|
+
return [4, __await(promises_1["default"].realpath(entry))];
|
|
118
|
+
case 11:
|
|
119
|
+
realPath = _d.sent();
|
|
120
|
+
if (!realPath.startsWith(baseDir)) {
|
|
121
|
+
throw new Error("symbolic link ".concat(path_1["default"].relative(baseDir, entry), " targets a file outside of the base directory: ").concat(baseDir));
|
|
122
|
+
}
|
|
123
|
+
return [4, __await(promises_1["default"].stat(realPath))];
|
|
124
|
+
case 12:
|
|
125
|
+
stats = _d.sent();
|
|
126
|
+
if (!stats.isFile()) return [3, 15];
|
|
127
|
+
return [4, __await(path_1["default"].relative(baseDir, entry))];
|
|
128
|
+
case 13: return [4, _d.sent()];
|
|
129
|
+
case 14:
|
|
130
|
+
_d.sent();
|
|
131
|
+
_d.label = 15;
|
|
132
|
+
case 15: return [3, 2];
|
|
133
|
+
case 16: return [3, 23];
|
|
134
|
+
case 17:
|
|
135
|
+
e_1_1 = _d.sent();
|
|
136
|
+
e_1 = { error: e_1_1 };
|
|
137
|
+
return [3, 23];
|
|
138
|
+
case 18:
|
|
139
|
+
_d.trys.push([18, , 21, 22]);
|
|
140
|
+
if (!(_b && !_b.done && (_c = _a["return"]))) return [3, 20];
|
|
141
|
+
return [4, __await(_c.call(_a))];
|
|
142
|
+
case 19:
|
|
143
|
+
_d.sent();
|
|
144
|
+
_d.label = 20;
|
|
145
|
+
case 20: return [3, 22];
|
|
146
|
+
case 21:
|
|
147
|
+
if (e_1) throw e_1.error;
|
|
148
|
+
return [7];
|
|
149
|
+
case 22: return [7];
|
|
150
|
+
case 23: return [2];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function buildManifest(dir) {
|
|
156
|
+
var e_2, _a;
|
|
157
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
+
var pluginJson, manifest, _b, _c, filePath, sanitisedFilePath, e_2_1;
|
|
159
|
+
return __generator(this, function (_d) {
|
|
160
|
+
switch (_d.label) {
|
|
161
|
+
case 0:
|
|
162
|
+
pluginJson = JSON.parse((0, fs_1.readFileSync)(path_1["default"].join(dir, 'plugin.json'), { encoding: 'utf8' }));
|
|
163
|
+
manifest = {
|
|
164
|
+
plugin: pluginJson.id,
|
|
165
|
+
version: pluginJson.info.version,
|
|
166
|
+
files: {}
|
|
167
|
+
};
|
|
168
|
+
_d.label = 1;
|
|
169
|
+
case 1:
|
|
170
|
+
_d.trys.push([1, 7, 8, 13]);
|
|
171
|
+
return [4, walk(dir, dir)];
|
|
172
|
+
case 2:
|
|
173
|
+
_b = __asyncValues.apply(void 0, [_d.sent()]);
|
|
174
|
+
_d.label = 3;
|
|
175
|
+
case 3: return [4, _b.next()];
|
|
176
|
+
case 4:
|
|
177
|
+
if (!(_c = _d.sent(), !_c.done)) return [3, 6];
|
|
178
|
+
filePath = _c.value;
|
|
179
|
+
if (filePath === MANIFEST_FILE) {
|
|
180
|
+
return [3, 5];
|
|
181
|
+
}
|
|
182
|
+
sanitisedFilePath = filePath.split(path_1["default"].sep).join(path_1["default"].posix.sep);
|
|
183
|
+
manifest.files[sanitisedFilePath] = crypto_1["default"]
|
|
184
|
+
.createHash('sha256')
|
|
185
|
+
.update((0, fs_1.readFileSync)(path_1["default"].join(dir, filePath)))
|
|
186
|
+
.digest('hex');
|
|
187
|
+
_d.label = 5;
|
|
188
|
+
case 5: return [3, 3];
|
|
189
|
+
case 6: return [3, 13];
|
|
190
|
+
case 7:
|
|
191
|
+
e_2_1 = _d.sent();
|
|
192
|
+
e_2 = { error: e_2_1 };
|
|
193
|
+
return [3, 13];
|
|
194
|
+
case 8:
|
|
195
|
+
_d.trys.push([8, , 11, 12]);
|
|
196
|
+
if (!(_c && !_c.done && (_a = _b["return"]))) return [3, 10];
|
|
197
|
+
return [4, _a.call(_b)];
|
|
198
|
+
case 9:
|
|
199
|
+
_d.sent();
|
|
200
|
+
_d.label = 10;
|
|
201
|
+
case 10: return [3, 12];
|
|
202
|
+
case 11:
|
|
203
|
+
if (e_2) throw e_2.error;
|
|
204
|
+
return [7];
|
|
205
|
+
case 12: return [7];
|
|
206
|
+
case 13: return [2, manifest];
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
exports.buildManifest = buildManifest;
|
|
212
|
+
function signManifest(manifest) {
|
|
213
|
+
var _a, _b;
|
|
214
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
215
|
+
var GRAFANA_API_KEY, GRAFANA_COM_URL, url, info, err_1;
|
|
216
|
+
return __generator(this, function (_c) {
|
|
217
|
+
switch (_c.label) {
|
|
218
|
+
case 0:
|
|
219
|
+
GRAFANA_API_KEY = process.env.GRAFANA_API_KEY;
|
|
220
|
+
if (!GRAFANA_API_KEY) {
|
|
221
|
+
throw new Error('You must create a GRAFANA_API_KEY env variable to sign plugins. Please see: https://grafana.com/docs/grafana/latest/developers/plugins/sign-a-plugin/#generate-an-api-key for instructions.');
|
|
222
|
+
}
|
|
223
|
+
GRAFANA_COM_URL = process.env.GRAFANA_COM_URL || 'https://grafana.com/api';
|
|
224
|
+
url = GRAFANA_COM_URL + '/plugins/ci/sign';
|
|
225
|
+
_c.label = 1;
|
|
226
|
+
case 1:
|
|
227
|
+
_c.trys.push([1, 3, , 4]);
|
|
228
|
+
return [4, axios_1["default"].post(url, manifest, {
|
|
229
|
+
headers: { Authorization: 'Bearer ' + GRAFANA_API_KEY }
|
|
230
|
+
})];
|
|
231
|
+
case 2:
|
|
232
|
+
info = _c.sent();
|
|
233
|
+
if (info.status !== 200) {
|
|
234
|
+
console.error('Error: ', info);
|
|
235
|
+
throw new Error('Error signing manifest');
|
|
236
|
+
}
|
|
237
|
+
return [2, info.data];
|
|
238
|
+
case 3:
|
|
239
|
+
err_1 = _c.sent();
|
|
240
|
+
if ((_b = (_a = err_1.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) {
|
|
241
|
+
throw new Error('Error signing manifest: ' + err_1.response.data.message);
|
|
242
|
+
}
|
|
243
|
+
throw new Error('Error signing manifest: ' + err_1.message);
|
|
244
|
+
case 4: return [2];
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
exports.signManifest = signManifest;
|
|
250
|
+
function saveManifest(dir, signedManifest) {
|
|
251
|
+
try {
|
|
252
|
+
(0, fs_1.writeFileSync)(path_1["default"].join(dir, MANIFEST_FILE), signedManifest);
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
console.error(error);
|
|
257
|
+
throw new Error('Error saving manifest');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
exports.saveManifest = saveManifest;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.assertRootUrlIsValid = exports.getPluginJson = exports.validatePluginJson = void 0;
|
|
4
|
+
var validatePluginJson = function (pluginJson) {
|
|
5
|
+
if (!pluginJson.id) {
|
|
6
|
+
throw new Error('Plugin id is missing in plugin.json');
|
|
7
|
+
}
|
|
8
|
+
if (!pluginJson.info) {
|
|
9
|
+
throw new Error('Plugin info node is missing in plugin.json');
|
|
10
|
+
}
|
|
11
|
+
if (!pluginJson.info.version) {
|
|
12
|
+
throw new Error('Plugin info.version is missing in plugin.json');
|
|
13
|
+
}
|
|
14
|
+
var types = ['panel', 'datasource', 'app'];
|
|
15
|
+
var type = pluginJson.type;
|
|
16
|
+
if (!types.includes(type)) {
|
|
17
|
+
throw new Error('Invalid plugin type in plugin.json: ' + type);
|
|
18
|
+
}
|
|
19
|
+
if (!pluginJson.id.endsWith('-' + type)) {
|
|
20
|
+
throw new Error('[plugin.json] id should end with: -' + type);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.validatePluginJson = validatePluginJson;
|
|
24
|
+
var getPluginJson = function (path) {
|
|
25
|
+
var pluginJson;
|
|
26
|
+
try {
|
|
27
|
+
pluginJson = require(path);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
throw new Error('Unable to find: ' + path);
|
|
31
|
+
}
|
|
32
|
+
(0, exports.validatePluginJson)(pluginJson);
|
|
33
|
+
return pluginJson;
|
|
34
|
+
};
|
|
35
|
+
exports.getPluginJson = getPluginJson;
|
|
36
|
+
var assertRootUrlIsValid = function (rootUrl) {
|
|
37
|
+
try {
|
|
38
|
+
new URL(rootUrl);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
throw new Error("".concat(rootUrl, " is not a valid URL"));
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.assertRootUrlIsValid = assertRootUrlIsValid;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
var pluginValidation_1 = require("./pluginValidation");
|
|
4
|
+
describe('pluginValidation', function () {
|
|
5
|
+
describe('plugin.json', function () {
|
|
6
|
+
test('missing plugin.json file', function () {
|
|
7
|
+
expect(function () { return (0, pluginValidation_1.getPluginJson)("".concat(__dirname, "/mocks/missing-plugin.json")); }).toThrowError();
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
describe('validatePluginJson', function () {
|
|
11
|
+
test('missing "id" field in the plugin.json file', function () {
|
|
12
|
+
expect(function () { return (0, pluginValidation_1.validatePluginJson)({}); }).toThrow('Plugin id is missing in plugin.json');
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
});
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@grafana/sign-plugin",
|
|
3
|
+
"version": "0.0.1-canary.127.7d9f230.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"directory": "packages/sign-plugin",
|
|
7
|
+
"url": "https://github.com/grafana/plugin-tools"
|
|
8
|
+
},
|
|
9
|
+
"author": "Grafana",
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"bin": "./dist/bin/run.js",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"registry": "https://registry.npmjs.org/",
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"clean": "rm -rf ./dist",
|
|
18
|
+
"build": "yarn clean && tsc && chmod +x ./dist/bin/run.js",
|
|
19
|
+
"dev": "nodemon --exec 'tsc'",
|
|
20
|
+
"lint": "eslint --cache --ext .js,.jsx,.ts,.tsx ./src",
|
|
21
|
+
"lint:fix": "yarn lint --fix",
|
|
22
|
+
"test": "jest",
|
|
23
|
+
"typecheck": "tsc --noEmit"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"axios": "^1.1.3",
|
|
27
|
+
"minimist": "^1.2.2"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/minimist": "^1.2.2"
|
|
31
|
+
},
|
|
32
|
+
"nodemonConfig": {
|
|
33
|
+
"watch": [
|
|
34
|
+
"src/**/*"
|
|
35
|
+
],
|
|
36
|
+
"ext": "*",
|
|
37
|
+
"events": {
|
|
38
|
+
"start": "cls || clear"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=16"
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "7d9f230a5b700fbbb315ece3a0d6e78ac23644d5"
|
|
45
|
+
}
|
package/src/bin/run.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './sign.command';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import minimist from 'minimist';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
|
+
import { assertRootUrlIsValid } from '../utils/pluginValidation';
|
|
5
|
+
import { buildManifest, signManifest, saveManifest } from '../utils/manifest';
|
|
6
|
+
import { getVersion } from '../utils/getVersion';
|
|
7
|
+
|
|
8
|
+
export const sign = async (argv: minimist.ParsedArgs) => {
|
|
9
|
+
const pluginDistDir = path.resolve('dist');
|
|
10
|
+
const signatureType: string = argv.signatureType;
|
|
11
|
+
const rootUrls: string[] = argv.rootUrls.split(',');
|
|
12
|
+
|
|
13
|
+
if (!existsSync(pluginDistDir)) {
|
|
14
|
+
throw new Error('Plugin `dist` directory is missing. Did you build the plugin before attempting to sign?');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
console.log('Building manifest...');
|
|
19
|
+
const manifest = await buildManifest(pluginDistDir);
|
|
20
|
+
|
|
21
|
+
console.log('Signing manifest...');
|
|
22
|
+
if (signatureType) {
|
|
23
|
+
manifest.signatureType = signatureType;
|
|
24
|
+
}
|
|
25
|
+
if (rootUrls && rootUrls.length > 0) {
|
|
26
|
+
rootUrls.forEach(assertRootUrlIsValid);
|
|
27
|
+
manifest.rootUrls = rootUrls;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
manifest.signPlugin = { version: getVersion() };
|
|
31
|
+
const signedManifest = await signManifest(manifest);
|
|
32
|
+
|
|
33
|
+
console.log('Saving signed manifest...');
|
|
34
|
+
saveManifest(pluginDistDir, signedManifest);
|
|
35
|
+
|
|
36
|
+
console.log('Signed successfully');
|
|
37
|
+
} catch (err) {
|
|
38
|
+
console.warn(err);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
|
|
4
|
+
export const getVersion = () => {
|
|
5
|
+
const packageJsonPath = resolve(__dirname, '..', '..', 'package.json');
|
|
6
|
+
const pkg = readFileSync(packageJsonPath, 'utf8');
|
|
7
|
+
const { version } = JSON.parse(pkg);
|
|
8
|
+
if (!version) {
|
|
9
|
+
throw `Could not find the version of sign-plugin`;
|
|
10
|
+
}
|
|
11
|
+
return version;
|
|
12
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
|
|
7
|
+
const MANIFEST_FILE = 'MANIFEST.txt';
|
|
8
|
+
|
|
9
|
+
export interface ManifestInfo {
|
|
10
|
+
// time: number; << filled in by the server
|
|
11
|
+
// keyId: string; << filled in by the server
|
|
12
|
+
// signedByOrg: string; << filled in by the server
|
|
13
|
+
// signedByOrgName: string; << filled in by the server
|
|
14
|
+
signatureType?: string; // filled in by the server if not specified
|
|
15
|
+
rootUrls?: string[]; // for private signatures
|
|
16
|
+
plugin: string;
|
|
17
|
+
version: string;
|
|
18
|
+
files: Record<string, string>;
|
|
19
|
+
signPlugin?: {
|
|
20
|
+
version: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type RecursiveWalk = AsyncGenerator<string, void | RecursiveWalk>;
|
|
25
|
+
|
|
26
|
+
async function* walk(dir: string, baseDir: string): RecursiveWalk {
|
|
27
|
+
for await (const d of await fs.opendir(dir)) {
|
|
28
|
+
const entry = path.join(dir, d.name);
|
|
29
|
+
if (d.isDirectory()) {
|
|
30
|
+
yield* await walk(entry, baseDir);
|
|
31
|
+
} else if (d.isFile()) {
|
|
32
|
+
yield path.relative(baseDir, entry);
|
|
33
|
+
} else if (d.isSymbolicLink()) {
|
|
34
|
+
const realPath = await fs.realpath(entry);
|
|
35
|
+
if (!realPath.startsWith(baseDir)) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`symbolic link ${path.relative(baseDir, entry)} targets a file outside of the base directory: ${baseDir}`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
// if resolved symlink target is a file include it in the manifest
|
|
41
|
+
const stats = await fs.stat(realPath);
|
|
42
|
+
if (stats.isFile()) {
|
|
43
|
+
yield path.relative(baseDir, entry);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function buildManifest(dir: string): Promise<ManifestInfo> {
|
|
50
|
+
const pluginJson = JSON.parse(readFileSync(path.join(dir, 'plugin.json'), { encoding: 'utf8' }));
|
|
51
|
+
|
|
52
|
+
const manifest = {
|
|
53
|
+
plugin: pluginJson.id,
|
|
54
|
+
version: pluginJson.info.version,
|
|
55
|
+
files: {},
|
|
56
|
+
} as ManifestInfo;
|
|
57
|
+
|
|
58
|
+
for await (const filePath of await walk(dir, dir)) {
|
|
59
|
+
if (filePath === MANIFEST_FILE) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Signing plugins on Windows can create invalid paths with `\\` in the manifest
|
|
64
|
+
// causing `Modified signature` errors in Grafana. Regardless of OS make sure
|
|
65
|
+
// we have a posix compatible path.
|
|
66
|
+
const sanitisedFilePath = filePath.split(path.sep).join(path.posix.sep);
|
|
67
|
+
|
|
68
|
+
manifest.files[sanitisedFilePath] = crypto
|
|
69
|
+
.createHash('sha256')
|
|
70
|
+
.update(readFileSync(path.join(dir, filePath)))
|
|
71
|
+
.digest('hex');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return manifest;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function signManifest(manifest: ManifestInfo): Promise<string> {
|
|
78
|
+
const GRAFANA_API_KEY = process.env.GRAFANA_API_KEY;
|
|
79
|
+
if (!GRAFANA_API_KEY) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
'You must create a GRAFANA_API_KEY env variable to sign plugins. Please see: https://grafana.com/docs/grafana/latest/developers/plugins/sign-a-plugin/#generate-an-api-key for instructions.'
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const GRAFANA_COM_URL = process.env.GRAFANA_COM_URL || 'https://grafana.com/api';
|
|
86
|
+
const url = GRAFANA_COM_URL + '/plugins/ci/sign';
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const info = await axios.post(url, manifest, {
|
|
90
|
+
headers: { Authorization: 'Bearer ' + GRAFANA_API_KEY },
|
|
91
|
+
});
|
|
92
|
+
if (info.status !== 200) {
|
|
93
|
+
console.error('Error: ', info);
|
|
94
|
+
throw new Error('Error signing manifest');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return info.data;
|
|
98
|
+
} catch (err: any) {
|
|
99
|
+
if (err.response?.data?.message) {
|
|
100
|
+
throw new Error('Error signing manifest: ' + err.response.data.message);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
throw new Error('Error signing manifest: ' + err.message);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function saveManifest(dir: string, signedManifest: string) {
|
|
108
|
+
try {
|
|
109
|
+
writeFileSync(path.join(dir, MANIFEST_FILE), signedManifest);
|
|
110
|
+
return true;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error(error);
|
|
113
|
+
throw new Error('Error saving manifest');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getPluginJson, validatePluginJson } from './pluginValidation';
|
|
2
|
+
|
|
3
|
+
describe('pluginValidation', () => {
|
|
4
|
+
describe('plugin.json', () => {
|
|
5
|
+
test('missing plugin.json file', () => {
|
|
6
|
+
expect(() => getPluginJson(`${__dirname}/mocks/missing-plugin.json`)).toThrowError();
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('validatePluginJson', () => {
|
|
11
|
+
test('missing "id" field in the plugin.json file', () => {
|
|
12
|
+
expect(() => validatePluginJson({})).toThrow('Plugin id is missing in plugin.json');
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export const validatePluginJson = (pluginJson: any) => {
|
|
2
|
+
if (!pluginJson.id) {
|
|
3
|
+
throw new Error('Plugin id is missing in plugin.json');
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
if (!pluginJson.info) {
|
|
7
|
+
throw new Error('Plugin info node is missing in plugin.json');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (!pluginJson.info.version) {
|
|
11
|
+
throw new Error('Plugin info.version is missing in plugin.json');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const types = ['panel', 'datasource', 'app'];
|
|
15
|
+
const type = pluginJson.type;
|
|
16
|
+
if (!types.includes(type)) {
|
|
17
|
+
throw new Error('Invalid plugin type in plugin.json: ' + type);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!pluginJson.id.endsWith('-' + type)) {
|
|
21
|
+
throw new Error('[plugin.json] id should end with: -' + type);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const getPluginJson = (path: string) => {
|
|
26
|
+
let pluginJson;
|
|
27
|
+
try {
|
|
28
|
+
pluginJson = require(path);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw new Error('Unable to find: ' + path);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
validatePluginJson(pluginJson);
|
|
34
|
+
|
|
35
|
+
return pluginJson;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const assertRootUrlIsValid = (rootUrl: string) => {
|
|
39
|
+
try {
|
|
40
|
+
new URL(rootUrl);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
throw new Error(`${rootUrl} is not a valid URL`);
|
|
43
|
+
}
|
|
44
|
+
};
|