diff --git a/packages/app/src/components/catalog/EntityPage.tsx b/packages/app/src/components/catalog/EntityPage.tsx
index 51467fc2bb..7629c86a1e 100644
--- a/packages/app/src/components/catalog/EntityPage.tsx
+++ b/packages/app/src/components/catalog/EntityPage.tsx
@@ -135,11 +135,11 @@ const OverviewContent = ({ entity }: { entity: Entity }) => (
- {isPagerDutyAvailable(entity) && (
-
-
-
- )}
+ {/* {isPagerDutyAvailable(entity) && ( */}
+
+
+
+ {/* )} */}
{isGitHubAvailable(entity) && (
<>
diff --git a/plugins/pagerduty/src/api/pagerDutyClient.ts b/plugins/pagerduty/src/api/pagerDutyClient.ts
index d5db842dab..fa42c82f9e 100644
--- a/plugins/pagerduty/src/api/pagerDutyClient.ts
+++ b/plugins/pagerduty/src/api/pagerDutyClient.ts
@@ -14,18 +14,22 @@
* limitations under the License.
*/
+const API_URL = 'https://api.pagerduty.com';
+const EVENTS_API_URL = 'https://events.pagerduty.com/v2';
+
type Options = {
method: string;
headers: {
'Content-Type': string;
Accept: string;
+ Authorization?: string;
};
- body: string;
+ body?: string;
};
const request = async (
url: string,
- options: Options,
+ options: any, //Options,
): Promise => {
const response = await fetch(url, options);
@@ -40,6 +44,25 @@ const request = async (
return await response.json();
};
+export const getServices = async (token: string, integrationKey: string) => {
+ const options = {
+ method: 'GET',
+ headers: {
+ Authorization: `Token token=${token}`,
+ Accept: 'application/vnd.pagerduty+json;version=2',
+ 'Content-Type': 'application/json',
+ },
+ // query: {
+ // query: encodeURIComponent(`key:${integrationKey}`),
+ // },
+ };
+
+ return request(
+ `${API_URL}/services/?query=key%253A238b701cc9d048f0bdd828355178eafe`,
+ options,
+ );
+};
+
export function triggerPagerDutyAlarm(
integrationKey: string,
source: string,
@@ -69,5 +92,5 @@ export function triggerPagerDutyAlarm(
}),
};
- return request('https://events.pagerduty.com/v2/enqueue', options);
+ return request(`${EVENTS_API_URL}/enqueue`, options);
}
diff --git a/plugins/pagerduty/src/components/PagerDutyServiceCard.tsx b/plugins/pagerduty/src/components/PagerDutyServiceCard.tsx
index e0564d76ce..917ae27090 100644
--- a/plugins/pagerduty/src/components/PagerDutyServiceCard.tsx
+++ b/plugins/pagerduty/src/components/PagerDutyServiceCard.tsx
@@ -14,13 +14,20 @@
* limitations under the License.
*/
import React from 'react';
-import { InfoCard, MissingAnnotationEmptyState } from '@backstage/core';
+import {
+ InfoCard,
+ MissingAnnotationEmptyState,
+ useApi,
+ configApiRef,
+} from '@backstage/core';
import { Entity } from '@backstage/catalog-model';
import { Grid } from '@material-ui/core';
import { Incidents } from './Incidents';
import { EscalationPolicy } from './Escalation';
import { PagerDutyData } from './types';
import { TriggerButton } from './TriggerButton';
+import { useAsync } from 'react-use';
+import { getServices } from '../api/pagerDutyClient';
export const PAGERDUTY_INTEGRATION_KEY = 'pagerduty.com/integration-key';
@@ -32,6 +39,20 @@ type Props = {
};
export const PagerDutyServiceCard = ({ entity }: Props) => {
+ const configApi = useApi(configApiRef);
+ const pagerDutyToken =
+ configApi.getOptionalString('pagerduty.api_token') ?? undefined;
+
+ console.log({ pagerDutyToken });
+ const { value, loading, error } = useAsync(async () => {
+ return await getServices(
+ pagerDutyToken!,
+ entity.metadata.annotations![PAGERDUTY_INTEGRATION_KEY],
+ );
+ });
+ if (value) console.log(value);
+ if (error) throw new Error(`Error in getting services, ${error}`);
+
// TODO: fetch this data
const mockData: PagerDutyData = {
pagerDutyServices: [
@@ -85,6 +106,7 @@ export const PagerDutyServiceCard = ({ entity }: Props) => {
+ {/* todo show something when we dont have token */}
);
};