diff --git a/config.d.ts b/config.d.ts index be21500..09bf304 100644 --- a/config.d.ts +++ b/config.d.ts @@ -27,6 +27,11 @@ export interface Config { * @visibility frontend */ eventsBaseUrl?: string; + /** + * Optional API Base URL to override the default. + * @visibility frontend + */ + apiBaseUrl?: string; /** * Optional PagerDuty API Token used in API calls from the backend component. * @visibility frontend diff --git a/src/apis/pagerduty.ts b/src/apis/pagerduty.ts index b62680b..492e04f 100644 --- a/src/apis/pagerduty.ts +++ b/src/apis/pagerduty.ts @@ -20,11 +20,16 @@ import { HttpError } from '@pagerduty/backstage-plugin-common'; +let apiBaseUrl = 'https://api.pagerduty.com'; +export function setAPIBaseUrl(url: string): void { + apiBaseUrl = url; +} + // Supporting custom actions export async function createService(name: string, description: string, escalationPolicyId: string, alertGrouping?: string): Promise { let alertGroupingParameters = "null"; let response: Response; - const baseUrl = 'https://api.pagerduty.com/services'; + const baseUrl = `${apiBaseUrl}/services`; // Set default body let body = JSON.stringify({ @@ -176,7 +181,7 @@ export async function createService(name: string, description: string, escalatio export async function createServiceIntegration(serviceId: string, vendorId: string): Promise { let response: Response; - const baseUrl = 'https://api.pagerduty.com/services'; + const baseUrl = `${apiBaseUrl}/services`; const options: RequestInit = { method: 'POST', body: JSON.stringify({ @@ -242,7 +247,7 @@ async function getEscalationPolicies(offset: number, limit: number): Promise<[Bo 'Content-Type': 'application/json', }, }; - const baseUrl = 'https://api.pagerduty.com/escalation_policies'; + const baseUrl = `${apiBaseUrl}/escalation_policies`; try { response = await fetch(`${baseUrl}?${params}`, options); @@ -353,7 +358,7 @@ export async function getOncallUsers(escalationPolicy: string): Promise