@abayramli/backstage-plugin-template-pulse-backend 0.0.0-stage → 0.1.1
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/LICENSE +201 -0
- package/README.md +18 -2
- package/config.schema.json +27 -0
- package/dist/ScaffolderTasksClient.cjs.js +95 -0
- package/dist/ScaffolderTasksClient.cjs.js.map +1 -0
- package/dist/index.cjs.js +10 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/plugin.cjs.js +61 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/router.cjs.js +271 -0
- package/dist/router.cjs.js.map +1 -0
- package/package.json +86 -3
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
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Template Pulse backend
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Analytics for Scaffolder runs, controlled by Backstage permissions.
|
|
4
|
+
|
|
5
|
+
Requires Backstage's new backend system and Node.js 22 or 24.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
yarn workspace backend add @abayramli/backstage-plugin-template-pulse-backend @abayramli/backstage-plugin-template-pulse-common
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Register it alongside your Scaffolder and permission backends:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
backend.add(import('@abayramli/backstage-plugin-template-pulse-backend'));
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Follow the [installation guide](https://github.com/alibayramli/template-pulse#add-to-backstage) to enable permissions and choose who can view their own runs or runs across the organization. Team filters require organization access and use the catalog group's current direct members.
|
|
18
|
+
|
|
19
|
+
By default, the backend reads the latest 200 Scaffolder runs through its public API (`templatePulse.historySource: service`). Add the optional [database history module](https://github.com/alibayramli/template-pulse/tree/main/plugins/scaffolder-backend-module-template-pulse) and set `templatePulse.historySource: database` to include all runs still stored in Scaffolder's database.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"templatePulse": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"maxTasks": {
|
|
9
|
+
"type": "number",
|
|
10
|
+
"description": "Service scan limit, or database detail page size. Default 200; range 1-1000."
|
|
11
|
+
},
|
|
12
|
+
"historySource": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"enum": [
|
|
15
|
+
"database",
|
|
16
|
+
"service"
|
|
17
|
+
],
|
|
18
|
+
"description": "Database uses the Scaffolder history module; service uses the bounded public API. Default service."
|
|
19
|
+
},
|
|
20
|
+
"maxHistoryRows": {
|
|
21
|
+
"type": "number",
|
|
22
|
+
"description": "Maximum database rollup groups per dimension. Summary metrics remain complete; filter choices use bounded server search. Default 10000; range 1-100000."
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var errors = require('@backstage/errors');
|
|
4
|
+
|
|
5
|
+
async function readBody(response, maxBytes, signal, onBytes) {
|
|
6
|
+
if (Number(response.headers.get("content-length")) > maxBytes) {
|
|
7
|
+
await response.body?.cancel();
|
|
8
|
+
throw new errors.ServiceUnavailableError(
|
|
9
|
+
"Scaffolder response exceeds the analytics size limit"
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
if (!response.body) return "";
|
|
13
|
+
const reader = response.body.getReader();
|
|
14
|
+
const decoder = new TextDecoder();
|
|
15
|
+
let bytes = 0;
|
|
16
|
+
let text = "";
|
|
17
|
+
try {
|
|
18
|
+
while (!signal.aborted) {
|
|
19
|
+
signal.throwIfAborted();
|
|
20
|
+
const chunk = await reader.read();
|
|
21
|
+
if (chunk.done) break;
|
|
22
|
+
bytes += chunk.value.byteLength;
|
|
23
|
+
onBytes?.(chunk.value.byteLength);
|
|
24
|
+
if (bytes > maxBytes)
|
|
25
|
+
throw new errors.ServiceUnavailableError(
|
|
26
|
+
"Scaffolder response exceeds the analytics size limit"
|
|
27
|
+
);
|
|
28
|
+
text += decoder.decode(chunk.value, { stream: true });
|
|
29
|
+
}
|
|
30
|
+
signal.throwIfAborted();
|
|
31
|
+
return text + decoder.decode();
|
|
32
|
+
} catch (error) {
|
|
33
|
+
await reader.cancel().catch(() => void 0);
|
|
34
|
+
throw error;
|
|
35
|
+
} finally {
|
|
36
|
+
reader.releaseLock();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
class ScaffolderTasksClient {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.options = options;
|
|
42
|
+
}
|
|
43
|
+
options;
|
|
44
|
+
async listTasks(request, options) {
|
|
45
|
+
const params = new URLSearchParams();
|
|
46
|
+
for (const [key, value] of Object.entries(request)) {
|
|
47
|
+
if (value !== void 0) params.set(key, String(value));
|
|
48
|
+
}
|
|
49
|
+
const body = await this.get(
|
|
50
|
+
`/v2/tasks?${params}`,
|
|
51
|
+
options.credentials,
|
|
52
|
+
8 * 1024 * 1024,
|
|
53
|
+
options.signal
|
|
54
|
+
);
|
|
55
|
+
return { items: body.tasks, totalItems: body.totalTasks };
|
|
56
|
+
}
|
|
57
|
+
async getLogs(request, options) {
|
|
58
|
+
return this.get(
|
|
59
|
+
`/v2/tasks/${encodeURIComponent(request.taskId)}/events`,
|
|
60
|
+
options.credentials,
|
|
61
|
+
2 * 1024 * 1024,
|
|
62
|
+
options.signal,
|
|
63
|
+
options.onBytes
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
async get(endpoint, credentials, maxBytes, requestSignal, onBytes) {
|
|
67
|
+
const timeout = AbortSignal.timeout(3e4);
|
|
68
|
+
const signal = requestSignal ? AbortSignal.any([requestSignal, timeout]) : timeout;
|
|
69
|
+
signal.throwIfAborted();
|
|
70
|
+
const baseUrl = await this.options.discovery.getBaseUrl("scaffolder");
|
|
71
|
+
const { token } = await this.options.auth.getPluginRequestToken({
|
|
72
|
+
onBehalfOf: credentials,
|
|
73
|
+
targetPluginId: "scaffolder"
|
|
74
|
+
});
|
|
75
|
+
signal.throwIfAborted();
|
|
76
|
+
const response = await fetch(`${baseUrl}${endpoint}`, {
|
|
77
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
78
|
+
signal
|
|
79
|
+
});
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
const body = await readBody(response, 64 * 1024, signal);
|
|
82
|
+
throw await errors.ResponseError.fromResponse(
|
|
83
|
+
new Response(body, {
|
|
84
|
+
status: response.status,
|
|
85
|
+
statusText: response.statusText,
|
|
86
|
+
headers: response.headers
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return JSON.parse(await readBody(response, maxBytes, signal, onBytes));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
exports.ScaffolderTasksClient = ScaffolderTasksClient;
|
|
95
|
+
//# sourceMappingURL=ScaffolderTasksClient.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScaffolderTasksClient.cjs.js","sources":["../src/ScaffolderTasksClient.ts"],"sourcesContent":["import type {\n AuthService,\n BackstageCredentials,\n DiscoveryService,\n} from '@backstage/backend-plugin-api';\nimport { ResponseError, ServiceUnavailableError } from '@backstage/errors';\nimport type {\n LogEvent,\n ScaffolderTask,\n} from '@backstage/plugin-scaffolder-common';\n\nasync function readBody(\n response: Response,\n maxBytes: number,\n signal: AbortSignal,\n onBytes?: (size: number) => void,\n) {\n if (Number(response.headers.get('content-length')) > maxBytes) {\n await response.body?.cancel();\n throw new ServiceUnavailableError(\n 'Scaffolder response exceeds the analytics size limit',\n );\n }\n if (!response.body) return '';\n const reader = response.body.getReader();\n const decoder = new TextDecoder();\n let bytes = 0;\n let text = '';\n try {\n while (!signal.aborted) {\n signal.throwIfAborted();\n const chunk = await reader.read();\n if (chunk.done) break;\n bytes += chunk.value.byteLength;\n onBytes?.(chunk.value.byteLength);\n if (bytes > maxBytes)\n throw new ServiceUnavailableError(\n 'Scaffolder response exceeds the analytics size limit',\n );\n text += decoder.decode(chunk.value, { stream: true });\n }\n signal.throwIfAborted();\n return text + decoder.decode();\n } catch (error) {\n await reader.cancel().catch(() => undefined);\n throw error;\n } finally {\n reader.releaseLock();\n }\n}\n\n// Use the public task endpoints without pulling in Scaffolder's action utilities.\nexport class ScaffolderTasksClient {\n constructor(\n private readonly options: {\n auth: AuthService;\n discovery: DiscoveryService;\n },\n ) {}\n\n async listTasks(\n request: { createdBy?: string; limit?: number; offset?: number },\n options: { credentials: BackstageCredentials; signal?: AbortSignal },\n ): Promise<{ items: ScaffolderTask[]; totalItems?: number }> {\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(request)) {\n if (value !== undefined) params.set(key, String(value));\n }\n const body = await this.get(\n `/v2/tasks?${params}`,\n options.credentials,\n 8 * 1024 * 1024,\n options.signal,\n );\n return { items: body.tasks, totalItems: body.totalTasks };\n }\n\n async getLogs(\n request: { taskId: string },\n options: {\n credentials: BackstageCredentials;\n signal?: AbortSignal;\n onBytes?: (size: number) => void;\n },\n ): Promise<LogEvent[]> {\n return this.get(\n `/v2/tasks/${encodeURIComponent(request.taskId)}/events`,\n options.credentials,\n 2 * 1024 * 1024,\n options.signal,\n options.onBytes,\n );\n }\n\n private async get(\n endpoint: string,\n credentials: BackstageCredentials,\n maxBytes: number,\n requestSignal?: AbortSignal,\n onBytes?: (size: number) => void,\n ) {\n const timeout = AbortSignal.timeout(30_000);\n const signal = requestSignal\n ? AbortSignal.any([requestSignal, timeout])\n : timeout;\n signal.throwIfAborted();\n const baseUrl = await this.options.discovery.getBaseUrl('scaffolder');\n const { token } = await this.options.auth.getPluginRequestToken({\n onBehalfOf: credentials,\n targetPluginId: 'scaffolder',\n });\n signal.throwIfAborted();\n const response = await fetch(`${baseUrl}${endpoint}`, {\n headers: { Authorization: `Bearer ${token}` },\n signal,\n });\n if (!response.ok) {\n const body = await readBody(response, 64 * 1024, signal);\n throw await ResponseError.fromResponse(\n new Response(body, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n }),\n );\n }\n return JSON.parse(await readBody(response, maxBytes, signal, onBytes));\n }\n}\n"],"names":["ServiceUnavailableError","ResponseError"],"mappings":";;;;AAWA,eAAe,QAAA,CACb,QAAA,EACA,QAAA,EACA,MAAA,EACA,OAAA,EACA;AACA,EAAA,IAAI,OAAO,QAAA,CAAS,OAAA,CAAQ,IAAI,gBAAgB,CAAC,IAAI,QAAA,EAAU;AAC7D,IAAA,MAAM,QAAA,CAAS,MAAM,MAAA,EAAO;AAC5B,IAAA,MAAM,IAAIA,8BAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,IAAI,CAAC,QAAA,CAAS,IAAA,EAAM,OAAO,EAAA;AAC3B,EAAA,MAAM,MAAA,GAAS,QAAA,CAAS,IAAA,CAAK,SAAA,EAAU;AACvC,EAAA,MAAM,OAAA,GAAU,IAAI,WAAA,EAAY;AAChC,EAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,EAAA,IAAI,IAAA,GAAO,EAAA;AACX,EAAA,IAAI;AACF,IAAA,OAAO,CAAC,OAAO,OAAA,EAAS;AACtB,MAAA,MAAA,CAAO,cAAA,EAAe;AACtB,MAAA,MAAM,KAAA,GAAQ,MAAM,MAAA,CAAO,IAAA,EAAK;AAChC,MAAA,IAAI,M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,CAAC,SAAS,EAAA,EAAI;AAChB,MAAA,MAAM,OAAO,MAAM,QAAA,CAAS,QAAA,EAAU,EAAA,GAAK,MAAM,MAAM,CAAA;AACvD,MAAA,MAAM,MAAMC,oBAAA,CAAc,YAAA;AAAA,QACxB,IAAI,SAAS,IAAA,EAAM;AAAA,UACjB,QAAQ,QAAA,CAAS,MAAA;AAAA,UACjB,YAAY,QAAA,CAAS,UAAA;AAAA,UACrB,SAAS,QAAA,CAAS;AAAA,SACnB;AAAA,OACH;AAAA,IACF;AACA,IAAA,OAAO,IAAA,CAAK,MAAM,MAAM,QAAA,CAAS,UAAU,QAAA,EAAU,MAAA,EAAQ,OAAO,CAAC,CAAA;AAAA,EACvE;AACF;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
|
|
3
|
+
/** Permission-aware template analytics for the new backend system. @public */
|
|
4
|
+
declare const templatePulsePlugin: _backstage_backend_plugin_api.BackendFeature;
|
|
5
|
+
|
|
6
|
+
export { templatePulsePlugin as default };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var backstagePluginTemplatePulseCommon = require('@abayramli/backstage-plugin-template-pulse-common');
|
|
5
|
+
var backstagePluginTemplatePulseNode = require('@abayramli/backstage-plugin-template-pulse-node');
|
|
6
|
+
var router = require('./router.cjs.js');
|
|
7
|
+
var ScaffolderTasksClient = require('./ScaffolderTasksClient.cjs.js');
|
|
8
|
+
|
|
9
|
+
const templatePulsePlugin = backendPluginApi.createBackendPlugin({
|
|
10
|
+
pluginId: "template-pulse",
|
|
11
|
+
register(env) {
|
|
12
|
+
env.registerInit({
|
|
13
|
+
deps: {
|
|
14
|
+
httpRouter: backendPluginApi.coreServices.httpRouter,
|
|
15
|
+
httpAuth: backendPluginApi.coreServices.httpAuth,
|
|
16
|
+
permissions: backendPluginApi.coreServices.permissions,
|
|
17
|
+
permissionsRegistry: backendPluginApi.coreServices.permissionsRegistry,
|
|
18
|
+
config: backendPluginApi.coreServices.rootConfig,
|
|
19
|
+
cache: backendPluginApi.coreServices.cache,
|
|
20
|
+
logger: backendPluginApi.coreServices.logger,
|
|
21
|
+
auth: backendPluginApi.coreServices.auth,
|
|
22
|
+
discovery: backendPluginApi.coreServices.discovery
|
|
23
|
+
},
|
|
24
|
+
async init({
|
|
25
|
+
httpRouter,
|
|
26
|
+
permissionsRegistry,
|
|
27
|
+
config,
|
|
28
|
+
auth,
|
|
29
|
+
discovery,
|
|
30
|
+
...services
|
|
31
|
+
}) {
|
|
32
|
+
if (config.getOptionalBoolean("permission.enabled") !== true) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"Template Pulse requires permission.enabled: true and an administrator permission policy."
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const maxTasks = config.getOptionalNumber("templatePulse.maxTasks") ?? 200;
|
|
38
|
+
if (!Number.isInteger(maxTasks) || maxTasks < 1 || maxTasks > 1e3) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
"templatePulse.maxTasks must be an integer between 1 and 1000."
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
permissionsRegistry.addPermissions(backstagePluginTemplatePulseCommon.executionsPermissions);
|
|
44
|
+
const historySource = config.getOptionalString("templatePulse.historySource") ?? "service";
|
|
45
|
+
if (!["database", "service"].includes(historySource))
|
|
46
|
+
throw new Error(
|
|
47
|
+
"templatePulse.historySource must be database or service."
|
|
48
|
+
);
|
|
49
|
+
const history = historySource === "database" ? new backstagePluginTemplatePulseNode.HistoryClient({ auth, discovery }) : void 0;
|
|
50
|
+
const teams = new backstagePluginTemplatePulseNode.TeamMembersClient({ auth, discovery });
|
|
51
|
+
const scaffolder = new ScaffolderTasksClient.ScaffolderTasksClient({ auth, discovery });
|
|
52
|
+
httpRouter.use(
|
|
53
|
+
router.createRouter({ ...services, scaffolder, maxTasks, history, teams })
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
exports.templatePulsePlugin = templatePulsePlugin;
|
|
61
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.ts"],"sourcesContent":["import {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { executionsPermissions } from '@abayramli/backstage-plugin-template-pulse-common';\nimport {\n HistoryClient,\n TeamMembersClient,\n} from '@abayramli/backstage-plugin-template-pulse-node';\nimport { createRouter } from './router';\nimport { ScaffolderTasksClient } from './ScaffolderTasksClient';\n\n/** Permission-aware template analytics for the new backend system. @public */\nexport const templatePulsePlugin = createBackendPlugin({\n pluginId: 'template-pulse',\n register(env) {\n env.registerInit({\n deps: {\n httpRouter: coreServices.httpRouter,\n httpAuth: coreServices.httpAuth,\n permissions: coreServices.permissions,\n permissionsRegistry: coreServices.permissionsRegistry,\n config: coreServices.rootConfig,\n cache: coreServices.cache,\n logger: coreServices.logger,\n auth: coreServices.auth,\n discovery: coreServices.discovery,\n },\n async init({\n httpRouter,\n permissionsRegistry,\n config,\n auth,\n discovery,\n ...services\n }) {\n // A disabled permission backend grants basic permissions automatically.\n // Require it explicitly so the administrator scope cannot become public.\n if (config.getOptionalBoolean('permission.enabled') !== true) {\n throw new Error(\n 'Template Pulse requires permission.enabled: true and an administrator permission policy.',\n );\n }\n const maxTasks =\n config.getOptionalNumber('templatePulse.maxTasks') ?? 200;\n if (!Number.isInteger(maxTasks) || maxTasks < 1 || maxTasks > 1000) {\n throw new Error(\n 'templatePulse.maxTasks must be an integer between 1 and 1000.',\n );\n }\n permissionsRegistry.addPermissions(executionsPermissions);\n const historySource =\n config.getOptionalString('templatePulse.historySource') ?? 'service';\n if (!['database', 'service'].includes(historySource))\n throw new Error(\n 'templatePulse.historySource must be database or service.',\n );\n const history =\n historySource === 'database'\n ? new HistoryClient({ auth, discovery })\n : undefined;\n const teams = new TeamMembersClient({ auth, discovery });\n const scaffolder = new ScaffolderTasksClient({ auth, discovery });\n httpRouter.use(\n createRouter({ ...services, scaffolder, maxTasks, history, teams }),\n );\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","executionsPermissions","HistoryClient","TeamMembersClient","ScaffolderTasksClient","createRouter"],"mappings":";;;;;;;;AAaO,MAAM,sBAAsBA,oCAAA,CAAoB;AAAA,EACrD,QAAA,EAAU,gBAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,YAAYC,6BAAA,CAAa,UAAA;AAAA,QACzB,UAAUA,6BAAA,CAAa,QAAA;AAAA,QACvB,aAAaA,6BAAA,CAAa,WAAA;AAAA,QAC1B,qBAAqBA,6BAAA,CAAa,mBAAA;AAAA,QAClC,QAAQA,6BAAA,CAAa,UAAA;AAAA,QACrB,OAAOA,6BAAA,CAAa,KAAA;AAAA,QACpB,QAAQA,6BAAA,CAAa,MAAA;AAAA,QACrB,MAAMA,6BAAA,CAAa,IAAA;AAAA,QACnB,WAAWA,6BAAA,CAAa;AAAA,OAC1B;AAAA,MACA,MAAM,IAAA,CAAK;AAAA,QACT,UAAA;AAAA,QACA,mBAAA;AAAA,QACA,MAAA;AAAA,QACA,IAAA;AAAA,QACA,SAAA;AAAA,QACA,GAAG;AAAA,OACL,EAAG;AAGD,QAAA,IAAI,MAAA,CAAO,kBAAA,CAAmB,oBAAoB,CAAA,KAAM,IAAA,EAAM;AAC5D,UAAA,MAAM,IAAI,KAAA;AAAA,YACR;AAAA,WACF;AAAA,QACF;AACA,QAAA,MAAM,QAAA,GACJ,MAAA,CAAO,iBAAA,CAAkB,wBAAwB,CAAA,IAAK,GAAA;AACxD,QAAA,IAAI,CAAC,OAAO,SAAA,CAAU,QAAQ,KAAK,QAAA,GAAW,CAAA,IAAK,WAAW,GAAA,EAAM;AAClE,UAAA,MAAM,IAAI,KAAA;AAAA,YACR;AAAA,WACF;AAAA,QACF;AACA,QAAA,mBAAA,CAAoB,eAAeC,wDAAqB,CAAA;AACxD,QAAA,MAAM,aAAA,GACJ,MAAA,CAAO,iBAAA,CAAkB,6BAA6B,CAAA,IAAK,SAAA;AAC7D,QAAA,IAAI,CAAC,CAAC,UAAA,EAAY,SAAS,CAAA,CAAE,SAAS,aAAa,CAAA;AACjD,UAAA,MAAM,IAAI,KAAA;AAAA,YACR;AAAA,WACF;AACF,QAAA,MAAM,OAAA,GACJ,kBAAkB,UAAA,GACd,IAAIC,+CAAc,EAAE,IAAA,EAAM,SAAA,EAAW,CAAA,GACrC,MAAA;AACN,QAAA,MAAM,QAAQ,IAAIC,kDAAA,CAAkB,EAAE,IAAA,EAAM,WAAW,CAAA;AACvD,QAAA,MAAM,aAAa,IAAIC,2CAAA,CAAsB,EAAE,IAAA,EAAM,WAAW,CAAA;AAChE,QAAA,UAAA,CAAW,GAAA;AAAA,UACTC,mBAAA,CAAa,EAAE,GAAG,QAAA,EAAU,YAAY,QAAA,EAAU,OAAA,EAAS,OAAO;AAAA,SACpE;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var pluginPermissionCommon = require('@backstage/plugin-permission-common');
|
|
4
|
+
var errors = require('@backstage/errors');
|
|
5
|
+
var Router = require('express-promise-router');
|
|
6
|
+
var backstagePluginTemplatePulseCommon = require('@abayramli/backstage-plugin-template-pulse-common');
|
|
7
|
+
var backstagePluginTemplatePulseNode = require('@abayramli/backstage-plugin-template-pulse-node');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var Router__default = /*#__PURE__*/_interopDefaultCompat(Router);
|
|
12
|
+
|
|
13
|
+
function withAbort(operation, signal) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const abort = () => reject(signal.reason);
|
|
16
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
17
|
+
if (signal.aborted) abort();
|
|
18
|
+
operation.then(
|
|
19
|
+
(value) => {
|
|
20
|
+
signal.removeEventListener("abort", abort);
|
|
21
|
+
resolve(value);
|
|
22
|
+
},
|
|
23
|
+
(error) => {
|
|
24
|
+
signal.removeEventListener("abort", abort);
|
|
25
|
+
reject(error);
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function ownerRef(task) {
|
|
31
|
+
return task.createdBy ?? task.spec.user?.ref;
|
|
32
|
+
}
|
|
33
|
+
async function mapLimited(items, fn, signal) {
|
|
34
|
+
const results = new Array(items.length);
|
|
35
|
+
let next = 0;
|
|
36
|
+
await Promise.all(
|
|
37
|
+
Array.from({ length: Math.min(4, items.length) }, async () => {
|
|
38
|
+
while (next < items.length) {
|
|
39
|
+
signal.throwIfAborted();
|
|
40
|
+
const index = next++;
|
|
41
|
+
results[index] = await fn(items[index]);
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
return results;
|
|
46
|
+
}
|
|
47
|
+
function taskMetadata(task) {
|
|
48
|
+
return {
|
|
49
|
+
id: task.id,
|
|
50
|
+
templateRef: task.spec.templateInfo?.entityRef ?? "unknown",
|
|
51
|
+
templateName: task.spec.templateInfo?.entity?.metadata.title ?? task.spec.templateInfo?.entity?.metadata.name ?? task.spec.templateInfo?.entityRef ?? "Unknown template",
|
|
52
|
+
userRef: ownerRef(task),
|
|
53
|
+
status: task.status,
|
|
54
|
+
createdAt: task.createdAt
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function projectTask(task, credentials, callerRef, { scaffolder, cache, logger }, signal, timingBudget) {
|
|
58
|
+
signal.throwIfAborted();
|
|
59
|
+
const execution = taskMetadata(task);
|
|
60
|
+
if (!["completed", "failed", "cancelled"].includes(task.status))
|
|
61
|
+
return execution;
|
|
62
|
+
const key = JSON.stringify([
|
|
63
|
+
callerRef,
|
|
64
|
+
task.id,
|
|
65
|
+
task.status,
|
|
66
|
+
task.lastHeartbeatAt
|
|
67
|
+
]);
|
|
68
|
+
const cached = await withAbort(cache.get(key), signal);
|
|
69
|
+
if (cached) return { ...execution, durationMs: cached.durationMs };
|
|
70
|
+
if (timingBudget.remainingBytes <= 0) return execution;
|
|
71
|
+
try {
|
|
72
|
+
const events = await withAbort(
|
|
73
|
+
scaffolder.getLogs(
|
|
74
|
+
{ taskId: task.id },
|
|
75
|
+
{
|
|
76
|
+
credentials,
|
|
77
|
+
signal,
|
|
78
|
+
onBytes: (size) => {
|
|
79
|
+
timingBudget.remainingBytes -= size;
|
|
80
|
+
if (timingBudget.remainingBytes < 0)
|
|
81
|
+
throw new Error("Analytics timing response budget exceeded");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
),
|
|
85
|
+
signal
|
|
86
|
+
);
|
|
87
|
+
const end = events.filter((event) => ["completion", "cancelled"].includes(event.type)).filter((event) => !event.body.status || event.body.status === task.status).map((event) => Date.parse(event.createdAt)).filter(Number.isFinite).sort((a, b) => b - a)[0];
|
|
88
|
+
const durationMs = end - Date.parse(task.createdAt);
|
|
89
|
+
if (Number.isFinite(durationMs) && durationMs >= 0) {
|
|
90
|
+
execution.durationMs = durationMs;
|
|
91
|
+
await withAbort(cache.set(key, { durationMs }, { ttl: 6e4 }), signal);
|
|
92
|
+
}
|
|
93
|
+
} catch {
|
|
94
|
+
signal.throwIfAborted();
|
|
95
|
+
logger.debug(`Execution timing unavailable for task ${task.id}`);
|
|
96
|
+
}
|
|
97
|
+
return execution;
|
|
98
|
+
}
|
|
99
|
+
function createRouter(options) {
|
|
100
|
+
const { httpAuth, permissions, scaffolder, maxTasks, history } = options;
|
|
101
|
+
const router = Router__default.default();
|
|
102
|
+
let activeAnalyticsRequests = 0;
|
|
103
|
+
async function runAnalytics(req, res, operation) {
|
|
104
|
+
if (activeAnalyticsRequests >= 4) {
|
|
105
|
+
res.setHeader("Retry-After", "2");
|
|
106
|
+
throw new errors.ServiceUnavailableError(
|
|
107
|
+
"Template Pulse analytics is busy. Try again shortly."
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
activeAnalyticsRequests++;
|
|
111
|
+
const controller = new AbortController();
|
|
112
|
+
const { signal } = controller;
|
|
113
|
+
const timeout = setTimeout(() => {
|
|
114
|
+
controller.abort(
|
|
115
|
+
new errors.ServiceUnavailableError(
|
|
116
|
+
"Template Pulse analytics timed out. Narrow the filters and try again."
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
}, 3e4);
|
|
120
|
+
timeout.unref();
|
|
121
|
+
const abort = () => {
|
|
122
|
+
if (!res.writableEnded)
|
|
123
|
+
controller.abort(
|
|
124
|
+
new errors.ServiceUnavailableError("Analytics request cancelled")
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
req.once("aborted", abort);
|
|
128
|
+
res.once("close", abort);
|
|
129
|
+
try {
|
|
130
|
+
return await withAbort(operation(signal), signal);
|
|
131
|
+
} finally {
|
|
132
|
+
clearTimeout(timeout);
|
|
133
|
+
req.removeListener("aborted", abort);
|
|
134
|
+
res.removeListener("close", abort);
|
|
135
|
+
controller.abort();
|
|
136
|
+
activeAnalyticsRequests--;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
router.get("/permissions", async (req, res) => {
|
|
140
|
+
const credentials = await httpAuth.credentials(req, { allow: ["user"] });
|
|
141
|
+
const [own, all] = await permissions.authorize(
|
|
142
|
+
[
|
|
143
|
+
{ permission: backstagePluginTemplatePulseCommon.executionsReadPermission },
|
|
144
|
+
{ permission: backstagePluginTemplatePulseCommon.executionsReadAllPermission }
|
|
145
|
+
],
|
|
146
|
+
{ credentials }
|
|
147
|
+
);
|
|
148
|
+
res.setHeader("Cache-Control", "no-store");
|
|
149
|
+
res.json({
|
|
150
|
+
canSearchHistory: Boolean(history),
|
|
151
|
+
canReadOwn: own?.result === pluginPermissionCommon.AuthorizeResult.ALLOW,
|
|
152
|
+
canReadAll: all?.result === pluginPermissionCommon.AuthorizeResult.ALLOW
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
router.get("/facets", async (req, res) => {
|
|
156
|
+
const { query, facet, search } = backstagePluginTemplatePulseNode.parseExecutionFacetQuery(req.query);
|
|
157
|
+
const credentials = await httpAuth.credentials(req, { allow: ["user"] });
|
|
158
|
+
await backstagePluginTemplatePulseNode.authorizeExecutionQuery({ query, credentials, permissions });
|
|
159
|
+
const searchFacets = history?.searchFacets?.bind(history);
|
|
160
|
+
if (!searchFacets)
|
|
161
|
+
throw new errors.InputError("Filter search requires the database history source.");
|
|
162
|
+
const result = await runAnalytics(
|
|
163
|
+
req,
|
|
164
|
+
res,
|
|
165
|
+
(signal) => searchFacets(query, credentials, facet, search, signal)
|
|
166
|
+
);
|
|
167
|
+
res.setHeader("Cache-Control", "no-store");
|
|
168
|
+
res.json(result);
|
|
169
|
+
});
|
|
170
|
+
router.get("/analytics", async (req, res) => {
|
|
171
|
+
const query = backstagePluginTemplatePulseNode.parseExecutionQuery(req.query);
|
|
172
|
+
const { scope } = query;
|
|
173
|
+
const credentials = await httpAuth.credentials(req, { allow: ["user"] });
|
|
174
|
+
const callerRef = credentials.principal.userEntityRef;
|
|
175
|
+
await backstagePluginTemplatePulseNode.authorizeExecutionQuery({ query, credentials, permissions });
|
|
176
|
+
const analytics = await runAnalytics(req, res, async (signal) => {
|
|
177
|
+
if (history) {
|
|
178
|
+
return history.search(query, credentials, maxTasks, signal);
|
|
179
|
+
}
|
|
180
|
+
if (query.allTime || query.offset || query.cursor) {
|
|
181
|
+
throw new errors.InputError(
|
|
182
|
+
"All-history search and result pagination require the database history source."
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const teamMembers = query.teamRef ? new Set(
|
|
186
|
+
await withAbort(
|
|
187
|
+
options.teams.getMembers(query.teamRef, credentials, signal),
|
|
188
|
+
signal
|
|
189
|
+
)
|
|
190
|
+
) : void 0;
|
|
191
|
+
const tasks = /* @__PURE__ */ new Map();
|
|
192
|
+
let sourceTotal;
|
|
193
|
+
let offset = 0;
|
|
194
|
+
let more = false;
|
|
195
|
+
while (offset < maxTasks) {
|
|
196
|
+
signal.throwIfAborted();
|
|
197
|
+
const limit = Math.min(100, maxTasks - offset);
|
|
198
|
+
const page = await withAbort(
|
|
199
|
+
scaffolder.listTasks(
|
|
200
|
+
{
|
|
201
|
+
createdBy: scope === "mine" ? callerRef : query.userRef,
|
|
202
|
+
limit,
|
|
203
|
+
offset
|
|
204
|
+
},
|
|
205
|
+
{ credentials, signal }
|
|
206
|
+
),
|
|
207
|
+
signal
|
|
208
|
+
);
|
|
209
|
+
sourceTotal = page.totalItems;
|
|
210
|
+
for (const task of page.items) {
|
|
211
|
+
if ((scope === "all" || ownerRef(task) === callerRef) && (!teamMembers || teamMembers.has(ownerRef(task) ?? "")))
|
|
212
|
+
tasks.set(task.id, task);
|
|
213
|
+
}
|
|
214
|
+
offset += page.items.length;
|
|
215
|
+
more = sourceTotal === void 0 ? page.items.length === limit : offset < sourceTotal;
|
|
216
|
+
if (!page.items.length || !more) break;
|
|
217
|
+
}
|
|
218
|
+
const metadata = [...tasks.values()].map(taskMetadata);
|
|
219
|
+
const from = Date.parse(query.from);
|
|
220
|
+
const to = Date.parse(query.to);
|
|
221
|
+
const cohort = [...tasks.values()].filter((task) => {
|
|
222
|
+
const row = taskMetadata(task);
|
|
223
|
+
const date = Date.parse(row.createdAt);
|
|
224
|
+
return date >= from && date < to && (!query.templateRef || row.templateRef === query.templateRef) && (!query.userRef || row.userRef === query.userRef);
|
|
225
|
+
});
|
|
226
|
+
const timingBudget = { remainingBytes: 16 * 1024 * 1024 };
|
|
227
|
+
const rows = await mapLimited(
|
|
228
|
+
cohort,
|
|
229
|
+
(task) => projectTask(task, credentials, callerRef, options, signal, timingBudget),
|
|
230
|
+
signal
|
|
231
|
+
);
|
|
232
|
+
rows.sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt));
|
|
233
|
+
const result = {
|
|
234
|
+
scope,
|
|
235
|
+
...backstagePluginTemplatePulseNode.aggregateExecutions(rows, query, maxTasks),
|
|
236
|
+
facets: {
|
|
237
|
+
templates: [
|
|
238
|
+
...new Map(
|
|
239
|
+
metadata.map((row) => [
|
|
240
|
+
row.templateRef,
|
|
241
|
+
{ id: row.templateRef, name: row.templateName }
|
|
242
|
+
])
|
|
243
|
+
).values()
|
|
244
|
+
].sort((a, b) => a.name.localeCompare(b.name)),
|
|
245
|
+
users: [
|
|
246
|
+
...new Set(
|
|
247
|
+
metadata.map((row) => row.userRef).filter((ref) => Boolean(ref))
|
|
248
|
+
)
|
|
249
|
+
].sort()
|
|
250
|
+
},
|
|
251
|
+
window: {
|
|
252
|
+
historySource: "service",
|
|
253
|
+
limit: maxTasks,
|
|
254
|
+
scanned: metadata.length,
|
|
255
|
+
sourceTotal,
|
|
256
|
+
truncated: more,
|
|
257
|
+
oldestAt: metadata.map((row) => row.createdAt).sort()[0],
|
|
258
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
signal.throwIfAborted();
|
|
262
|
+
return result;
|
|
263
|
+
});
|
|
264
|
+
res.setHeader("Cache-Control", "no-store");
|
|
265
|
+
res.json(analytics);
|
|
266
|
+
});
|
|
267
|
+
return router;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
exports.createRouter = createRouter;
|
|
271
|
+
//# sourceMappingURL=router.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.cjs.js","sources":["../src/router.ts"],"sourcesContent":["import type {\n CacheService,\n HttpAuthService,\n LoggerService,\n PermissionsService,\n} from '@backstage/backend-plugin-api';\nimport { AuthorizeResult } from '@backstage/plugin-permission-common';\nimport { InputError, ServiceUnavailableError } from '@backstage/errors';\nimport type { Request, Response } from 'express';\nimport Router from 'express-promise-router';\nimport {\n executionsReadAllPermission,\n executionsReadPermission,\n type Execution,\n type ExecutionAnalytics,\n} from '@abayramli/backstage-plugin-template-pulse-common';\nimport {\n aggregateExecutions,\n authorizeExecutionQuery,\n parseExecutionFacetQuery,\n parseExecutionQuery,\n type ExecutionHistory,\n type TeamMembersClient,\n} from '@abayramli/backstage-plugin-template-pulse-node';\nimport type { ScaffolderTasksClient } from './ScaffolderTasksClient';\n\ntype Task = Awaited<\n ReturnType<ScaffolderTasksClient['listTasks']>\n>['items'][number];\ntype Credentials = Parameters<ScaffolderTasksClient['listTasks']>[1]['credentials'];\ntype Options = {\n httpAuth: HttpAuthService;\n permissions: PermissionsService;\n scaffolder: Pick<ScaffolderTasksClient, 'listTasks' | 'getLogs'>;\n cache: CacheService;\n logger: LoggerService;\n maxTasks: number;\n history?: ExecutionHistory;\n teams: Pick<TeamMembersClient, 'getMembers'>;\n};\n\nfunction withAbort<T>(operation: Promise<T>, signal: AbortSignal): Promise<T> {\n return new Promise((resolve, reject) => {\n const abort = () => reject(signal.reason);\n signal.addEventListener('abort', abort, { once: true });\n if (signal.aborted) abort();\n operation.then(\n value => {\n signal.removeEventListener('abort', abort);\n resolve(value);\n },\n error => {\n signal.removeEventListener('abort', abort);\n reject(error);\n },\n );\n });\n}\n\nfunction ownerRef(task: Task): string | undefined {\n // The HTTP task record also carries createdBy. Prefer it over the decorated\n // catalog identity; older Scaffolder service typings only declare spec.user.\n return (\n (task as Task & { createdBy?: string }).createdBy ?? task.spec.user?.ref\n );\n}\n\nasync function mapLimited<T, R>(\n items: T[],\n fn: (item: T) => Promise<R>,\n signal: AbortSignal,\n): Promise<R[]> {\n const results = new Array<R>(items.length);\n let next = 0;\n await Promise.all(\n Array.from({ length: Math.min(4, items.length) }, async () => {\n while (next < items.length) {\n signal.throwIfAborted();\n const index = next++;\n results[index] = await fn(items[index]);\n }\n }),\n );\n return results;\n}\n\nfunction taskMetadata(task: Task): Execution {\n return {\n id: task.id,\n templateRef: task.spec.templateInfo?.entityRef ?? 'unknown',\n templateName:\n task.spec.templateInfo?.entity?.metadata.title ??\n task.spec.templateInfo?.entity?.metadata.name ??\n task.spec.templateInfo?.entityRef ??\n 'Unknown template',\n userRef: ownerRef(task),\n status: task.status,\n createdAt: task.createdAt,\n };\n}\n\nasync function projectTask(\n task: Task,\n credentials: Credentials,\n callerRef: string,\n { scaffolder, cache, logger }: Options,\n signal: AbortSignal,\n timingBudget: { remainingBytes: number },\n): Promise<Execution> {\n signal.throwIfAborted();\n const execution = taskMetadata(task);\n\n if (!['completed', 'failed', 'cancelled'].includes(task.status))\n return execution;\n\n // Cache only the timing projection, scoped to the caller. Access is evaluated\n // on each request and task listing still uses the caller's credentials.\n const key = JSON.stringify([\n callerRef,\n task.id,\n task.status,\n task.lastHeartbeatAt,\n ]);\n const cached = await withAbort(cache.get<{ durationMs: number }>(key), signal);\n if (cached) return { ...execution, durationMs: cached.durationMs };\n if (timingBudget.remainingBytes <= 0) return execution;\n\n try {\n const events = await withAbort(\n scaffolder.getLogs(\n { taskId: task.id },\n {\n credentials,\n signal,\n onBytes: size => {\n timingBudget.remainingBytes -= size;\n if (timingBudget.remainingBytes < 0)\n throw new Error('Analytics timing response budget exceeded');\n },\n },\n ),\n signal,\n );\n const end = events\n .filter(event => ['completion', 'cancelled'].includes(event.type))\n .filter(event => !event.body.status || event.body.status === task.status)\n .map(event => Date.parse(event.createdAt))\n .filter(Number.isFinite)\n .sort((a, b) => b - a)[0];\n const durationMs = end - Date.parse(task.createdAt);\n if (Number.isFinite(durationMs) && durationMs >= 0) {\n execution.durationMs = durationMs;\n await withAbort(cache.set(key, { durationMs }, { ttl: 60_000 }), signal);\n }\n } catch {\n signal.throwIfAborted();\n // Retained task metadata can outlive its events. Never infer a finish time\n // from a heartbeat, or send raw event messages to the dashboard.\n logger.debug(`Execution timing unavailable for task ${task.id}`);\n }\n return execution;\n}\n\nexport function createRouter(options: Options) {\n const { httpAuth, permissions, scaffolder, maxTasks, history } = options;\n const router = Router();\n let activeAnalyticsRequests = 0;\n\n async function runAnalytics<T>(\n req: Request,\n res: Response,\n operation: (signal: AbortSignal) => Promise<T>,\n ): Promise<T> {\n if (activeAnalyticsRequests >= 4) {\n res.setHeader('Retry-After', '2');\n throw new ServiceUnavailableError(\n 'Template Pulse analytics is busy. Try again shortly.',\n );\n }\n activeAnalyticsRequests++;\n const controller = new AbortController();\n const { signal } = controller;\n const timeout = setTimeout(() => {\n controller.abort(\n new ServiceUnavailableError(\n 'Template Pulse analytics timed out. Narrow the filters and try again.',\n ),\n );\n }, 30_000);\n timeout.unref();\n const abort = () => {\n if (!res.writableEnded)\n controller.abort(\n new ServiceUnavailableError('Analytics request cancelled'),\n );\n };\n req.once('aborted', abort);\n res.once('close', abort);\n try {\n return await withAbort(operation(signal), signal);\n } finally {\n clearTimeout(timeout);\n req.removeListener('aborted', abort);\n res.removeListener('close', abort);\n controller.abort();\n activeAnalyticsRequests--;\n }\n }\n\n router.get('/permissions', async (req, res) => {\n const credentials = await httpAuth.credentials(req, { allow: ['user'] });\n const [own, all] = await permissions.authorize(\n [\n { permission: executionsReadPermission },\n { permission: executionsReadAllPermission },\n ],\n { credentials },\n );\n res.setHeader('Cache-Control', 'no-store');\n res.json({\n canSearchHistory: Boolean(history),\n canReadOwn: own?.result === AuthorizeResult.ALLOW,\n canReadAll: all?.result === AuthorizeResult.ALLOW,\n });\n });\n\n router.get('/facets', async (req, res) => {\n const { query, facet, search } = parseExecutionFacetQuery(req.query);\n const credentials = await httpAuth.credentials(req, { allow: ['user'] });\n await authorizeExecutionQuery({ query, credentials, permissions });\n const searchFacets = history?.searchFacets?.bind(history);\n if (!searchFacets)\n throw new InputError('Filter search requires the database history source.');\n const result = await runAnalytics(req, res, signal =>\n searchFacets(query, credentials, facet, search, signal),\n );\n res.setHeader('Cache-Control', 'no-store');\n res.json(result);\n });\n\n router.get('/analytics', async (req, res) => {\n const query = parseExecutionQuery(req.query);\n const { scope } = query;\n\n const credentials = await httpAuth.credentials(req, { allow: ['user'] });\n const callerRef = credentials.principal.userEntityRef;\n await authorizeExecutionQuery({ query, credentials, permissions });\n\n const analytics = await runAnalytics(req, res, async signal => {\n if (history) {\n return history.search(query, credentials, maxTasks, signal);\n }\n if (query.allTime || query.offset || query.cursor) {\n throw new InputError(\n 'All-history search and result pagination require the database history source.',\n );\n }\n const teamMembers = query.teamRef\n ? new Set(\n await withAbort(\n options.teams.getMembers(query.teamRef, credentials, signal),\n signal,\n ),\n )\n : undefined;\n\n // Page the public service rather than relying on private Scaffolder tables.\n // Its task policy continues to apply, including administrator restrictions.\n const tasks = new Map<string, Task>();\n let sourceTotal: number | undefined;\n let offset = 0;\n let more = false;\n while (offset < maxTasks) {\n signal.throwIfAborted();\n const limit = Math.min(100, maxTasks - offset);\n const page = await withAbort(\n scaffolder.listTasks(\n {\n createdBy: scope === 'mine' ? callerRef : query.userRef,\n limit,\n offset,\n },\n { credentials, signal },\n ),\n signal,\n );\n sourceTotal = page.totalItems;\n for (const task of page.items) {\n if (\n (scope === 'all' || ownerRef(task) === callerRef) &&\n (!teamMembers || teamMembers.has(ownerRef(task) ?? ''))\n )\n tasks.set(task.id, task);\n }\n offset += page.items.length;\n more =\n sourceTotal === undefined\n ? page.items.length === limit\n : offset < sourceTotal;\n if (!page.items.length || !more) break;\n }\n\n const metadata = [...tasks.values()].map(taskMetadata);\n const from = Date.parse(query.from);\n const to = Date.parse(query.to);\n // Apply cohort filters before reading timings; execution search/status are detail-only.\n // The public Scaffolder service does not support these filters itself.\n const cohort = [...tasks.values()].filter(task => {\n const row = taskMetadata(task);\n const date = Date.parse(row.createdAt);\n return (\n date >= from &&\n date < to &&\n (!query.templateRef || row.templateRef === query.templateRef) &&\n (!query.userRef || row.userRef === query.userRef)\n );\n });\n const timingBudget = { remainingBytes: 16 * 1024 * 1024 };\n const rows = await mapLimited(\n cohort,\n task =>\n projectTask(task, credentials, callerRef, options, signal, timingBudget),\n signal,\n );\n rows.sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt));\n const result: ExecutionAnalytics = {\n scope,\n ...aggregateExecutions(rows, query, maxTasks),\n facets: {\n templates: [\n ...new Map(\n metadata.map(row => [\n row.templateRef,\n { id: row.templateRef, name: row.templateName },\n ]),\n ).values(),\n ].sort((a, b) => a.name.localeCompare(b.name)),\n users: [\n ...new Set(\n metadata\n .map(row => row.userRef)\n .filter((ref): ref is string => Boolean(ref)),\n ),\n ].sort(),\n },\n window: {\n historySource: 'service',\n limit: maxTasks,\n scanned: metadata.length,\n sourceTotal,\n truncated: more,\n oldestAt: metadata.map(row => row.createdAt).sort()[0],\n generatedAt: new Date().toISOString(),\n },\n };\n signal.throwIfAborted();\n return result;\n });\n res.setHeader('Cache-Control', 'no-store');\n res.json(analytics);\n });\n\n return router;\n}\n"],"names":["Router","ServiceUnavailableError","executionsReadPermission","executionsReadAllPermission","AuthorizeResult","parseExecutionFacetQuery","authorizeExecutionQuery","InputError","parseExecutionQuery","aggregateExecutions"],"mappings":";;;;;;;;;;;;AAyCA,SAAS,SAAA,CAAa,WAAuB,MAAA,EAAiC;AAC5E,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAA,KAAW;AACtC,IAAA,MAAM,KAAA,GAAQ,MAAM,MAAA,CAAO,MAAA,CAAO,MAAM,CAAA;AACxC,IAAA,MAAA,CAAO,iBAAiB,OAAA,EAAS,KAAA,EAAO,EAAE,IAAA,EAAM,MAAM,CAAA;AACtD,IAAA,IAAI,MAAA,CAAO,SAAS,KAAA,EAAM;AAC1B,IAAA,SAAA,CAAU,IAAA;AAAA,MACR,CAAA,KAAA,KAAS;AACP,QAAA,MAAA,CAAO,mBAAA,CAAoB,SAAS,KA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package.json
CHANGED
|
@@ -1,6 +1,89 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abayramli/backstage-plugin-template-pulse-backend",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Analytics and searchable history for Scaffolder runs, with access controlled by Backstage permissions.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"backstage": {
|
|
7
|
+
"role": "backend-plugin",
|
|
8
|
+
"pluginId": "template-pulse",
|
|
9
|
+
"features": {
|
|
10
|
+
".": "@backstage/BackendFeature"
|
|
11
|
+
},
|
|
12
|
+
"pluginPackages": [
|
|
13
|
+
"@abayramli/backstage-plugin-template-pulse",
|
|
14
|
+
"@abayramli/backstage-plugin-template-pulse-backend",
|
|
15
|
+
"@abayramli/backstage-plugin-template-pulse-common",
|
|
16
|
+
"@abayramli/backstage-plugin-template-pulse-node"
|
|
17
|
+
],
|
|
18
|
+
"peerModules": [
|
|
19
|
+
"@abayramli/backstage-plugin-scaffolder-backend-module-template-pulse"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/index.cjs.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"backstage": "@backstage/BackendFeature",
|
|
30
|
+
"require": "./dist/index.cjs.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.cjs.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"config.schema.json"
|
|
39
|
+
],
|
|
40
|
+
"configSchema": "config.schema.json",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"lint": "backstage-cli package lint",
|
|
43
|
+
"test": "backstage-cli package test",
|
|
44
|
+
"build": "backstage-cli package build",
|
|
45
|
+
"prepack": "backstage-cli package prepack",
|
|
46
|
+
"postpack": "backstage-cli package postpack",
|
|
47
|
+
"clean": "backstage-cli package clean"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@abayramli/backstage-plugin-template-pulse-common": "^0.1.1",
|
|
51
|
+
"@abayramli/backstage-plugin-template-pulse-node": "^0.1.1",
|
|
52
|
+
"@backstage/backend-plugin-api": "^1.10.1",
|
|
53
|
+
"@backstage/errors": "^1.3.1",
|
|
54
|
+
"@backstage/plugin-permission-common": "^0.9.11",
|
|
55
|
+
"@backstage/plugin-scaffolder-common": "^2.3.0",
|
|
56
|
+
"express": "^4.22.0",
|
|
57
|
+
"express-promise-router": "^4.1.1"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@backstage/cli": "^0.36.6",
|
|
61
|
+
"@types/express": "^4.17.21",
|
|
62
|
+
"@types/jest": "^30.0.0",
|
|
63
|
+
"jest": "~30.2.0"
|
|
64
|
+
},
|
|
65
|
+
"repository": {
|
|
66
|
+
"type": "git",
|
|
67
|
+
"url": "https://github.com/alibayramli/template-pulse.git",
|
|
68
|
+
"directory": "plugins/template-pulse-backend"
|
|
69
|
+
},
|
|
70
|
+
"typesVersions": {
|
|
71
|
+
"*": {
|
|
72
|
+
"package.json": [
|
|
73
|
+
"package.json"
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"homepage": "https://github.com/alibayramli/template-pulse#readme",
|
|
78
|
+
"bugs": "https://github.com/alibayramli/template-pulse/issues",
|
|
79
|
+
"keywords": [
|
|
80
|
+
"backstage",
|
|
81
|
+
"backstage-plugin",
|
|
82
|
+
"scaffolder",
|
|
83
|
+
"template-pulse",
|
|
84
|
+
"analytics"
|
|
85
|
+
],
|
|
86
|
+
"engines": {
|
|
87
|
+
"node": "22 || 24"
|
|
88
|
+
}
|
|
6
89
|
}
|