@pagerduty/backstage-plugin-backend 0.9.10 → 0.9.11

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.
@@ -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
- 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]; }
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
- n.default = e;
27
- return Object.freeze(n);
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({ items: componentEntities }) {
33
+ async function createComponentEntitiesReferenceDict({
34
+ items: componentEntities
35
+ }) {
34
36
  const componentEntitiesDict = {};
35
- await Promise.all(componentEntities.map(async (entity) => {
36
- const serviceId = entity.metadata.annotations?.["pagerduty.com/service-id"];
37
- const integrationKey = entity.metadata.annotations?.["pagerduty.com/integration-key"];
38
- const account = entity.metadata.annotations?.["pagerduty.com/account"];
39
- if (serviceId !== void 0 && serviceId !== "") {
40
- componentEntitiesDict[serviceId] = {
41
- ref: `${entity.kind}:${entity.metadata.namespace}/${entity.metadata.name}`.toLowerCase(),
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((mapping) => mapping.serviceId === service.id);
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((entity) => `${entity.kind}:${entity.metadata.namespace}/${entity.metadata.name}`.toLowerCase() === entityMapping.entityRef)?.metadata.name ?? "";
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((entity) => `${entity.kind}:${entity.metadata.namespace}/${entity.metadata.name}`.toLowerCase() === entityMapping.entityRef)?.metadata.name ?? "";
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((integration) => integration.vendor?.id === backstageVendorId)?.integration_key ?? "";
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("/dependencies/service/:serviceId", async (request, response) => {
176
- try {
177
- const serviceId = request.params.serviceId || "";
178
- const account = request.query.account || "";
179
- if (serviceId === "") {
180
- response.status(400).json("Bad Request: ':serviceId' must be provided as part of the path");
181
- return;
182
- }
183
- const dependencies = Object.keys(request.body).length === 0 ? [] : request.body;
184
- if (!dependencies || dependencies.length === 0) {
185
- response.status(400).json("Bad Request: 'dependencies' must be provided as part of the request body");
186
- return;
187
- }
188
- const serviceRelations = [];
189
- dependencies.forEach(async (dependency) => {
190
- serviceRelations.push({
191
- supporting_service: {
192
- id: dependency,
193
- type: "service"
194
- },
195
- dependent_service: {
196
- id: serviceId,
197
- type: "service"
198
- }
199
- });
200
- });
201
- await pagerduty.removeServiceRelationsFromService(serviceRelations, account);
202
- response.sendStatus(200);
203
- } catch (error) {
204
- if (error instanceof backstagePluginCommon.HttpError) {
205
- logger.error(`Error occurred while processing request: ${error.message}`);
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("Bad Request: ':serviceId' must be provided as part of the path");
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("Bad Request: 'dependencies' must be provided as part of the request body");
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(`Error occurred while processing request: ${error.message}`);
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("Bad Request: ':serviceId' must be provided as part of the path");
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("/catalog/entity/:type/:namespace/:name", async (request, response) => {
278
- const type = request.params.type;
279
- const namespace = request.params.namespace;
280
- const name = request.params.name;
281
- try {
282
- if (type && namespace && name) {
283
- const entityRef = `${type}:${namespace}/${name}`.toLowerCase();
284
- const foundEntity = await catalogApi?.getEntityByRef(entityRef);
285
- if (foundEntity) {
286
- response.json(foundEntity.metadata.annotations?.["pagerduty.com/service-id"]);
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(404);
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(settings.map(async (setting) => {
307
- if (setting.id === void 0 || setting.value === void 0) {
308
- response.status(400).json("Bad Request: 'id' and 'value' are required");
309
- return;
310
- }
311
- if (!isValidSetting(setting.value)) {
312
- response.status(400).json("Bad Request: 'value' is invalid. Valid options are 'backstage', 'pagerduty', 'both' or 'disabled'");
313
- return;
314
- }
315
- await store.updateSetting(setting);
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(`Error occurred while processing request: ${error.message}`);
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("Bad Request: 'serviceId' must be provided as part of the request body");
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((mapping) => mapping.serviceId === entity.serviceId);
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((integration) => integration.vendor?.id === backstageVendorId);
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(`Error occurred while processing request: ${error.message}`);
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(entityMappings, componentEntitiesDict, componentEntities, pagerDutyServices);
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("/mapping/entity/:type/:namespace/:name", async (request, response) => {
427
- try {
428
- const entityType = request.params.type || "";
429
- const entityNamespace = request.params.namespace || "";
430
- const entityName = request.params.name || "";
431
- if (entityType === "" || entityNamespace === "" || entityName === "") {
432
- response.status(400).json("Required params not specified.");
433
- return;
434
- }
435
- const entityRef = `${entityType}:${entityNamespace}/${entityName}`.toLowerCase();
436
- const entityMapping = await store.findEntityMappingByEntityRef(entityRef);
437
- if (!entityMapping) {
438
- response.status(404).json(`Mapping for entityRef ${entityRef} not found.`);
439
- return;
440
- }
441
- response.json({
442
- mapping: entityMapping
443
- });
444
- } catch (error) {
445
- if (error instanceof backstagePluginCommon.HttpError) {
446
- response.status(error.status).json({
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("/mapping/entity/service/:serviceId", async (request, response) => {
455
- try {
456
- const serviceId = request.params.serviceId ?? "";
457
- if (serviceId === "") {
458
- response.status(400).json("Required params not specified.");
459
- return;
460
- }
461
- const entityMapping = await store.findEntityMappingByServiceId(serviceId);
462
- if (!entityMapping) {
463
- response.status(404).json(`Mapping for serviceId ${serviceId} not found.`);
464
- return;
465
- }
466
- response.json({
467
- mapping: entityMapping
468
- });
469
- } catch (error) {
470
- if (error instanceof backstagePluginCommon.HttpError) {
471
- response.status(error.status).json({
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((policy) => {
489
- let policyLabel = policy.name;
490
- if (policy.account && policy.account !== "default") {
491
- policyLabel = `(${policy.account}) ${policy.name}`;
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
- return {
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("Bad Request: ':serviceId' must be provided as part of the path or 'integration_key' as a query parameter");
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(integrationKey, account);
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("/services/:serviceId/integration/:vendorId", async (request, response) => {
583
- try {
584
- const serviceId = request.params.serviceId || "";
585
- const vendorId = request.params.vendorId || "";
586
- const account = request.query.account || "";
587
- if (serviceId === "" || vendorId === "") {
588
- response.status(400).json("Bad Request: ':serviceId' and ':vendorId' must be provided as part of the path");
589
- return;
590
- }
591
- const integrationKey = await pagerduty.createServiceIntegration({
592
- serviceId,
593
- vendorId,
594
- account
595
- });
596
- response.json(integrationKey);
597
- } catch (error) {
598
- if (error instanceof backstagePluginCommon.HttpError) {
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("/services/:serviceId/change-events", async (request, response) => {
609
- try {
610
- const serviceId = request.params.serviceId || "";
611
- const account = request.query.account || "";
612
- const changeEvents = await pagerduty.getChangeEvents(serviceId, account);
613
- const changeEventsResponse = {
614
- change_events: changeEvents
615
- };
616
- response.json(changeEventsResponse);
617
- } catch (error) {
618
- if (error instanceof backstagePluginCommon.HttpError) {
619
- response.status(error.status).json({
620
- errors: [
621
- `${error.message}`
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
  }