@backstage-community/plugin-nomad-backend 0.1.20

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/CHANGELOG.md ADDED
@@ -0,0 +1,431 @@
1
+ # @backstage-community/plugin-nomad-backend
2
+
3
+ ## 0.1.20
4
+
5
+ ### Patch Changes
6
+
7
+ - afff3cf: Migrated from the [backstage/backstage](https://github.com/backstage/backstage) monorepo.
8
+
9
+ ## 0.1.19
10
+
11
+ ### Patch Changes
12
+
13
+ - d5a1fe1: Replaced winston logger with `LoggerService`
14
+ - Updated dependencies
15
+ - @backstage/backend-common@0.21.7
16
+ - @backstage/backend-plugin-api@0.6.17
17
+ - @backstage/config@1.2.0
18
+ - @backstage/errors@1.2.4
19
+
20
+ ## 0.1.19-next.1
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies
25
+ - @backstage/backend-common@0.21.7-next.1
26
+ - @backstage/backend-plugin-api@0.6.17-next.1
27
+ - @backstage/config@1.2.0
28
+ - @backstage/errors@1.2.4
29
+
30
+ ## 0.1.19-next.0
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies
35
+ - @backstage/backend-common@0.21.7-next.0
36
+ - @backstage/backend-plugin-api@0.6.17-next.0
37
+ - @backstage/config@1.2.0
38
+ - @backstage/errors@1.2.4
39
+
40
+ ## 0.1.18
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies
45
+ - @backstage/backend-common@0.21.6
46
+ - @backstage/backend-plugin-api@0.6.16
47
+ - @backstage/config@1.2.0
48
+ - @backstage/errors@1.2.4
49
+
50
+ ## 0.1.17
51
+
52
+ ### Patch Changes
53
+
54
+ - Updated dependencies
55
+ - @backstage/backend-common@0.21.5
56
+ - @backstage/backend-plugin-api@0.6.15
57
+ - @backstage/config@1.2.0
58
+ - @backstage/errors@1.2.4
59
+
60
+ ## 0.1.16
61
+
62
+ ### Patch Changes
63
+
64
+ - 4467036: Allow unauthenticated access to health check endpoint.
65
+ - Updated dependencies
66
+ - @backstage/backend-common@0.21.4
67
+ - @backstage/config@1.2.0
68
+ - @backstage/errors@1.2.4
69
+ - @backstage/backend-plugin-api@0.6.14
70
+
71
+ ## 0.1.16-next.2
72
+
73
+ ### Patch Changes
74
+
75
+ - Updated dependencies
76
+ - @backstage/backend-common@0.21.4-next.2
77
+ - @backstage/backend-plugin-api@0.6.14-next.2
78
+ - @backstage/config@1.2.0-next.1
79
+ - @backstage/errors@1.2.4-next.0
80
+
81
+ ## 0.1.16-next.1
82
+
83
+ ### Patch Changes
84
+
85
+ - Updated dependencies
86
+ - @backstage/config@1.2.0-next.1
87
+ - @backstage/backend-common@0.21.4-next.1
88
+ - @backstage/backend-plugin-api@0.6.14-next.1
89
+ - @backstage/errors@1.2.4-next.0
90
+
91
+ ## 0.1.15-next.0
92
+
93
+ ### Patch Changes
94
+
95
+ - Updated dependencies
96
+ - @backstage/backend-common@0.21.3-next.0
97
+ - @backstage/errors@1.2.4-next.0
98
+ - @backstage/backend-plugin-api@0.6.13-next.0
99
+ - @backstage/config@1.1.2-next.0
100
+
101
+ ## 0.1.12
102
+
103
+ ### Patch Changes
104
+
105
+ - 9aac2b0: Use `--cwd` as the first `yarn` argument
106
+ - Updated dependencies
107
+ - @backstage/backend-common@0.21.0
108
+ - @backstage/backend-plugin-api@0.6.10
109
+ - @backstage/config@1.1.1
110
+ - @backstage/errors@1.2.3
111
+
112
+ ## 0.1.12-next.3
113
+
114
+ ### Patch Changes
115
+
116
+ - Updated dependencies
117
+ - @backstage/backend-common@0.21.0-next.3
118
+ - @backstage/backend-plugin-api@0.6.10-next.3
119
+ - @backstage/config@1.1.1
120
+ - @backstage/errors@1.2.3
121
+
122
+ ## 0.1.12-next.2
123
+
124
+ ### Patch Changes
125
+
126
+ - 9aac2b0: Use `--cwd` as the first `yarn` argument
127
+ - Updated dependencies
128
+ - @backstage/backend-common@0.21.0-next.2
129
+ - @backstage/backend-plugin-api@0.6.10-next.2
130
+ - @backstage/config@1.1.1
131
+ - @backstage/errors@1.2.3
132
+
133
+ ## 0.1.12-next.1
134
+
135
+ ### Patch Changes
136
+
137
+ - Updated dependencies
138
+ - @backstage/backend-plugin-api@0.6.10-next.1
139
+ - @backstage/backend-common@0.21.0-next.1
140
+ - @backstage/config@1.1.1
141
+ - @backstage/errors@1.2.3
142
+
143
+ ## 0.1.12-next.0
144
+
145
+ ### Patch Changes
146
+
147
+ - Updated dependencies
148
+ - @backstage/backend-common@0.21.0-next.0
149
+ - @backstage/backend-plugin-api@0.6.10-next.0
150
+ - @backstage/config@1.1.1
151
+ - @backstage/errors@1.2.3
152
+
153
+ ## 0.1.11
154
+
155
+ ### Patch Changes
156
+
157
+ - 4016f21: Remove some unused dependencies
158
+ - Updated dependencies
159
+ - @backstage/backend-common@0.20.1
160
+ - @backstage/backend-plugin-api@0.6.9
161
+ - @backstage/config@1.1.1
162
+ - @backstage/errors@1.2.3
163
+
164
+ ## 0.1.11-next.2
165
+
166
+ ### Patch Changes
167
+
168
+ - Updated dependencies
169
+ - @backstage/backend-plugin-api@0.6.9-next.2
170
+ - @backstage/backend-common@0.20.1-next.2
171
+
172
+ ## 0.1.11-next.1
173
+
174
+ ### Patch Changes
175
+
176
+ - Updated dependencies
177
+ - @backstage/backend-common@0.20.1-next.1
178
+ - @backstage/config@1.1.1
179
+ - @backstage/backend-plugin-api@0.6.9-next.1
180
+ - @backstage/errors@1.2.3
181
+
182
+ ## 0.1.11-next.0
183
+
184
+ ### Patch Changes
185
+
186
+ - 4016f21: Remove some unused dependencies
187
+ - Updated dependencies
188
+ - @backstage/backend-common@0.20.1-next.0
189
+ - @backstage/backend-plugin-api@0.6.9-next.0
190
+ - @backstage/config@1.1.1
191
+ - @backstage/errors@1.2.3
192
+
193
+ ## 0.1.10
194
+
195
+ ### Patch Changes
196
+
197
+ - Updated dependencies
198
+ - @backstage/backend-common@0.20.0
199
+ - @backstage/backend-plugin-api@0.6.8
200
+ - @backstage/config@1.1.1
201
+ - @backstage/errors@1.2.3
202
+
203
+ ## 0.1.10-next.3
204
+
205
+ ### Patch Changes
206
+
207
+ - Updated dependencies
208
+ - @backstage/backend-common@0.20.0-next.3
209
+ - @backstage/backend-plugin-api@0.6.8-next.3
210
+ - @backstage/config@1.1.1
211
+ - @backstage/errors@1.2.3
212
+
213
+ ## 0.1.10-next.2
214
+
215
+ ### Patch Changes
216
+
217
+ - Updated dependencies
218
+ - @backstage/backend-common@0.20.0-next.2
219
+ - @backstage/backend-plugin-api@0.6.8-next.2
220
+ - @backstage/config@1.1.1
221
+ - @backstage/errors@1.2.3
222
+
223
+ ## 0.1.10-next.1
224
+
225
+ ### Patch Changes
226
+
227
+ - Updated dependencies
228
+ - @backstage/backend-common@0.20.0-next.1
229
+ - @backstage/backend-plugin-api@0.6.8-next.1
230
+ - @backstage/config@1.1.1
231
+ - @backstage/errors@1.2.3
232
+
233
+ ## 0.1.10-next.0
234
+
235
+ ### Patch Changes
236
+
237
+ - Updated dependencies
238
+ - @backstage/backend-common@0.20.0-next.0
239
+ - @backstage/backend-plugin-api@0.6.8-next.0
240
+ - @backstage/config@1.1.1
241
+ - @backstage/errors@1.2.3
242
+
243
+ ## 0.1.9
244
+
245
+ ### Patch Changes
246
+
247
+ - Updated dependencies
248
+ - @backstage/backend-common@0.19.9
249
+ - @backstage/backend-plugin-api@0.6.7
250
+ - @backstage/config@1.1.1
251
+ - @backstage/errors@1.2.3
252
+
253
+ ## 0.1.9-next.2
254
+
255
+ ### Patch Changes
256
+
257
+ - Updated dependencies
258
+ - @backstage/backend-plugin-api@0.6.7-next.2
259
+ - @backstage/backend-common@0.19.9-next.2
260
+
261
+ ## 0.1.9-next.1
262
+
263
+ ### Patch Changes
264
+
265
+ - Updated dependencies
266
+ - @backstage/backend-common@0.19.9-next.1
267
+ - @backstage/backend-plugin-api@0.6.7-next.1
268
+ - @backstage/config@1.1.1
269
+ - @backstage/errors@1.2.3
270
+
271
+ ## 0.1.9-next.0
272
+
273
+ ### Patch Changes
274
+
275
+ - Updated dependencies
276
+ - @backstage/backend-common@0.19.9-next.0
277
+ - @backstage/backend-plugin-api@0.6.7-next.0
278
+ - @backstage/config@1.1.1
279
+ - @backstage/errors@1.2.3
280
+
281
+ ## 0.1.8
282
+
283
+ ### Patch Changes
284
+
285
+ - 6822918c50: Added support for the [new backend system](https://backstage.io/docs/backend-system/)
286
+ - Updated dependencies
287
+ - @backstage/backend-common@0.19.8
288
+ - @backstage/errors@1.2.3
289
+ - @backstage/backend-plugin-api@0.6.6
290
+ - @backstage/config@1.1.1
291
+
292
+ ## 0.1.8-next.2
293
+
294
+ ### Patch Changes
295
+
296
+ - 6822918c50: Added support for the [new backend system](https://backstage.io/docs/backend-system/)
297
+ - Updated dependencies
298
+ - @backstage/backend-common@0.19.8-next.2
299
+ - @backstage/errors@1.2.3-next.0
300
+ - @backstage/backend-plugin-api@0.6.6-next.2
301
+ - @backstage/config@1.1.1-next.0
302
+
303
+ ## 0.1.7-next.1
304
+
305
+ ### Patch Changes
306
+
307
+ - Updated dependencies
308
+ - @backstage/backend-common@0.19.7-next.1
309
+ - @backstage/config@1.1.0
310
+ - @backstage/errors@1.2.2
311
+
312
+ ## 0.1.7-next.0
313
+
314
+ ### Patch Changes
315
+
316
+ - Updated dependencies
317
+ - @backstage/backend-common@0.19.7-next.0
318
+ - @backstage/config@1.1.0
319
+ - @backstage/errors@1.2.2
320
+
321
+ ## 0.1.5
322
+
323
+ ### Patch Changes
324
+
325
+ - Updated dependencies
326
+ - @backstage/backend-common@0.19.5
327
+ - @backstage/config@1.1.0
328
+ - @backstage/errors@1.2.2
329
+
330
+ ## 0.1.5-next.3
331
+
332
+ ### Patch Changes
333
+
334
+ - Updated dependencies
335
+ - @backstage/config@1.1.0-next.2
336
+ - @backstage/errors@1.2.2-next.0
337
+ - @backstage/backend-common@0.19.5-next.3
338
+
339
+ ## 0.1.5-next.2
340
+
341
+ ### Patch Changes
342
+
343
+ - Updated dependencies
344
+ - @backstage/config@1.1.0-next.1
345
+ - @backstage/backend-common@0.19.5-next.2
346
+ - @backstage/errors@1.2.1
347
+
348
+ ## 0.1.5-next.1
349
+
350
+ ### Patch Changes
351
+
352
+ - Updated dependencies
353
+ - @backstage/config@1.1.0-next.0
354
+ - @backstage/backend-common@0.19.5-next.1
355
+ - @backstage/errors@1.2.1
356
+
357
+ ## 0.1.4-next.0
358
+
359
+ ### Patch Changes
360
+
361
+ - Updated dependencies
362
+ - @backstage/backend-common@0.19.4-next.0
363
+ - @backstage/config@1.0.8
364
+ - @backstage/errors@1.2.1
365
+
366
+ ## 0.1.2
367
+
368
+ ### Patch Changes
369
+
370
+ - 12a8c94eda8d: Add package repository and homepage metadata
371
+ - Updated dependencies
372
+ - @backstage/backend-common@0.19.2
373
+ - @backstage/config@1.0.8
374
+ - @backstage/errors@1.2.1
375
+
376
+ ## 0.1.2-next.2
377
+
378
+ ### Patch Changes
379
+
380
+ - Updated dependencies
381
+ - @backstage/backend-common@0.19.2-next.2
382
+
383
+ ## 0.1.2-next.1
384
+
385
+ ### Patch Changes
386
+
387
+ - 12a8c94eda8d: Add package repository and homepage metadata
388
+ - Updated dependencies
389
+ - @backstage/backend-common@0.19.2-next.1
390
+ - @backstage/config@1.0.8
391
+ - @backstage/errors@1.2.1
392
+
393
+ ## 0.1.2-next.0
394
+
395
+ ### Patch Changes
396
+
397
+ - Updated dependencies
398
+ - @backstage/backend-common@0.19.2-next.0
399
+ - @backstage/config@1.0.8
400
+ - @backstage/errors@1.2.1
401
+
402
+ ## 0.1.1
403
+
404
+ ### Patch Changes
405
+
406
+ - Updated dependencies
407
+ - @backstage/errors@1.2.1
408
+ - @backstage/backend-common@0.19.1
409
+ - @backstage/config@1.0.8
410
+
411
+ ## 0.1.1-next.0
412
+
413
+ ### Patch Changes
414
+
415
+ - Updated dependencies
416
+ - @backstage/errors@1.2.1-next.0
417
+ - @backstage/backend-common@0.19.1-next.0
418
+ - @backstage/config@1.0.8
419
+
420
+ ## 0.1.0
421
+
422
+ ### Minor Changes
423
+
424
+ - 05bf04ca6863: Initialize Nomad plugin with frontend and backend. List jobs/allocations
425
+
426
+ ### Patch Changes
427
+
428
+ - Updated dependencies
429
+ - @backstage/backend-common@0.19.0
430
+ - @backstage/errors@1.2.0
431
+ - @backstage/config@1.0.8
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # @backstage-community/plugin-nomad-backend
2
+
3
+ A backend for [Nomad](https://www.nomadproject.io/), this plugin exposes a service with routes that are used by the `@backstage-community/plugin-nomad-backend` plugin to query Job and Group information from a Nomad API.
4
+
5
+ ## New Backend System
6
+
7
+ The Nomad backend plugin has support for the [new backend system](https://backstage.io/docs/backend-system/), here's how you can set that up:
8
+
9
+ In your `packages/backend/src/index.ts` make the following changes:
10
+
11
+ ```diff
12
+ import { createBackend } from '@backstage/backend-defaults';
13
+ const backend = createBackend();
14
+ // ... other feature additions
15
+ backend.add(import('@backstage-community/plugin-nomad-backend'));
16
+ backend.start();
17
+ ```
18
+
19
+ ## Set Up
20
+
21
+ 1. Install the plugin using:
22
+
23
+ ```bash
24
+ # From your Backstage root directory
25
+ yarn --cwd packages/backend add @backstage-community/plugin-nomad-backend
26
+ ```
27
+
28
+ 2. Create a `nomad.ts` file inside `packages/backend/src/plugins/`:
29
+
30
+ ```typescript
31
+ import { createRouter } from '@backstage-community/plugin-nomad-backend';
32
+ import { Router } from 'express';
33
+ import { PluginEnvironment } from '../types';
34
+
35
+ export default async function createPlugin(
36
+ props: PluginEnvironment,
37
+ ): Promise<Router> {
38
+ return await createRouter(props);
39
+ }
40
+ ```
41
+
42
+ 3. Modify your `packages/backend/src/index.ts` to include:
43
+
44
+ ```diff
45
+ ...
46
+
47
+ import { Config } from '@backstage/config';
48
+ import app from './plugins/app';
49
+ +import nomad from './plugins/nomad';
50
+ ...
51
+
52
+ async function main() {
53
+ ...
54
+
55
+ const authEnv = useHotMemoize(module, () => createEnv('auth'));
56
+ + const nomadEnv = useHotMemoize(module, () => createEnv('nomad'));
57
+ ...
58
+
59
+ const apiRouter = Router();
60
+ apiRouter.use('/catalog', await catalog(catalogEnv));
61
+ + apiRouter.use('/nomad', await nomad(nomadEnv));
62
+ ```
63
+
64
+ Note: for this backend to work, the `nomad` configuration described in the README of `@backstage-community/plugin-nomad` must be implemented.
@@ -0,0 +1,119 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var fetch = require('node-fetch');
6
+ var backendCommon = require('@backstage/backend-common');
7
+ var errors = require('@backstage/errors');
8
+ var express = require('express');
9
+ var Router = require('express-promise-router');
10
+ var backendPluginApi = require('@backstage/backend-plugin-api');
11
+
12
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
13
+
14
+ var fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
15
+ var express__default = /*#__PURE__*/_interopDefaultCompat(express);
16
+ var Router__default = /*#__PURE__*/_interopDefaultCompat(Router);
17
+
18
+ async function createRouter(options) {
19
+ const { config, logger } = options;
20
+ const addr = config.getString("nomad.addr");
21
+ const token = config.getOptionalString("nomad.token");
22
+ const router = Router__default.default();
23
+ router.use(express__default.default.json());
24
+ router.get("/health", (_, resp) => {
25
+ resp.json({ status: "ok" });
26
+ });
27
+ router.get("/v1/allocations", async (req, res) => {
28
+ var _a, _b;
29
+ const namespace = (_a = req.query.namespace) != null ? _a : "";
30
+ if (!namespace || namespace === "") {
31
+ throw new errors.InputError(`Missing "namespace" query parameter`);
32
+ }
33
+ const filter = (_b = req.query.filter) != null ? _b : "";
34
+ logger.debug(`request headers: namespace=${namespace} filter=${filter}`);
35
+ const endpoint = `${addr}/v1/allocations?namespace=${encodeURIComponent(
36
+ namespace
37
+ )}&filter=${encodeURIComponent(filter)}`;
38
+ const allocationsResp = await fetch__default.default(endpoint, {
39
+ method: "GET",
40
+ headers: {
41
+ Accept: "application/json",
42
+ "X-Nomad-Token": token || ""
43
+ }
44
+ });
45
+ if (allocationsResp.status !== 200) {
46
+ const body = await allocationsResp.text();
47
+ logger.error(`failed to call /v1/allocations endpoint: ${body}`);
48
+ res.status(allocationsResp.status).json({ message: body });
49
+ return;
50
+ }
51
+ const allocationsBody = await allocationsResp.json();
52
+ logger.debug(`/v1/allocations response: ${allocationsBody}`);
53
+ res.json(allocationsBody);
54
+ });
55
+ router.get("/v1/job/:job_id/versions", async (req, resp) => {
56
+ var _a, _b;
57
+ const namespace = (_a = req.query.namespace) != null ? _a : "";
58
+ if (!namespace || namespace === "") {
59
+ throw new errors.InputError(`Missing "namespace" query parameter`);
60
+ }
61
+ const jobID = (_b = req.params.job_id) != null ? _b : "";
62
+ const apiResp = await fetch__default.default(
63
+ `${addr}/v1/job/${jobID}/versions?namespace=${encodeURIComponent(
64
+ namespace
65
+ )}`,
66
+ {
67
+ method: "GET",
68
+ headers: {
69
+ Accept: "application/json",
70
+ "X-Nomad-Token": token || ""
71
+ }
72
+ }
73
+ );
74
+ if (apiResp.status !== 200) {
75
+ const body = await apiResp.text();
76
+ logger.error(`failed to call /v1/job/:job_id/versions endpoint: ${body}`);
77
+ resp.status(apiResp.status).json({ message: body });
78
+ return;
79
+ }
80
+ const versionsBody = await apiResp.json();
81
+ logger.debug(`/v1/job/:job_id/versions response: ${versionsBody}`);
82
+ resp.json(versionsBody);
83
+ });
84
+ router.use(backendCommon.requestLoggingHandler());
85
+ router.use(backendCommon.errorHandler());
86
+ return router;
87
+ }
88
+
89
+ const nomadPlugin = backendPluginApi.createBackendPlugin({
90
+ pluginId: "nomad",
91
+ register(env) {
92
+ env.registerInit({
93
+ deps: {
94
+ logger: backendPluginApi.coreServices.logger,
95
+ config: backendPluginApi.coreServices.rootConfig,
96
+ httpRouter: backendPluginApi.coreServices.httpRouter
97
+ },
98
+ async init({ logger, config, httpRouter }) {
99
+ httpRouter.use(
100
+ await createRouter({
101
+ /**
102
+ * Logger for logging purposes
103
+ */
104
+ logger,
105
+ config
106
+ })
107
+ );
108
+ httpRouter.addAuthPolicy({
109
+ path: "/health",
110
+ allow: "unauthenticated"
111
+ });
112
+ }
113
+ });
114
+ }
115
+ });
116
+
117
+ exports.createRouter = createRouter;
118
+ exports.default = nomadPlugin;
119
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/service/router.ts","../src/plugin.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fetch from 'node-fetch';\nimport { errorHandler, requestLoggingHandler } from '@backstage/backend-common';\nimport { Config } from '@backstage/config';\nimport { InputError } from '@backstage/errors';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\n/** @public */\nexport interface RouterOptions {\n logger: LoggerService;\n config: Config;\n}\n\n/** @public */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const { config, logger } = options;\n\n // Get Nomad addr and token from config\n const addr = config.getString('nomad.addr');\n const token = config.getOptionalString('nomad.token');\n\n const router = Router();\n router.use(express.json());\n\n router.get('/health', (_, resp) => {\n resp.json({ status: 'ok' });\n });\n\n router.get('/v1/allocations', async (req, res) => {\n // Check namespace argument\n const namespace = (req.query.namespace as string) ?? '';\n if (!namespace || namespace === '') {\n throw new InputError(`Missing \"namespace\" query parameter`);\n }\n\n // Check filter argument\n const filter = (req.query.filter as string) ?? '';\n logger.debug(`request headers: namespace=${namespace} filter=${filter}`);\n\n // Issue the request\n const endpoint = `${addr}/v1/allocations?namespace=${encodeURIComponent(\n namespace,\n )}&filter=${encodeURIComponent(filter)}`;\n const allocationsResp = await fetch(endpoint, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n 'X-Nomad-Token': token || '',\n },\n });\n\n // Check response\n if (allocationsResp.status !== 200) {\n const body = await allocationsResp.text();\n logger.error(`failed to call /v1/allocations endpoint: ${body}`);\n res.status(allocationsResp.status).json({ message: body });\n return;\n }\n\n // Deserialize and return\n const allocationsBody = await allocationsResp.json();\n logger.debug(`/v1/allocations response: ${allocationsBody}`);\n res.json(allocationsBody);\n });\n\n router.get('/v1/job/:job_id/versions', async (req, resp) => {\n // Check namespace argument\n const namespace = (req.query.namespace as string) ?? '';\n if (!namespace || namespace === '') {\n throw new InputError(`Missing \"namespace\" query parameter`);\n }\n\n // Get job ID\n const jobID = (req.params.job_id as string) ?? '';\n\n // Issue the request\n const apiResp = await fetch(\n `${addr}/v1/job/${jobID}/versions?namespace=${encodeURIComponent(\n namespace,\n )}`,\n {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n 'X-Nomad-Token': token || '',\n },\n },\n );\n\n // Check response\n if (apiResp.status !== 200) {\n const body = await apiResp.text();\n logger.error(`failed to call /v1/job/:job_id/versions endpoint: ${body}`);\n resp.status(apiResp.status).json({ message: body });\n return;\n }\n\n // Deserialize and return\n const versionsBody = await apiResp.json();\n logger.debug(`/v1/job/:job_id/versions response: ${versionsBody}`);\n resp.json(versionsBody);\n });\n\n router.use(requestLoggingHandler());\n router.use(errorHandler());\n return router;\n}\n","/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouter } from './service/router';\n\n/**\n * Nomad backend plugin\n *\n * @public\n */\nexport const nomadPlugin = createBackendPlugin({\n pluginId: 'nomad',\n register(env) {\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n httpRouter: coreServices.httpRouter,\n },\n async init({ logger, config, httpRouter }) {\n httpRouter.use(\n await createRouter({\n /**\n * Logger for logging purposes\n */\n logger,\n config,\n }),\n );\n httpRouter.addAuthPolicy({\n path: '/health',\n allow: 'unauthenticated',\n });\n },\n });\n },\n});\n"],"names":["Router","express","InputError","fetch","requestLoggingHandler","errorHandler","createBackendPlugin","coreServices"],"mappings":";;;;;;;;;;;;;;;;;AA+BA,eAAsB,aACpB,OACyB,EAAA;AACzB,EAAM,MAAA,EAAE,MAAQ,EAAA,MAAA,EAAW,GAAA,OAAA,CAAA;AAG3B,EAAM,MAAA,IAAA,GAAO,MAAO,CAAA,SAAA,CAAU,YAAY,CAAA,CAAA;AAC1C,EAAM,MAAA,KAAA,GAAQ,MAAO,CAAA,iBAAA,CAAkB,aAAa,CAAA,CAAA;AAEpD,EAAA,MAAM,SAASA,uBAAO,EAAA,CAAA;AACtB,EAAO,MAAA,CAAA,GAAA,CAAIC,wBAAQ,CAAA,IAAA,EAAM,CAAA,CAAA;AAEzB,EAAA,MAAA,CAAO,GAAI,CAAA,SAAA,EAAW,CAAC,CAAA,EAAG,IAAS,KAAA;AACjC,IAAA,IAAA,CAAK,IAAK,CAAA,EAAE,MAAQ,EAAA,IAAA,EAAM,CAAA,CAAA;AAAA,GAC3B,CAAA,CAAA;AAED,EAAA,MAAA,CAAO,GAAI,CAAA,iBAAA,EAAmB,OAAO,GAAA,EAAK,GAAQ,KAAA;AA/CpD,IAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AAiDI,IAAA,MAAM,SAAa,GAAA,CAAA,EAAA,GAAA,GAAA,CAAI,KAAM,CAAA,SAAA,KAAV,IAAkC,GAAA,EAAA,GAAA,EAAA,CAAA;AACrD,IAAI,IAAA,CAAC,SAAa,IAAA,SAAA,KAAc,EAAI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AM,MAAA,YAAA,GAAe,MAAM,OAAA,CAAQ,IAAK,EAAA,CAAA;AACxC,IAAO,MAAA,CAAA,KAAA,CAAM,CAAsC,mCAAA,EAAA,YAAY,CAAE,CAAA,CAAA,CAAA;AACjE,IAAA,IAAA,CAAK,KAAK,YAAY,CAAA,CAAA;AAAA,GACvB,CAAA,CAAA;AAED,EAAO,MAAA,CAAA,GAAA,CAAIC,qCAAuB,CAAA,CAAA;AAClC,EAAO,MAAA,CAAA,GAAA,CAAIC,4BAAc,CAAA,CAAA;AACzB,EAAO,OAAA,MAAA,CAAA;AACT;;AClGO,MAAM,cAAcC,oCAAoB,CAAA;AAAA,EAC7C,QAAU,EAAA,OAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQC,6BAAa,CAAA,MAAA;AAAA,QACrB,QAAQA,6BAAa,CAAA,UAAA;AAAA,QACrB,YAAYA,6BAAa,CAAA,UAAA;AAAA,OAC3B;AAAA,MACA,MAAM,IAAK,CAAA,EAAE,MAAQ,EAAA,MAAA,EAAQ,YAAc,EAAA;AACzC,QAAW,UAAA,CAAA,GAAA;AAAA,UACT,MAAM,YAAa,CAAA;AAAA;AAAA;AAAA;AAAA,YAIjB,MAAA;AAAA,YACA,MAAA;AAAA,WACD,CAAA;AAAA,SACH,CAAA;AACA,QAAA,UAAA,CAAW,aAAc,CAAA;AAAA,UACvB,IAAM,EAAA,SAAA;AAAA,UACN,KAAO,EAAA,iBAAA;AAAA,SACR,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
@@ -0,0 +1,21 @@
1
+ import { Config } from '@backstage/config';
2
+ import express from 'express';
3
+ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
4
+ import { LoggerService } from '@backstage/backend-plugin-api';
5
+
6
+ /** @public */
7
+ interface RouterOptions {
8
+ logger: LoggerService;
9
+ config: Config;
10
+ }
11
+ /** @public */
12
+ declare function createRouter(options: RouterOptions): Promise<express.Router>;
13
+
14
+ /**
15
+ * Nomad backend plugin
16
+ *
17
+ * @public
18
+ */
19
+ declare const nomadPlugin: () => _backstage_backend_plugin_api.BackendFeature;
20
+
21
+ export { type RouterOptions, createRouter, nomadPlugin as default };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@backstage-community/plugin-nomad-backend",
3
+ "version": "0.1.20",
4
+ "backstage": {
5
+ "role": "backend-plugin"
6
+ },
7
+ "publishConfig": {
8
+ "access": "public",
9
+ "main": "dist/index.cjs.js",
10
+ "types": "dist/index.d.ts"
11
+ },
12
+ "homepage": "https://backstage.io",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/backstage/community-plugins",
16
+ "directory": "workspaces/nomad/plugins/nomad-backend"
17
+ },
18
+ "license": "Apache-2.0",
19
+ "main": "dist/index.cjs.js",
20
+ "types": "dist/index.d.ts",
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "scripts": {
25
+ "build": "backstage-cli package build",
26
+ "clean": "backstage-cli package clean",
27
+ "lint": "backstage-cli package lint",
28
+ "prepack": "backstage-cli package prepack",
29
+ "postpack": "backstage-cli package postpack",
30
+ "start": "backstage-cli package start",
31
+ "test": "backstage-cli package test"
32
+ },
33
+ "dependencies": {
34
+ "@backstage/backend-common": "^0.21.7",
35
+ "@backstage/backend-plugin-api": "^0.6.17",
36
+ "@backstage/config": "^1.2.0",
37
+ "@backstage/errors": "^1.2.4",
38
+ "@types/express": "*",
39
+ "express": "^4.17.1",
40
+ "express-promise-router": "^4.1.0",
41
+ "node-fetch": "^2.6.7",
42
+ "yn": "^4.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@backstage/cli": "^0.26.3",
46
+ "@types/node-fetch": "^2.5.12",
47
+ "@types/supertest": "^2.0.8",
48
+ "supertest": "^6.2.4"
49
+ }
50
+ }