@pagerduty/backstage-plugin-backend 0.9.10 → 0.10.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/config.d.ts +32 -29
- package/dist/apis/pagerduty.cjs.js +317 -94
- package/dist/apis/pagerduty.cjs.js.map +1 -1
- package/dist/auth/auth.cjs.js +71 -37
- package/dist/auth/auth.cjs.js.map +1 -1
- package/dist/db/PagerDutyBackendDatabase.cjs.js +16 -5
- package/dist/db/PagerDutyBackendDatabase.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/plugin.cjs.js +10 -8
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/service/router.cjs.js +297 -250
- package/dist/service/router.cjs.js.map +1 -1
- package/migrations/20240527_init.js +16 -24
- package/migrations/20240710_add_account_column.js +16 -10
- package/migrations/20240722_add_settings_table.js +11 -17
- package/package.json +1 -1
|
@@ -10,47 +10,54 @@ var Router = require('express-promise-router');
|
|
|
10
10
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
11
11
|
|
|
12
12
|
function _interopNamespaceCompat(e) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
}
|
|
13
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
24
22
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n.default = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
var express__namespace = /*#__PURE__*/_interopNamespaceCompat(express);
|
|
31
31
|
var Router__default = /*#__PURE__*/_interopDefaultCompat(Router);
|
|
32
32
|
|
|
33
|
-
async function createComponentEntitiesReferenceDict({
|
|
33
|
+
async function createComponentEntitiesReferenceDict({
|
|
34
|
+
items: componentEntities
|
|
35
|
+
}) {
|
|
34
36
|
const componentEntitiesDict = {};
|
|
35
|
-
await Promise.all(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
name: entity.metadata.name
|
|
43
|
-
};
|
|
44
|
-
} else if (integrationKey !== void 0 && integrationKey !== "") {
|
|
45
|
-
const service = await pagerduty.getServiceByIntegrationKey(integrationKey, account).catch(() => void 0);
|
|
46
|
-
if (service !== void 0) {
|
|
47
|
-
componentEntitiesDict[service.id] = {
|
|
37
|
+
await Promise.all(
|
|
38
|
+
componentEntities.map(async (entity) => {
|
|
39
|
+
const serviceId = entity.metadata.annotations?.["pagerduty.com/service-id"];
|
|
40
|
+
const integrationKey = entity.metadata.annotations?.["pagerduty.com/integration-key"];
|
|
41
|
+
const account = entity.metadata.annotations?.["pagerduty.com/account"];
|
|
42
|
+
if (serviceId !== void 0 && serviceId !== "") {
|
|
43
|
+
componentEntitiesDict[serviceId] = {
|
|
48
44
|
ref: `${entity.kind}:${entity.metadata.namespace}/${entity.metadata.name}`.toLowerCase(),
|
|
49
45
|
name: entity.metadata.name
|
|
50
46
|
};
|
|
47
|
+
} else if (integrationKey !== void 0 && integrationKey !== "") {
|
|
48
|
+
const service = await pagerduty.getServiceByIntegrationKey(
|
|
49
|
+
integrationKey,
|
|
50
|
+
account
|
|
51
|
+
).catch(() => void 0);
|
|
52
|
+
if (service !== void 0) {
|
|
53
|
+
componentEntitiesDict[service.id] = {
|
|
54
|
+
ref: `${entity.kind}:${entity.metadata.namespace}/${entity.metadata.name}`.toLowerCase(),
|
|
55
|
+
name: entity.metadata.name
|
|
56
|
+
};
|
|
57
|
+
}
|
|
51
58
|
}
|
|
52
|
-
}
|
|
53
|
-
|
|
59
|
+
})
|
|
60
|
+
);
|
|
54
61
|
return componentEntitiesDict;
|
|
55
62
|
}
|
|
56
63
|
async function buildEntityMappingsResponse(entityMappings, componentEntitiesDict, componentEntities, pagerDutyServices) {
|
|
@@ -60,7 +67,9 @@ async function buildEntityMappingsResponse(entityMappings, componentEntitiesDict
|
|
|
60
67
|
pagerDutyServices.forEach((service) => {
|
|
61
68
|
const entityRef = componentEntitiesDict[service.id]?.ref;
|
|
62
69
|
const entityName = componentEntitiesDict[service.id]?.name;
|
|
63
|
-
const entityMapping = entityMappings.find(
|
|
70
|
+
const entityMapping = entityMappings.find(
|
|
71
|
+
(mapping) => mapping.serviceId === service.id
|
|
72
|
+
);
|
|
64
73
|
if (entityMapping) {
|
|
65
74
|
if (entityRef === void 0) {
|
|
66
75
|
if (entityMapping.entityRef === "" || entityMapping.entityRef === void 0) {
|
|
@@ -77,7 +86,9 @@ async function buildEntityMappingsResponse(entityMappings, componentEntitiesDict
|
|
|
77
86
|
account: service.account
|
|
78
87
|
});
|
|
79
88
|
} else {
|
|
80
|
-
const entityRefName = componentEntities.items.find(
|
|
89
|
+
const entityRefName = componentEntities.items.find(
|
|
90
|
+
(entity) => `${entity.kind}:${entity.metadata.namespace}/${entity.metadata.name}`.toLowerCase() === entityMapping.entityRef
|
|
91
|
+
)?.metadata.name ?? "";
|
|
81
92
|
result.mappings.push({
|
|
82
93
|
entityRef: entityMapping.entityRef,
|
|
83
94
|
entityName: entityRefName,
|
|
@@ -92,7 +103,9 @@ async function buildEntityMappingsResponse(entityMappings, componentEntitiesDict
|
|
|
92
103
|
});
|
|
93
104
|
}
|
|
94
105
|
} else if (entityRef !== entityMapping.entityRef) {
|
|
95
|
-
const entityRefName = componentEntities.items.find(
|
|
106
|
+
const entityRefName = componentEntities.items.find(
|
|
107
|
+
(entity) => `${entity.kind}:${entity.metadata.namespace}/${entity.metadata.name}`.toLowerCase() === entityMapping.entityRef
|
|
108
|
+
)?.metadata.name ?? "";
|
|
96
109
|
result.mappings.push({
|
|
97
110
|
entityRef: entityMapping.entityRef !== "" ? entityMapping.entityRef : "",
|
|
98
111
|
entityName: entityMapping.entityRef !== "" ? entityRefName : "",
|
|
@@ -121,7 +134,9 @@ async function buildEntityMappingsResponse(entityMappings, componentEntitiesDict
|
|
|
121
134
|
}
|
|
122
135
|
} else {
|
|
123
136
|
const backstageVendorId = "PRO19CT";
|
|
124
|
-
const backstageIntegrationKey = service.integrations?.find(
|
|
137
|
+
const backstageIntegrationKey = service.integrations?.find(
|
|
138
|
+
(integration) => integration.vendor?.id === backstageVendorId
|
|
139
|
+
)?.integration_key ?? "";
|
|
125
140
|
if (entityRef !== void 0) {
|
|
126
141
|
result.mappings.push({
|
|
127
142
|
entityRef,
|
|
@@ -172,56 +187,67 @@ async function createRouter(options) {
|
|
|
172
187
|
pagerduty.loadPagerDutyEndpointsFromConfig(config, logger);
|
|
173
188
|
const router = Router__default.default();
|
|
174
189
|
router.use(express__namespace.json());
|
|
175
|
-
router.delete(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
response.status(error.status).json({
|
|
207
|
-
errors: [
|
|
208
|
-
`${error.message}`
|
|
209
|
-
]
|
|
190
|
+
router.delete(
|
|
191
|
+
"/dependencies/service/:serviceId",
|
|
192
|
+
async (request, response) => {
|
|
193
|
+
try {
|
|
194
|
+
const serviceId = request.params.serviceId || "";
|
|
195
|
+
const account = request.query.account || "";
|
|
196
|
+
if (serviceId === "") {
|
|
197
|
+
response.status(400).json(
|
|
198
|
+
"Bad Request: ':serviceId' must be provided as part of the path"
|
|
199
|
+
);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const dependencies = Object.keys(request.body).length === 0 ? [] : request.body;
|
|
203
|
+
if (!dependencies || dependencies.length === 0) {
|
|
204
|
+
response.status(400).json(
|
|
205
|
+
"Bad Request: 'dependencies' must be provided as part of the request body"
|
|
206
|
+
);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const serviceRelations = [];
|
|
210
|
+
dependencies.forEach(async (dependency) => {
|
|
211
|
+
serviceRelations.push({
|
|
212
|
+
supporting_service: {
|
|
213
|
+
id: dependency,
|
|
214
|
+
type: "service"
|
|
215
|
+
},
|
|
216
|
+
dependent_service: {
|
|
217
|
+
id: serviceId,
|
|
218
|
+
type: "service"
|
|
219
|
+
}
|
|
220
|
+
});
|
|
210
221
|
});
|
|
222
|
+
await pagerduty.removeServiceRelationsFromService(serviceRelations, account);
|
|
223
|
+
response.sendStatus(200);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
if (error instanceof backstagePluginCommon.HttpError) {
|
|
226
|
+
logger.error(
|
|
227
|
+
`Error occurred while processing request: ${error.message}`
|
|
228
|
+
);
|
|
229
|
+
response.status(error.status).json({
|
|
230
|
+
errors: [`${error.message}`]
|
|
231
|
+
});
|
|
232
|
+
}
|
|
211
233
|
}
|
|
212
234
|
}
|
|
213
|
-
|
|
235
|
+
);
|
|
214
236
|
router.post("/dependencies/service/:serviceId", async (request, response) => {
|
|
215
237
|
try {
|
|
216
238
|
const serviceId = request.params.serviceId || "";
|
|
217
239
|
const account = request.query.account || "";
|
|
218
240
|
if (serviceId === "") {
|
|
219
|
-
response.status(400).json(
|
|
241
|
+
response.status(400).json(
|
|
242
|
+
"Bad Request: ':serviceId' must be provided as part of the path"
|
|
243
|
+
);
|
|
220
244
|
return;
|
|
221
245
|
}
|
|
222
246
|
const dependencies = Object.keys(request.body).length === 0 ? [] : request.body;
|
|
223
247
|
if (!dependencies || dependencies.length === 0) {
|
|
224
|
-
response.status(400).json(
|
|
248
|
+
response.status(400).json(
|
|
249
|
+
"Bad Request: 'dependencies' must be provided as part of the request body"
|
|
250
|
+
);
|
|
225
251
|
return;
|
|
226
252
|
}
|
|
227
253
|
const serviceRelations = [];
|
|
@@ -241,11 +267,11 @@ async function createRouter(options) {
|
|
|
241
267
|
response.sendStatus(200);
|
|
242
268
|
} catch (error) {
|
|
243
269
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
244
|
-
logger.error(
|
|
270
|
+
logger.error(
|
|
271
|
+
`Error occurred while processing request: ${error.message}`
|
|
272
|
+
);
|
|
245
273
|
response.status(error.status).json({
|
|
246
|
-
errors: [
|
|
247
|
-
`${error.message}`
|
|
248
|
-
]
|
|
274
|
+
errors: [`${error.message}`]
|
|
249
275
|
});
|
|
250
276
|
}
|
|
251
277
|
}
|
|
@@ -262,66 +288,75 @@ async function createRouter(options) {
|
|
|
262
288
|
});
|
|
263
289
|
}
|
|
264
290
|
} else {
|
|
265
|
-
response.status(400).json(
|
|
291
|
+
response.status(400).json(
|
|
292
|
+
"Bad Request: ':serviceId' must be provided as part of the path"
|
|
293
|
+
);
|
|
266
294
|
}
|
|
267
295
|
} catch (error) {
|
|
268
296
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
269
297
|
response.status(error.status).json({
|
|
270
|
-
errors: [
|
|
271
|
-
`${error.message}`
|
|
272
|
-
]
|
|
298
|
+
errors: [`${error.message}`]
|
|
273
299
|
});
|
|
274
300
|
}
|
|
275
301
|
}
|
|
276
302
|
});
|
|
277
|
-
router.get(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
303
|
+
router.get(
|
|
304
|
+
"/catalog/entity/:type/:namespace/:name",
|
|
305
|
+
async (request, response) => {
|
|
306
|
+
const type = request.params.type;
|
|
307
|
+
const namespace = request.params.namespace;
|
|
308
|
+
const name = request.params.name;
|
|
309
|
+
try {
|
|
310
|
+
if (type && namespace && name) {
|
|
311
|
+
const entityRef = `${type}:${namespace}/${name}`.toLowerCase();
|
|
312
|
+
const foundEntity = await catalogApi?.getEntityByRef(entityRef);
|
|
313
|
+
if (foundEntity) {
|
|
314
|
+
response.json(
|
|
315
|
+
foundEntity.metadata.annotations?.["pagerduty.com/service-id"]
|
|
316
|
+
);
|
|
317
|
+
} else {
|
|
318
|
+
response.status(404);
|
|
319
|
+
}
|
|
287
320
|
} else {
|
|
288
|
-
response.status(
|
|
321
|
+
response.status(400).json(
|
|
322
|
+
"Bad Request: ':entityRef' must be provided as part of the path"
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
} catch (error) {
|
|
326
|
+
if (error instanceof backstagePluginCommon.HttpError) {
|
|
327
|
+
response.status(error.status).json({
|
|
328
|
+
errors: [`${error.message}`]
|
|
329
|
+
});
|
|
289
330
|
}
|
|
290
|
-
} else {
|
|
291
|
-
response.status(400).json("Bad Request: ':entityRef' must be provided as part of the path");
|
|
292
|
-
}
|
|
293
|
-
} catch (error) {
|
|
294
|
-
if (error instanceof backstagePluginCommon.HttpError) {
|
|
295
|
-
response.status(error.status).json({
|
|
296
|
-
errors: [
|
|
297
|
-
`${error.message}`
|
|
298
|
-
]
|
|
299
|
-
});
|
|
300
331
|
}
|
|
301
332
|
}
|
|
302
|
-
|
|
333
|
+
);
|
|
303
334
|
router.post("/settings", async (request, response) => {
|
|
304
335
|
try {
|
|
305
336
|
const settings = request.body;
|
|
306
|
-
await Promise.all(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
337
|
+
await Promise.all(
|
|
338
|
+
settings.map(async (setting) => {
|
|
339
|
+
if (setting.id === void 0 || setting.value === void 0) {
|
|
340
|
+
response.status(400).json("Bad Request: 'id' and 'value' are required");
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (!isValidSetting(setting.value)) {
|
|
344
|
+
response.status(400).json(
|
|
345
|
+
"Bad Request: 'value' is invalid. Valid options are 'backstage', 'pagerduty', 'both' or 'disabled'"
|
|
346
|
+
);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
await store.updateSetting(setting);
|
|
350
|
+
})
|
|
351
|
+
);
|
|
317
352
|
response.sendStatus(200);
|
|
318
353
|
} catch (error) {
|
|
319
354
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
320
|
-
logger.error(
|
|
355
|
+
logger.error(
|
|
356
|
+
`Error occurred while processing request: ${error.message}`
|
|
357
|
+
);
|
|
321
358
|
response.status(error.status).json({
|
|
322
|
-
errors: [
|
|
323
|
-
`${error.message}`
|
|
324
|
-
]
|
|
359
|
+
errors: [`${error.message}`]
|
|
325
360
|
});
|
|
326
361
|
}
|
|
327
362
|
}
|
|
@@ -338,9 +373,7 @@ async function createRouter(options) {
|
|
|
338
373
|
} catch (error) {
|
|
339
374
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
340
375
|
response.status(error.status).json({
|
|
341
|
-
errors: [
|
|
342
|
-
`${error.message}`
|
|
343
|
-
]
|
|
376
|
+
errors: [`${error.message}`]
|
|
344
377
|
});
|
|
345
378
|
}
|
|
346
379
|
}
|
|
@@ -355,15 +388,21 @@ async function createRouter(options) {
|
|
|
355
388
|
try {
|
|
356
389
|
const entity = request.body;
|
|
357
390
|
if (!entity.serviceId) {
|
|
358
|
-
response.status(400).json(
|
|
391
|
+
response.status(400).json(
|
|
392
|
+
"Bad Request: 'serviceId' must be provided as part of the request body"
|
|
393
|
+
);
|
|
359
394
|
return;
|
|
360
395
|
}
|
|
361
396
|
const entityMappings = await store.getAllEntityMappings();
|
|
362
|
-
const oldMapping = entityMappings.find(
|
|
397
|
+
const oldMapping = entityMappings.find(
|
|
398
|
+
(mapping) => mapping.serviceId === entity.serviceId
|
|
399
|
+
);
|
|
363
400
|
if (entity.entityRef !== "" && (entity.integrationKey === "" || entity.integrationKey === void 0)) {
|
|
364
401
|
const backstageVendorId = "PRO19CT";
|
|
365
402
|
const service = await pagerduty.getServiceById(entity.serviceId, entity.account);
|
|
366
|
-
const backstageIntegration = service.integrations?.find(
|
|
403
|
+
const backstageIntegration = service.integrations?.find(
|
|
404
|
+
(integration) => integration.vendor?.id === backstageVendorId
|
|
405
|
+
);
|
|
367
406
|
if (!backstageIntegration) {
|
|
368
407
|
const integrationKey = await pagerduty.createServiceIntegration({
|
|
369
408
|
serviceId: entity.serviceId,
|
|
@@ -392,11 +431,11 @@ async function createRouter(options) {
|
|
|
392
431
|
});
|
|
393
432
|
} catch (error) {
|
|
394
433
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
395
|
-
logger.error(
|
|
434
|
+
logger.error(
|
|
435
|
+
`Error occurred while processing request: ${error.message}`
|
|
436
|
+
);
|
|
396
437
|
response.status(error.status).json({
|
|
397
|
-
errors: [
|
|
398
|
-
`${error.message}`
|
|
399
|
-
]
|
|
438
|
+
errors: [`${error.message}`]
|
|
400
439
|
});
|
|
401
440
|
}
|
|
402
441
|
}
|
|
@@ -411,71 +450,80 @@ async function createRouter(options) {
|
|
|
411
450
|
});
|
|
412
451
|
const componentEntitiesDict = await createComponentEntitiesReferenceDict(componentEntities);
|
|
413
452
|
const pagerDutyServices = await pagerduty.getAllServices();
|
|
414
|
-
const result = await buildEntityMappingsResponse(
|
|
453
|
+
const result = await buildEntityMappingsResponse(
|
|
454
|
+
entityMappings,
|
|
455
|
+
componentEntitiesDict,
|
|
456
|
+
componentEntities,
|
|
457
|
+
pagerDutyServices
|
|
458
|
+
);
|
|
415
459
|
response.json(result);
|
|
416
460
|
} catch (error) {
|
|
417
461
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
418
462
|
response.status(error.status).json({
|
|
419
|
-
errors: [
|
|
420
|
-
`${error.message}`
|
|
421
|
-
]
|
|
463
|
+
errors: [`${error.message}`]
|
|
422
464
|
});
|
|
423
465
|
}
|
|
424
466
|
}
|
|
425
467
|
});
|
|
426
|
-
router.get(
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
errors: [
|
|
448
|
-
`${error.message}`
|
|
449
|
-
]
|
|
468
|
+
router.get(
|
|
469
|
+
"/mapping/entity/:type/:namespace/:name",
|
|
470
|
+
async (request, response) => {
|
|
471
|
+
try {
|
|
472
|
+
const entityType = request.params.type || "";
|
|
473
|
+
const entityNamespace = request.params.namespace || "";
|
|
474
|
+
const entityName = request.params.name || "";
|
|
475
|
+
if (entityType === "" || entityNamespace === "" || entityName === "") {
|
|
476
|
+
response.status(400).json("Required params not specified.");
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
const entityRef = `${entityType}:${entityNamespace}/${entityName}`.toLowerCase();
|
|
480
|
+
const entityMapping = await store.findEntityMappingByEntityRef(
|
|
481
|
+
entityRef
|
|
482
|
+
);
|
|
483
|
+
if (!entityMapping) {
|
|
484
|
+
response.status(404).json(`Mapping for entityRef ${entityRef} not found.`);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
response.json({
|
|
488
|
+
mapping: entityMapping
|
|
450
489
|
});
|
|
490
|
+
} catch (error) {
|
|
491
|
+
if (error instanceof backstagePluginCommon.HttpError) {
|
|
492
|
+
response.status(error.status).json({
|
|
493
|
+
errors: [`${error.message}`]
|
|
494
|
+
});
|
|
495
|
+
}
|
|
451
496
|
}
|
|
452
497
|
}
|
|
453
|
-
|
|
454
|
-
router.get(
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
errors: [
|
|
473
|
-
`${error.message}`
|
|
474
|
-
]
|
|
498
|
+
);
|
|
499
|
+
router.get(
|
|
500
|
+
"/mapping/entity/service/:serviceId",
|
|
501
|
+
async (request, response) => {
|
|
502
|
+
try {
|
|
503
|
+
const serviceId = request.params.serviceId ?? "";
|
|
504
|
+
if (serviceId === "") {
|
|
505
|
+
response.status(400).json("Required params not specified.");
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
const entityMapping = await store.findEntityMappingByServiceId(
|
|
509
|
+
serviceId
|
|
510
|
+
);
|
|
511
|
+
if (!entityMapping) {
|
|
512
|
+
response.status(404).json(`Mapping for serviceId ${serviceId} not found.`);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
response.json({
|
|
516
|
+
mapping: entityMapping
|
|
475
517
|
});
|
|
518
|
+
} catch (error) {
|
|
519
|
+
if (error instanceof backstagePluginCommon.HttpError) {
|
|
520
|
+
response.status(error.status).json({
|
|
521
|
+
errors: [`${error.message}`]
|
|
522
|
+
});
|
|
523
|
+
}
|
|
476
524
|
}
|
|
477
525
|
}
|
|
478
|
-
|
|
526
|
+
);
|
|
479
527
|
router.get("/escalation_policies", async (_, response) => {
|
|
480
528
|
try {
|
|
481
529
|
let escalationPolicyList = await pagerduty.getAllEscalationPolicies();
|
|
@@ -485,23 +533,23 @@ async function createRouter(options) {
|
|
|
485
533
|
}
|
|
486
534
|
return a.account.localeCompare(b.account);
|
|
487
535
|
});
|
|
488
|
-
const escalationPolicyDropDownOptions = escalationPolicyList.map(
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
536
|
+
const escalationPolicyDropDownOptions = escalationPolicyList.map(
|
|
537
|
+
(policy) => {
|
|
538
|
+
let policyLabel = policy.name;
|
|
539
|
+
if (policy.account && policy.account !== "default") {
|
|
540
|
+
policyLabel = `(${policy.account}) ${policy.name}`;
|
|
541
|
+
}
|
|
542
|
+
return {
|
|
543
|
+
label: policyLabel,
|
|
544
|
+
value: policy.id
|
|
545
|
+
};
|
|
492
546
|
}
|
|
493
|
-
|
|
494
|
-
label: policyLabel,
|
|
495
|
-
value: policy.id
|
|
496
|
-
};
|
|
497
|
-
});
|
|
547
|
+
);
|
|
498
548
|
response.json(escalationPolicyDropDownOptions);
|
|
499
549
|
} catch (error) {
|
|
500
550
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
501
551
|
response.status(error.status).json({
|
|
502
|
-
errors: [
|
|
503
|
-
`${error.message}`
|
|
504
|
-
]
|
|
552
|
+
errors: [`${error.message}`]
|
|
505
553
|
});
|
|
506
554
|
}
|
|
507
555
|
}
|
|
@@ -522,9 +570,7 @@ async function createRouter(options) {
|
|
|
522
570
|
} catch (error) {
|
|
523
571
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
524
572
|
response.status(error.status).json({
|
|
525
|
-
errors: [
|
|
526
|
-
`${error.message}`
|
|
527
|
-
]
|
|
573
|
+
errors: [`${error.message}`]
|
|
528
574
|
});
|
|
529
575
|
}
|
|
530
576
|
}
|
|
@@ -534,7 +580,9 @@ async function createRouter(options) {
|
|
|
534
580
|
const serviceId = request.params.serviceId || "";
|
|
535
581
|
const account = request.query.account || "";
|
|
536
582
|
if (serviceId === "") {
|
|
537
|
-
response.status(400).json(
|
|
583
|
+
response.status(400).json(
|
|
584
|
+
"Bad Request: ':serviceId' must be provided as part of the path or 'integration_key' as a query parameter"
|
|
585
|
+
);
|
|
538
586
|
return;
|
|
539
587
|
}
|
|
540
588
|
const service = await pagerduty.getServiceById(serviceId, account);
|
|
@@ -545,9 +593,7 @@ async function createRouter(options) {
|
|
|
545
593
|
} catch (error) {
|
|
546
594
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
547
595
|
response.status(error.status).json({
|
|
548
|
-
errors: [
|
|
549
|
-
`${error.message}`
|
|
550
|
-
]
|
|
596
|
+
errors: [`${error.message}`]
|
|
551
597
|
});
|
|
552
598
|
}
|
|
553
599
|
}
|
|
@@ -557,7 +603,10 @@ async function createRouter(options) {
|
|
|
557
603
|
const integrationKey = request.query.integration_key || "";
|
|
558
604
|
const account = request.query.account || "";
|
|
559
605
|
if (integrationKey !== "") {
|
|
560
|
-
const service = await pagerduty.getServiceByIntegrationKey(
|
|
606
|
+
const service = await pagerduty.getServiceByIntegrationKey(
|
|
607
|
+
integrationKey,
|
|
608
|
+
account
|
|
609
|
+
);
|
|
561
610
|
const serviceResponse = {
|
|
562
611
|
service
|
|
563
612
|
};
|
|
@@ -572,58 +621,62 @@ async function createRouter(options) {
|
|
|
572
621
|
} catch (error) {
|
|
573
622
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
574
623
|
response.status(error.status).json({
|
|
575
|
-
errors: [
|
|
576
|
-
`${error.message}`
|
|
577
|
-
]
|
|
624
|
+
errors: [`${error.message}`]
|
|
578
625
|
});
|
|
579
626
|
}
|
|
580
627
|
}
|
|
581
628
|
});
|
|
582
|
-
router.post(
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
logger.error(`Error occurred while processing request: ${error.message}`);
|
|
600
|
-
response.status(error.status).json({
|
|
601
|
-
errors: [
|
|
602
|
-
`${error.message}`
|
|
603
|
-
]
|
|
629
|
+
router.post(
|
|
630
|
+
"/services/:serviceId/integration/:vendorId",
|
|
631
|
+
async (request, response) => {
|
|
632
|
+
try {
|
|
633
|
+
const serviceId = request.params.serviceId || "";
|
|
634
|
+
const vendorId = request.params.vendorId || "";
|
|
635
|
+
const account = request.query.account || "";
|
|
636
|
+
if (serviceId === "" || vendorId === "") {
|
|
637
|
+
response.status(400).json(
|
|
638
|
+
"Bad Request: ':serviceId' and ':vendorId' must be provided as part of the path"
|
|
639
|
+
);
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
const integrationKey = await pagerduty.createServiceIntegration({
|
|
643
|
+
serviceId,
|
|
644
|
+
vendorId,
|
|
645
|
+
account
|
|
604
646
|
});
|
|
647
|
+
response.json(integrationKey);
|
|
648
|
+
} catch (error) {
|
|
649
|
+
if (error instanceof backstagePluginCommon.HttpError) {
|
|
650
|
+
logger.error(
|
|
651
|
+
`Error occurred while processing request: ${error.message}`
|
|
652
|
+
);
|
|
653
|
+
response.status(error.status).json({
|
|
654
|
+
errors: [`${error.message}`]
|
|
655
|
+
});
|
|
656
|
+
}
|
|
605
657
|
}
|
|
606
658
|
}
|
|
607
|
-
|
|
608
|
-
router.get(
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
659
|
+
);
|
|
660
|
+
router.get(
|
|
661
|
+
"/services/:serviceId/change-events",
|
|
662
|
+
async (request, response) => {
|
|
663
|
+
try {
|
|
664
|
+
const serviceId = request.params.serviceId || "";
|
|
665
|
+
const account = request.query.account || "";
|
|
666
|
+
const changeEvents = await pagerduty.getChangeEvents(serviceId, account);
|
|
667
|
+
const changeEventsResponse = {
|
|
668
|
+
change_events: changeEvents
|
|
669
|
+
};
|
|
670
|
+
response.json(changeEventsResponse);
|
|
671
|
+
} catch (error) {
|
|
672
|
+
if (error instanceof backstagePluginCommon.HttpError) {
|
|
673
|
+
response.status(error.status).json({
|
|
674
|
+
errors: [`${error.message}`]
|
|
675
|
+
});
|
|
676
|
+
}
|
|
624
677
|
}
|
|
625
678
|
}
|
|
626
|
-
|
|
679
|
+
);
|
|
627
680
|
router.get("/services/:serviceId/incidents", async (request, response) => {
|
|
628
681
|
try {
|
|
629
682
|
const serviceId = request.params.serviceId || "";
|
|
@@ -636,9 +689,7 @@ async function createRouter(options) {
|
|
|
636
689
|
} catch (error) {
|
|
637
690
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
638
691
|
response.status(error.status).json({
|
|
639
|
-
errors: [
|
|
640
|
-
`${error.message}`
|
|
641
|
-
]
|
|
692
|
+
errors: [`${error.message}`]
|
|
642
693
|
});
|
|
643
694
|
}
|
|
644
695
|
}
|
|
@@ -655,9 +706,7 @@ async function createRouter(options) {
|
|
|
655
706
|
} catch (error) {
|
|
656
707
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
657
708
|
response.status(error.status).json({
|
|
658
|
-
errors: [
|
|
659
|
-
`${error.message}`
|
|
660
|
-
]
|
|
709
|
+
errors: [`${error.message}`]
|
|
661
710
|
});
|
|
662
711
|
}
|
|
663
712
|
}
|
|
@@ -674,9 +723,7 @@ async function createRouter(options) {
|
|
|
674
723
|
} catch (error) {
|
|
675
724
|
if (error instanceof backstagePluginCommon.HttpError) {
|
|
676
725
|
response.status(error.status).json({
|
|
677
|
-
errors: [
|
|
678
|
-
`${error.message}`
|
|
679
|
-
]
|
|
726
|
+
errors: [`${error.message}`]
|
|
680
727
|
});
|
|
681
728
|
}
|
|
682
729
|
}
|