@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.
- 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 +3 -4
- 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
|
@@ -26,17 +26,23 @@ function insertEndpointConfig(account) {
|
|
|
26
26
|
}
|
|
27
27
|
function loadPagerDutyEndpointsFromConfig(config, logger) {
|
|
28
28
|
if (config.getOptional("pagerDuty.accounts")) {
|
|
29
|
-
logger.debug(
|
|
29
|
+
logger.debug(
|
|
30
|
+
`New accounts configuration detected. Loading PagerDuty endpoints from config.`
|
|
31
|
+
);
|
|
30
32
|
isLegacyConfig = false;
|
|
31
33
|
const accounts = config.getOptional("pagerDuty.accounts");
|
|
32
34
|
if (accounts?.length === 1) {
|
|
33
|
-
logger.debug(
|
|
35
|
+
logger.debug(
|
|
36
|
+
`Single account configuration detected. Loading PagerDuty endpoints from config to 'default'.`
|
|
37
|
+
);
|
|
34
38
|
EndpointConfig.default = {
|
|
35
39
|
eventsBaseUrl: accounts[0].eventsBaseUrl !== void 0 ? accounts[0].eventsBaseUrl : "https://events.pagerduty.com/v2",
|
|
36
40
|
apiBaseUrl: accounts[0].apiBaseUrl !== void 0 ? accounts[0].apiBaseUrl : "https://api.pagerduty.com"
|
|
37
41
|
};
|
|
38
42
|
} else {
|
|
39
|
-
logger.debug(
|
|
43
|
+
logger.debug(
|
|
44
|
+
`Multiple account configuration detected. Loading PagerDuty endpoints from config.`
|
|
45
|
+
);
|
|
40
46
|
accounts?.forEach((account) => {
|
|
41
47
|
if (account.isDefault) {
|
|
42
48
|
setFallbackEndpointConfig(account);
|
|
@@ -68,7 +74,7 @@ async function addServiceRelationsToService(serviceRelations, account) {
|
|
|
68
74
|
method: "POST",
|
|
69
75
|
headers: {
|
|
70
76
|
Authorization: await auth.getAuthToken(account),
|
|
71
|
-
|
|
77
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
72
78
|
"Content-Type": "application/json"
|
|
73
79
|
},
|
|
74
80
|
body: JSON.stringify({
|
|
@@ -83,24 +89,42 @@ async function addServiceRelationsToService(serviceRelations, account) {
|
|
|
83
89
|
throw new Error(`Failed to retrieve service dependencies: ${error}`);
|
|
84
90
|
}
|
|
85
91
|
if (response.status >= 500) {
|
|
86
|
-
throw new backstagePluginCommon.HttpError(
|
|
92
|
+
throw new backstagePluginCommon.HttpError(
|
|
93
|
+
`Failed to add service dependencies. PagerDuty API returned a server error. Retrying with the same arguments will not work.`,
|
|
94
|
+
response.status
|
|
95
|
+
);
|
|
87
96
|
}
|
|
88
97
|
switch (response.status) {
|
|
89
98
|
case 400:
|
|
90
|
-
throw new backstagePluginCommon.HttpError(
|
|
99
|
+
throw new backstagePluginCommon.HttpError(
|
|
100
|
+
"Failed to add service dependencies. Caller provided invalid arguments. Please review the response for error details. Retrying with the same arguments will not work.",
|
|
101
|
+
400
|
|
102
|
+
);
|
|
91
103
|
case 401:
|
|
92
|
-
throw new backstagePluginCommon.HttpError(
|
|
104
|
+
throw new backstagePluginCommon.HttpError(
|
|
105
|
+
"Failed to add service dependencies. Caller did not supply credentials or did not provide the correct credentials. If you are using an API key, it may be invalid or your Authorization header may be malformed.",
|
|
106
|
+
401
|
|
107
|
+
);
|
|
93
108
|
case 403:
|
|
94
|
-
throw new backstagePluginCommon.HttpError(
|
|
109
|
+
throw new backstagePluginCommon.HttpError(
|
|
110
|
+
"Failed to add service dependencies. Caller is not authorized to view the requested resource. While your authentication is valid, the authenticated user or token does not have permission to perform this action.",
|
|
111
|
+
403
|
|
112
|
+
);
|
|
95
113
|
case 404:
|
|
96
|
-
throw new backstagePluginCommon.HttpError(
|
|
114
|
+
throw new backstagePluginCommon.HttpError(
|
|
115
|
+
"Failed to add service dependencies. The requested resource was not found.",
|
|
116
|
+
404
|
|
117
|
+
);
|
|
97
118
|
}
|
|
98
119
|
let result;
|
|
99
120
|
try {
|
|
100
121
|
result = await response.json();
|
|
101
122
|
return result.relationships;
|
|
102
123
|
} catch (error) {
|
|
103
|
-
throw new backstagePluginCommon.HttpError(
|
|
124
|
+
throw new backstagePluginCommon.HttpError(
|
|
125
|
+
`Failed to parse service dependency information: ${error}`,
|
|
126
|
+
500
|
|
127
|
+
);
|
|
104
128
|
}
|
|
105
129
|
}
|
|
106
130
|
async function removeServiceRelationsFromService(serviceRelations, account) {
|
|
@@ -109,7 +133,7 @@ async function removeServiceRelationsFromService(serviceRelations, account) {
|
|
|
109
133
|
method: "POST",
|
|
110
134
|
headers: {
|
|
111
135
|
Authorization: await auth.getAuthToken(account),
|
|
112
|
-
|
|
136
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
113
137
|
"Content-Type": "application/json"
|
|
114
138
|
},
|
|
115
139
|
body: JSON.stringify({
|
|
@@ -124,24 +148,42 @@ async function removeServiceRelationsFromService(serviceRelations, account) {
|
|
|
124
148
|
throw new Error(`Failed to retrieve service dependencies: ${error}`);
|
|
125
149
|
}
|
|
126
150
|
if (response.status >= 500) {
|
|
127
|
-
throw new backstagePluginCommon.HttpError(
|
|
151
|
+
throw new backstagePluginCommon.HttpError(
|
|
152
|
+
`Failed to remove service dependencies. PagerDuty API returned a server error. Retrying with the same arguments will not work.`,
|
|
153
|
+
response.status
|
|
154
|
+
);
|
|
128
155
|
}
|
|
129
156
|
switch (response.status) {
|
|
130
157
|
case 400:
|
|
131
|
-
throw new backstagePluginCommon.HttpError(
|
|
158
|
+
throw new backstagePluginCommon.HttpError(
|
|
159
|
+
"Failed to remove service dependencies. Caller provided invalid arguments. Please review the response for error details. Retrying with the same arguments will not work.",
|
|
160
|
+
400
|
|
161
|
+
);
|
|
132
162
|
case 401:
|
|
133
|
-
throw new backstagePluginCommon.HttpError(
|
|
163
|
+
throw new backstagePluginCommon.HttpError(
|
|
164
|
+
"Failed to remove service dependencies. Caller did not supply credentials or did not provide the correct credentials. If you are using an API key, it may be invalid or your Authorization header may be malformed.",
|
|
165
|
+
401
|
|
166
|
+
);
|
|
134
167
|
case 403:
|
|
135
|
-
throw new backstagePluginCommon.HttpError(
|
|
168
|
+
throw new backstagePluginCommon.HttpError(
|
|
169
|
+
"Failed to remove service dependencies. Caller is not authorized to view the requested resource. While your authentication is valid, the authenticated user or token does not have permission to perform this action.",
|
|
170
|
+
403
|
|
171
|
+
);
|
|
136
172
|
case 404:
|
|
137
|
-
throw new backstagePluginCommon.HttpError(
|
|
173
|
+
throw new backstagePluginCommon.HttpError(
|
|
174
|
+
"Failed to remove service dependencies. The requested resource was not found.",
|
|
175
|
+
404
|
|
176
|
+
);
|
|
138
177
|
}
|
|
139
178
|
let result;
|
|
140
179
|
try {
|
|
141
180
|
result = await response.json();
|
|
142
181
|
return result.relationships;
|
|
143
182
|
} catch (error) {
|
|
144
|
-
throw new backstagePluginCommon.HttpError(
|
|
183
|
+
throw new backstagePluginCommon.HttpError(
|
|
184
|
+
`Failed to parse service dependency information: ${error}`,
|
|
185
|
+
500
|
|
186
|
+
);
|
|
145
187
|
}
|
|
146
188
|
}
|
|
147
189
|
async function getServiceRelationshipsById(serviceId, account) {
|
|
@@ -150,7 +192,7 @@ async function getServiceRelationshipsById(serviceId, account) {
|
|
|
150
192
|
method: "GET",
|
|
151
193
|
headers: {
|
|
152
194
|
Authorization: await auth.getAuthToken(account),
|
|
153
|
-
|
|
195
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
154
196
|
"Content-Type": "application/json"
|
|
155
197
|
}
|
|
156
198
|
};
|
|
@@ -162,24 +204,42 @@ async function getServiceRelationshipsById(serviceId, account) {
|
|
|
162
204
|
throw new Error(`Failed to retrieve service dependencies: ${error}`);
|
|
163
205
|
}
|
|
164
206
|
if (response.status >= 500) {
|
|
165
|
-
throw new backstagePluginCommon.HttpError(
|
|
207
|
+
throw new backstagePluginCommon.HttpError(
|
|
208
|
+
`Failed to list service dependencies. PagerDuty API returned a server error. Retrying with the same arguments will not work.`,
|
|
209
|
+
response.status
|
|
210
|
+
);
|
|
166
211
|
}
|
|
167
212
|
switch (response.status) {
|
|
168
213
|
case 400:
|
|
169
|
-
throw new backstagePluginCommon.HttpError(
|
|
214
|
+
throw new backstagePluginCommon.HttpError(
|
|
215
|
+
"Failed to list service dependencies. Caller provided invalid arguments. Please review the response for error details. Retrying with the same arguments will not work.",
|
|
216
|
+
400
|
|
217
|
+
);
|
|
170
218
|
case 401:
|
|
171
|
-
throw new backstagePluginCommon.HttpError(
|
|
219
|
+
throw new backstagePluginCommon.HttpError(
|
|
220
|
+
"Failed to list service dependencies. Caller did not supply credentials or did not provide the correct credentials. If you are using an API key, it may be invalid or your Authorization header may be malformed.",
|
|
221
|
+
401
|
|
222
|
+
);
|
|
172
223
|
case 403:
|
|
173
|
-
throw new backstagePluginCommon.HttpError(
|
|
224
|
+
throw new backstagePluginCommon.HttpError(
|
|
225
|
+
"Failed to list service dependencies. Caller is not authorized to view the requested resource. While your authentication is valid, the authenticated user or token does not have permission to perform this action.",
|
|
226
|
+
403
|
|
227
|
+
);
|
|
174
228
|
case 404:
|
|
175
|
-
throw new backstagePluginCommon.HttpError(
|
|
229
|
+
throw new backstagePluginCommon.HttpError(
|
|
230
|
+
"Failed to list service dependencies. The requested resource was not found.",
|
|
231
|
+
404
|
|
232
|
+
);
|
|
176
233
|
}
|
|
177
234
|
let result;
|
|
178
235
|
try {
|
|
179
236
|
result = await response.json();
|
|
180
237
|
return result.relationships;
|
|
181
238
|
} catch (error) {
|
|
182
|
-
throw new backstagePluginCommon.HttpError(
|
|
239
|
+
throw new backstagePluginCommon.HttpError(
|
|
240
|
+
`Failed to parse service dependency information: ${error}`,
|
|
241
|
+
500
|
|
242
|
+
);
|
|
183
243
|
}
|
|
184
244
|
}
|
|
185
245
|
async function getEscalationPolicies(offset, limit, account) {
|
|
@@ -189,7 +249,7 @@ async function getEscalationPolicies(offset, limit, account) {
|
|
|
189
249
|
method: "GET",
|
|
190
250
|
headers: {
|
|
191
251
|
Authorization: await auth.getAuthToken(account),
|
|
192
|
-
|
|
252
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
193
253
|
"Content-Type": "application/json"
|
|
194
254
|
}
|
|
195
255
|
};
|
|
@@ -201,24 +261,42 @@ async function getEscalationPolicies(offset, limit, account) {
|
|
|
201
261
|
throw new Error(`Failed to retrieve escalation policies: ${error}`);
|
|
202
262
|
}
|
|
203
263
|
if (response.status >= 500) {
|
|
204
|
-
throw new backstagePluginCommon.HttpError(
|
|
264
|
+
throw new backstagePluginCommon.HttpError(
|
|
265
|
+
`Failed to list escalation policies. PagerDuty API returned a server error. Retrying with the same arguments will not work.`,
|
|
266
|
+
response.status
|
|
267
|
+
);
|
|
205
268
|
}
|
|
206
269
|
switch (response.status) {
|
|
207
270
|
case 400:
|
|
208
|
-
throw new backstagePluginCommon.HttpError(
|
|
271
|
+
throw new backstagePluginCommon.HttpError(
|
|
272
|
+
"Failed to list escalation policies. Caller provided invalid arguments.",
|
|
273
|
+
400
|
|
274
|
+
);
|
|
209
275
|
case 401:
|
|
210
|
-
throw new backstagePluginCommon.HttpError(
|
|
276
|
+
throw new backstagePluginCommon.HttpError(
|
|
277
|
+
"Failed to list escalation policies. Caller did not supply credentials or did not provide the correct credentials.",
|
|
278
|
+
401
|
|
279
|
+
);
|
|
211
280
|
case 403:
|
|
212
|
-
throw new backstagePluginCommon.HttpError(
|
|
281
|
+
throw new backstagePluginCommon.HttpError(
|
|
282
|
+
"Failed to list escalation policies. Caller is not authorized to view the requested resource.",
|
|
283
|
+
403
|
|
284
|
+
);
|
|
213
285
|
case 429:
|
|
214
|
-
throw new backstagePluginCommon.HttpError(
|
|
286
|
+
throw new backstagePluginCommon.HttpError(
|
|
287
|
+
"Failed to list escalation policies. Rate limit exceeded.",
|
|
288
|
+
429
|
|
289
|
+
);
|
|
215
290
|
}
|
|
216
291
|
let result;
|
|
217
292
|
try {
|
|
218
293
|
result = await response.json();
|
|
219
294
|
return [result.more ?? false, result.escalation_policies];
|
|
220
295
|
} catch (error) {
|
|
221
|
-
throw new backstagePluginCommon.HttpError(
|
|
296
|
+
throw new backstagePluginCommon.HttpError(
|
|
297
|
+
`Failed to parse escalation policy information: ${error}`,
|
|
298
|
+
500
|
|
299
|
+
);
|
|
222
300
|
}
|
|
223
301
|
}
|
|
224
302
|
async function getAllEscalationPolicies() {
|
|
@@ -261,7 +339,7 @@ async function getOncallUsers(escalationPolicy, account) {
|
|
|
261
339
|
method: "GET",
|
|
262
340
|
headers: {
|
|
263
341
|
Authorization: await auth.getAuthToken(account),
|
|
264
|
-
|
|
342
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
265
343
|
"Content-Type": "application/json"
|
|
266
344
|
}
|
|
267
345
|
};
|
|
@@ -273,15 +351,27 @@ async function getOncallUsers(escalationPolicy, account) {
|
|
|
273
351
|
throw new Error(`Failed to retrieve oncalls: ${error}`);
|
|
274
352
|
}
|
|
275
353
|
if (response.status >= 500) {
|
|
276
|
-
throw new backstagePluginCommon.HttpError(
|
|
354
|
+
throw new backstagePluginCommon.HttpError(
|
|
355
|
+
`Failed to list oncalls. PagerDuty API returned a server error. Retrying with the same arguments will not work.`,
|
|
356
|
+
response.status
|
|
357
|
+
);
|
|
277
358
|
}
|
|
278
359
|
switch (response.status) {
|
|
279
360
|
case 400:
|
|
280
|
-
throw new backstagePluginCommon.HttpError(
|
|
361
|
+
throw new backstagePluginCommon.HttpError(
|
|
362
|
+
"Failed to list oncalls. Caller provided invalid arguments.",
|
|
363
|
+
400
|
|
364
|
+
);
|
|
281
365
|
case 401:
|
|
282
|
-
throw new backstagePluginCommon.HttpError(
|
|
366
|
+
throw new backstagePluginCommon.HttpError(
|
|
367
|
+
"Failed to list oncalls. Caller did not supply credentials or did not provide the correct credentials.",
|
|
368
|
+
401
|
|
369
|
+
);
|
|
283
370
|
case 403:
|
|
284
|
-
throw new backstagePluginCommon.HttpError(
|
|
371
|
+
throw new backstagePluginCommon.HttpError(
|
|
372
|
+
"Failed to list oncalls. Caller is not authorized to view the requested resource.",
|
|
373
|
+
403
|
|
374
|
+
);
|
|
285
375
|
case 429:
|
|
286
376
|
throw new backstagePluginCommon.HttpError("Failed to list oncalls. Rate limit exceeded.", 429);
|
|
287
377
|
}
|
|
@@ -320,29 +410,47 @@ async function getServiceById(serviceId, account) {
|
|
|
320
410
|
method: "GET",
|
|
321
411
|
headers: {
|
|
322
412
|
Authorization: token,
|
|
323
|
-
|
|
413
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
324
414
|
"Content-Type": "application/json"
|
|
325
415
|
}
|
|
326
416
|
};
|
|
327
417
|
const apiBaseUrl = getApiBaseUrl(account);
|
|
328
418
|
const baseUrl = `${apiBaseUrl}/services`;
|
|
329
419
|
try {
|
|
330
|
-
response = await fetchWithRetries(
|
|
420
|
+
response = await fetchWithRetries(
|
|
421
|
+
`${baseUrl}/${serviceId}?${params}`,
|
|
422
|
+
options
|
|
423
|
+
);
|
|
331
424
|
} catch (error) {
|
|
332
425
|
throw new Error(`Failed to retrieve service: ${error}`);
|
|
333
426
|
}
|
|
334
427
|
if (response.status >= 500) {
|
|
335
|
-
throw new backstagePluginCommon.HttpError(
|
|
428
|
+
throw new backstagePluginCommon.HttpError(
|
|
429
|
+
`Failed to get service. PagerDuty API returned a server error. Retrying with the same arguments will not work.`,
|
|
430
|
+
response.status
|
|
431
|
+
);
|
|
336
432
|
}
|
|
337
433
|
switch (response.status) {
|
|
338
434
|
case 400:
|
|
339
|
-
throw new backstagePluginCommon.HttpError(
|
|
435
|
+
throw new backstagePluginCommon.HttpError(
|
|
436
|
+
"Failed to get service. Caller provided invalid arguments.",
|
|
437
|
+
400
|
|
438
|
+
);
|
|
340
439
|
case 401:
|
|
341
|
-
throw new backstagePluginCommon.HttpError(
|
|
440
|
+
throw new backstagePluginCommon.HttpError(
|
|
441
|
+
"Failed to get service. Caller did not supply credentials or did not provide the correct credentials.",
|
|
442
|
+
401
|
|
443
|
+
);
|
|
342
444
|
case 403:
|
|
343
|
-
throw new backstagePluginCommon.HttpError(
|
|
445
|
+
throw new backstagePluginCommon.HttpError(
|
|
446
|
+
"Failed to get service. Caller is not authorized to view the requested resource.",
|
|
447
|
+
403
|
|
448
|
+
);
|
|
344
449
|
case 404:
|
|
345
|
-
throw new backstagePluginCommon.HttpError(
|
|
450
|
+
throw new backstagePluginCommon.HttpError(
|
|
451
|
+
"Failed to get service. The requested resource was not found.",
|
|
452
|
+
404
|
|
453
|
+
);
|
|
346
454
|
}
|
|
347
455
|
let result;
|
|
348
456
|
try {
|
|
@@ -360,7 +468,7 @@ async function getServiceByIntegrationKey(integrationKey, account) {
|
|
|
360
468
|
method: "GET",
|
|
361
469
|
headers: {
|
|
362
470
|
Authorization: token,
|
|
363
|
-
|
|
471
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
364
472
|
"Content-Type": "application/json"
|
|
365
473
|
}
|
|
366
474
|
};
|
|
@@ -372,17 +480,32 @@ async function getServiceByIntegrationKey(integrationKey, account) {
|
|
|
372
480
|
throw new Error(`Failed to retrieve service: ${error}`);
|
|
373
481
|
}
|
|
374
482
|
if (response.status >= 500) {
|
|
375
|
-
throw new backstagePluginCommon.HttpError(
|
|
483
|
+
throw new backstagePluginCommon.HttpError(
|
|
484
|
+
`Failed to get service. PagerDuty API returned a server error. Retrying with the same arguments will not work.`,
|
|
485
|
+
response.status
|
|
486
|
+
);
|
|
376
487
|
}
|
|
377
488
|
switch (response.status) {
|
|
378
489
|
case 400:
|
|
379
|
-
throw new backstagePluginCommon.HttpError(
|
|
490
|
+
throw new backstagePluginCommon.HttpError(
|
|
491
|
+
"Failed to get service. Caller provided invalid arguments.",
|
|
492
|
+
400
|
|
493
|
+
);
|
|
380
494
|
case 401:
|
|
381
|
-
throw new backstagePluginCommon.HttpError(
|
|
495
|
+
throw new backstagePluginCommon.HttpError(
|
|
496
|
+
"Failed to get service. Caller did not supply credentials or did not provide the correct credentials.",
|
|
497
|
+
401
|
|
498
|
+
);
|
|
382
499
|
case 403:
|
|
383
|
-
throw new backstagePluginCommon.HttpError(
|
|
500
|
+
throw new backstagePluginCommon.HttpError(
|
|
501
|
+
"Failed to get service. Caller is not authorized to view the requested resource.",
|
|
502
|
+
403
|
|
503
|
+
);
|
|
384
504
|
case 404:
|
|
385
|
-
throw new backstagePluginCommon.HttpError(
|
|
505
|
+
throw new backstagePluginCommon.HttpError(
|
|
506
|
+
"Failed to get service. The requested resource was not found.",
|
|
507
|
+
404
|
|
508
|
+
);
|
|
386
509
|
}
|
|
387
510
|
let result;
|
|
388
511
|
try {
|
|
@@ -391,7 +514,10 @@ async function getServiceByIntegrationKey(integrationKey, account) {
|
|
|
391
514
|
throw new backstagePluginCommon.HttpError(`Failed to parse service information: ${error}`, 500);
|
|
392
515
|
}
|
|
393
516
|
if (result.services.length === 0) {
|
|
394
|
-
throw new backstagePluginCommon.HttpError(
|
|
517
|
+
throw new backstagePluginCommon.HttpError(
|
|
518
|
+
`Failed to get service. The requested resource was not found.`,
|
|
519
|
+
404
|
|
520
|
+
);
|
|
395
521
|
}
|
|
396
522
|
return result.services[0];
|
|
397
523
|
}
|
|
@@ -406,7 +532,7 @@ async function getAllServices() {
|
|
|
406
532
|
method: "GET",
|
|
407
533
|
headers: {
|
|
408
534
|
Authorization: token,
|
|
409
|
-
|
|
535
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
410
536
|
"Content-Type": "application/json"
|
|
411
537
|
}
|
|
412
538
|
};
|
|
@@ -420,15 +546,27 @@ async function getAllServices() {
|
|
|
420
546
|
const paginatedUrl = `${baseUrl}?${params}&offset=${offset}&limit=${limit}`;
|
|
421
547
|
response = await fetchWithRetries(paginatedUrl, options);
|
|
422
548
|
if (response.status >= 500) {
|
|
423
|
-
throw new backstagePluginCommon.HttpError(
|
|
549
|
+
throw new backstagePluginCommon.HttpError(
|
|
550
|
+
`Failed to get services. PagerDuty API returned a server error. Retrying with the same arguments will not work.`,
|
|
551
|
+
response.status
|
|
552
|
+
);
|
|
424
553
|
}
|
|
425
554
|
switch (response.status) {
|
|
426
555
|
case 400:
|
|
427
|
-
throw new backstagePluginCommon.HttpError(
|
|
556
|
+
throw new backstagePluginCommon.HttpError(
|
|
557
|
+
"Failed to get services. Caller provided invalid arguments.",
|
|
558
|
+
400
|
|
559
|
+
);
|
|
428
560
|
case 401:
|
|
429
|
-
throw new backstagePluginCommon.HttpError(
|
|
561
|
+
throw new backstagePluginCommon.HttpError(
|
|
562
|
+
"Failed to get services. Caller did not supply credentials or did not provide the correct credentials.",
|
|
563
|
+
401
|
|
564
|
+
);
|
|
430
565
|
case 403:
|
|
431
|
-
throw new backstagePluginCommon.HttpError(
|
|
566
|
+
throw new backstagePluginCommon.HttpError(
|
|
567
|
+
"Failed to get services. Caller is not authorized to view the requested resource.",
|
|
568
|
+
403
|
|
569
|
+
);
|
|
432
570
|
default:
|
|
433
571
|
break;
|
|
434
572
|
}
|
|
@@ -453,36 +591,57 @@ async function getChangeEvents(serviceId, account) {
|
|
|
453
591
|
method: "GET",
|
|
454
592
|
headers: {
|
|
455
593
|
Authorization: await auth.getAuthToken(account),
|
|
456
|
-
|
|
594
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
457
595
|
"Content-Type": "application/json"
|
|
458
596
|
}
|
|
459
597
|
};
|
|
460
598
|
const apiBaseUrl = getApiBaseUrl(account);
|
|
461
599
|
const baseUrl = `${apiBaseUrl}/services`;
|
|
462
600
|
try {
|
|
463
|
-
response = await fetchWithRetries(
|
|
601
|
+
response = await fetchWithRetries(
|
|
602
|
+
`${baseUrl}/${serviceId}/change_events?${params}`,
|
|
603
|
+
options
|
|
604
|
+
);
|
|
464
605
|
} catch (error) {
|
|
465
606
|
throw new Error(`Failed to retrieve change events for service: ${error}`);
|
|
466
607
|
}
|
|
467
608
|
if (response.status >= 500) {
|
|
468
|
-
throw new backstagePluginCommon.HttpError(
|
|
609
|
+
throw new backstagePluginCommon.HttpError(
|
|
610
|
+
`Failed to get change events for service. PagerDuty API returned a server error. Retrying with the same arguments will not work.`,
|
|
611
|
+
response.status
|
|
612
|
+
);
|
|
469
613
|
}
|
|
470
614
|
switch (response.status) {
|
|
471
615
|
case 400:
|
|
472
|
-
throw new backstagePluginCommon.HttpError(
|
|
616
|
+
throw new backstagePluginCommon.HttpError(
|
|
617
|
+
"Failed to get change events for service. Caller provided invalid arguments.",
|
|
618
|
+
400
|
|
619
|
+
);
|
|
473
620
|
case 401:
|
|
474
|
-
throw new backstagePluginCommon.HttpError(
|
|
621
|
+
throw new backstagePluginCommon.HttpError(
|
|
622
|
+
"Failed to get change events for service. Caller did not supply credentials or did not provide the correct credentials.",
|
|
623
|
+
401
|
|
624
|
+
);
|
|
475
625
|
case 403:
|
|
476
|
-
throw new backstagePluginCommon.HttpError(
|
|
626
|
+
throw new backstagePluginCommon.HttpError(
|
|
627
|
+
"Failed to get change events for service. Caller is not authorized to view the requested resource.",
|
|
628
|
+
403
|
|
629
|
+
);
|
|
477
630
|
case 404:
|
|
478
|
-
throw new backstagePluginCommon.HttpError(
|
|
631
|
+
throw new backstagePluginCommon.HttpError(
|
|
632
|
+
"Failed to get change events for service. The requested resource was not found.",
|
|
633
|
+
404
|
|
634
|
+
);
|
|
479
635
|
}
|
|
480
636
|
let result;
|
|
481
637
|
try {
|
|
482
638
|
result = await response.json();
|
|
483
639
|
return result.change_events;
|
|
484
640
|
} catch (error) {
|
|
485
|
-
throw new backstagePluginCommon.HttpError(
|
|
641
|
+
throw new backstagePluginCommon.HttpError(
|
|
642
|
+
`Failed to parse change events information: ${error}`,
|
|
643
|
+
500
|
|
644
|
+
);
|
|
486
645
|
}
|
|
487
646
|
}
|
|
488
647
|
async function getIncidents(serviceId, account) {
|
|
@@ -492,7 +651,7 @@ async function getIncidents(serviceId, account) {
|
|
|
492
651
|
method: "GET",
|
|
493
652
|
headers: {
|
|
494
653
|
Authorization: await auth.getAuthToken(account),
|
|
495
|
-
|
|
654
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
496
655
|
"Content-Type": "application/json"
|
|
497
656
|
}
|
|
498
657
|
};
|
|
@@ -504,19 +663,37 @@ async function getIncidents(serviceId, account) {
|
|
|
504
663
|
throw new Error(`Failed to retrieve incidents for service: ${error}`);
|
|
505
664
|
}
|
|
506
665
|
if (response.status >= 500) {
|
|
507
|
-
throw new backstagePluginCommon.HttpError(
|
|
666
|
+
throw new backstagePluginCommon.HttpError(
|
|
667
|
+
`Failed to get incidents for service. PagerDuty API returned a server error. Retrying with the same arguments will not work.`,
|
|
668
|
+
response.status
|
|
669
|
+
);
|
|
508
670
|
}
|
|
509
671
|
switch (response.status) {
|
|
510
672
|
case 400:
|
|
511
|
-
throw new backstagePluginCommon.HttpError(
|
|
673
|
+
throw new backstagePluginCommon.HttpError(
|
|
674
|
+
"Failed to get incidents for service. Caller provided invalid arguments.",
|
|
675
|
+
400
|
|
676
|
+
);
|
|
512
677
|
case 401:
|
|
513
|
-
throw new backstagePluginCommon.HttpError(
|
|
678
|
+
throw new backstagePluginCommon.HttpError(
|
|
679
|
+
"Failed to get incidents for service. Caller did not supply credentials or did not provide the correct credentials.",
|
|
680
|
+
401
|
|
681
|
+
);
|
|
514
682
|
case 402:
|
|
515
|
-
throw new backstagePluginCommon.HttpError(
|
|
683
|
+
throw new backstagePluginCommon.HttpError(
|
|
684
|
+
"Failed to get incidents for service. Account does not have the abilities to perform the action. Please review the response for the required abilities.",
|
|
685
|
+
402
|
|
686
|
+
);
|
|
516
687
|
case 403:
|
|
517
|
-
throw new backstagePluginCommon.HttpError(
|
|
688
|
+
throw new backstagePluginCommon.HttpError(
|
|
689
|
+
"Failed to get incidents for service. Caller is not authorized to view the requested resource.",
|
|
690
|
+
403
|
|
691
|
+
);
|
|
518
692
|
case 429:
|
|
519
|
-
throw new backstagePluginCommon.HttpError(
|
|
693
|
+
throw new backstagePluginCommon.HttpError(
|
|
694
|
+
"Failed to get incidents for service. Too many requests have been made, the rate limit has been reached.",
|
|
695
|
+
429
|
|
696
|
+
);
|
|
520
697
|
}
|
|
521
698
|
let result;
|
|
522
699
|
try {
|
|
@@ -532,7 +709,7 @@ async function getServiceStandards(serviceId, account) {
|
|
|
532
709
|
method: "GET",
|
|
533
710
|
headers: {
|
|
534
711
|
Authorization: await auth.getAuthToken(account),
|
|
535
|
-
|
|
712
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
536
713
|
"Content-Type": "application/json"
|
|
537
714
|
}
|
|
538
715
|
};
|
|
@@ -541,24 +718,41 @@ async function getServiceStandards(serviceId, account) {
|
|
|
541
718
|
try {
|
|
542
719
|
response = await fetchWithRetries(baseUrl, options);
|
|
543
720
|
} catch (error) {
|
|
544
|
-
throw new Error(
|
|
721
|
+
throw new Error(
|
|
722
|
+
`Failed to retrieve service standards for service: ${error}`
|
|
723
|
+
);
|
|
545
724
|
}
|
|
546
725
|
if (response.status >= 500) {
|
|
547
|
-
throw new backstagePluginCommon.HttpError(
|
|
726
|
+
throw new backstagePluginCommon.HttpError(
|
|
727
|
+
`Failed to get service standards for service. PagerDuty API returned a server error. Retrying with the same arguments will not work.`,
|
|
728
|
+
response.status
|
|
729
|
+
);
|
|
548
730
|
}
|
|
549
731
|
switch (response.status) {
|
|
550
732
|
case 401:
|
|
551
|
-
throw new backstagePluginCommon.HttpError(
|
|
733
|
+
throw new backstagePluginCommon.HttpError(
|
|
734
|
+
"Failed to get service standards for service. Caller did not supply credentials or did not provide the correct credentials.",
|
|
735
|
+
401
|
|
736
|
+
);
|
|
552
737
|
case 403:
|
|
553
|
-
throw new backstagePluginCommon.HttpError(
|
|
738
|
+
throw new backstagePluginCommon.HttpError(
|
|
739
|
+
"Failed to get service standards for service. Caller is not authorized to view the requested resource.",
|
|
740
|
+
403
|
|
741
|
+
);
|
|
554
742
|
case 429:
|
|
555
|
-
throw new backstagePluginCommon.HttpError(
|
|
743
|
+
throw new backstagePluginCommon.HttpError(
|
|
744
|
+
"Failed to get service standards for service. Too many requests have been made, the rate limit has been reached.",
|
|
745
|
+
429
|
|
746
|
+
);
|
|
556
747
|
}
|
|
557
748
|
try {
|
|
558
749
|
const result = await response.json();
|
|
559
750
|
return result;
|
|
560
751
|
} catch (error) {
|
|
561
|
-
throw new backstagePluginCommon.HttpError(
|
|
752
|
+
throw new backstagePluginCommon.HttpError(
|
|
753
|
+
`Failed to parse service standards information: ${error}`,
|
|
754
|
+
500
|
|
755
|
+
);
|
|
562
756
|
}
|
|
563
757
|
}
|
|
564
758
|
async function getServiceMetrics(serviceId, account) {
|
|
@@ -569,16 +763,14 @@ async function getServiceMetrics(serviceId, account) {
|
|
|
569
763
|
filters: {
|
|
570
764
|
created_at_start: startDate.toISO(),
|
|
571
765
|
created_at_end: endDate.toISO(),
|
|
572
|
-
service_ids: [
|
|
573
|
-
serviceId
|
|
574
|
-
]
|
|
766
|
+
service_ids: [serviceId]
|
|
575
767
|
}
|
|
576
768
|
});
|
|
577
769
|
const options = {
|
|
578
770
|
method: "POST",
|
|
579
771
|
headers: {
|
|
580
772
|
Authorization: await auth.getAuthToken(account),
|
|
581
|
-
|
|
773
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
582
774
|
"Content-Type": "application/json"
|
|
583
775
|
},
|
|
584
776
|
body
|
|
@@ -591,22 +783,38 @@ async function getServiceMetrics(serviceId, account) {
|
|
|
591
783
|
throw new Error(`Failed to retrieve service metrics for service: ${error}`);
|
|
592
784
|
}
|
|
593
785
|
if (response.status >= 500) {
|
|
594
|
-
throw new backstagePluginCommon.HttpError(
|
|
786
|
+
throw new backstagePluginCommon.HttpError(
|
|
787
|
+
`Failed to get service metrics for service. PagerDuty API returned a server error. Retrying with the same arguments will not work.`,
|
|
788
|
+
response.status
|
|
789
|
+
);
|
|
595
790
|
}
|
|
596
791
|
switch (response.status) {
|
|
597
792
|
case 400:
|
|
598
|
-
throw new backstagePluginCommon.HttpError(
|
|
793
|
+
throw new backstagePluginCommon.HttpError(
|
|
794
|
+
"Failed to get service metrics for service. Caller provided invalid arguments. Please review the response for error details. Retrying with the same arguments will not work.",
|
|
795
|
+
400
|
|
796
|
+
);
|
|
599
797
|
case 429:
|
|
600
|
-
throw new backstagePluginCommon.HttpError(
|
|
798
|
+
throw new backstagePluginCommon.HttpError(
|
|
799
|
+
"Failed to get service metrics for service. Too many requests have been made, the rate limit has been reached.",
|
|
800
|
+
429
|
|
801
|
+
);
|
|
601
802
|
}
|
|
602
803
|
try {
|
|
603
804
|
const result = await response.json();
|
|
604
805
|
return result.data;
|
|
605
806
|
} catch (error) {
|
|
606
|
-
throw new backstagePluginCommon.HttpError(
|
|
807
|
+
throw new backstagePluginCommon.HttpError(
|
|
808
|
+
`Failed to parse service metrics information: ${error}`,
|
|
809
|
+
500
|
|
810
|
+
);
|
|
607
811
|
}
|
|
608
812
|
}
|
|
609
|
-
async function createServiceIntegration({
|
|
813
|
+
async function createServiceIntegration({
|
|
814
|
+
serviceId,
|
|
815
|
+
vendorId,
|
|
816
|
+
account
|
|
817
|
+
}) {
|
|
610
818
|
let response;
|
|
611
819
|
const apiBaseUrl = getApiBaseUrl(account);
|
|
612
820
|
const baseUrl = `${apiBaseUrl}/services`;
|
|
@@ -628,27 +836,40 @@ async function createServiceIntegration({ serviceId, vendorId, account }) {
|
|
|
628
836
|
}),
|
|
629
837
|
headers: {
|
|
630
838
|
Authorization: token,
|
|
631
|
-
|
|
839
|
+
Accept: "application/vnd.pagerduty+json;version=2",
|
|
632
840
|
"Content-Type": "application/json"
|
|
633
841
|
}
|
|
634
842
|
};
|
|
635
843
|
try {
|
|
636
|
-
response = await fetchWithRetries(
|
|
844
|
+
response = await fetchWithRetries(
|
|
845
|
+
`${baseUrl}/${serviceId}/integrations`,
|
|
846
|
+
options
|
|
847
|
+
);
|
|
637
848
|
} catch (error) {
|
|
638
849
|
throw new Error(`Failed to create service integration: ${error}`);
|
|
639
850
|
}
|
|
640
851
|
if (response.status >= 500) {
|
|
641
|
-
throw new Error(
|
|
852
|
+
throw new Error(
|
|
853
|
+
`Failed to create service integration. PagerDuty API returned a server error. Retrying with the same arguments will not work.`
|
|
854
|
+
);
|
|
642
855
|
}
|
|
643
856
|
switch (response.status) {
|
|
644
857
|
case 400:
|
|
645
|
-
throw new Error(
|
|
858
|
+
throw new Error(
|
|
859
|
+
`Failed to create service integration. Caller provided invalid arguments.`
|
|
860
|
+
);
|
|
646
861
|
case 401:
|
|
647
|
-
throw new Error(
|
|
862
|
+
throw new Error(
|
|
863
|
+
`Failed to create service integration. Caller did not supply credentials or did not provide the correct credentials.`
|
|
864
|
+
);
|
|
648
865
|
case 403:
|
|
649
|
-
throw new Error(
|
|
866
|
+
throw new Error(
|
|
867
|
+
`Failed to create service integration. Caller is not authorized to view the requested resource.`
|
|
868
|
+
);
|
|
650
869
|
case 429:
|
|
651
|
-
throw new Error(
|
|
870
|
+
throw new Error(
|
|
871
|
+
`Failed to create service integration. Rate limit exceeded.`
|
|
872
|
+
);
|
|
652
873
|
}
|
|
653
874
|
let result;
|
|
654
875
|
try {
|
|
@@ -675,7 +896,9 @@ async function fetchWithRetries(url, options) {
|
|
|
675
896
|
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
676
897
|
factor *= 2;
|
|
677
898
|
}
|
|
678
|
-
throw new Error(
|
|
899
|
+
throw new Error(
|
|
900
|
+
`Failed to fetch data after ${maxRetries} retries. Last error: ${error}`
|
|
901
|
+
);
|
|
679
902
|
}
|
|
680
903
|
|
|
681
904
|
exports.addServiceRelationsToService = addServiceRelationsToService;
|