address comments
This commit is contained in:
@@ -312,3 +312,5 @@ homepage:
|
||||
timezone: 'Europe/Stockholm'
|
||||
- label: TYO
|
||||
timezone: 'Asia/Tokyo'
|
||||
pagerduty:
|
||||
eventsBaseUrl: 'https://events.pagerduty.com/v2'
|
||||
|
||||
@@ -21,25 +21,25 @@
|
||||
"@backstage/plugin-kubernetes": "^0.3.0",
|
||||
"@backstage/plugin-lighthouse": "^0.2.3",
|
||||
"@backstage/plugin-newrelic": "^0.2.1",
|
||||
"@backstage/plugin-pagerduty": "0.2.1",
|
||||
"@backstage/plugin-register-component": "^0.2.2",
|
||||
"@backstage/plugin-rollbar": "^0.2.3",
|
||||
"@backstage/plugin-scaffolder": "^0.3.1",
|
||||
"@backstage/plugin-sentry": "^0.2.3",
|
||||
"@backstage/plugin-search": "^0.2.1",
|
||||
"@backstage/plugin-sentry": "^0.2.3",
|
||||
"@backstage/plugin-tech-radar": "^0.3.0",
|
||||
"@backstage/plugin-techdocs": "^0.2.3",
|
||||
"@backstage/plugin-user-settings": "^0.2.2",
|
||||
"@backstage/plugin-welcome": "^0.2.1",
|
||||
"@backstage/test-utils": "^0.1.3",
|
||||
"@backstage/plugin-pagerduty": "^0.2.1",
|
||||
"@backstage/theme": "^0.2.1",
|
||||
"@material-ui/core": "^4.11.0",
|
||||
"@material-ui/icons": "^4.9.1",
|
||||
"@octokit/rest": "^18.0.0",
|
||||
"@roadiehq/backstage-plugin-buildkite": "^0.1.3",
|
||||
"@roadiehq/backstage-plugin-github-insights": "^0.2.15",
|
||||
"@roadiehq/backstage-plugin-github-pull-requests": "^0.6.3",
|
||||
"@roadiehq/backstage-plugin-travis-ci": "^0.2.8",
|
||||
"@roadiehq/backstage-plugin-buildkite": "^0.1.3",
|
||||
"history": "^5.0.0",
|
||||
"prop-types": "^15.7.2",
|
||||
"react": "^16.12.0",
|
||||
|
||||
@@ -38,6 +38,6 @@ export { plugin as Cloudbuild } from '@backstage/plugin-cloudbuild';
|
||||
export { plugin as CostInsights } from '@backstage/plugin-cost-insights';
|
||||
export { plugin as GitHubInsights } from '@roadiehq/backstage-plugin-github-insights';
|
||||
export { plugin as UserSettings } from '@backstage/plugin-user-settings';
|
||||
export { plugin as Pagerduty } from '@backstage/plugin-pagerduty';
|
||||
export { plugin as PagerDuty } from '@backstage/plugin-pagerduty';
|
||||
export { plugin as Buildkite } from '@roadiehq/backstage-plugin-buildkite';
|
||||
export { plugin as Search } from '@backstage/plugin-search';
|
||||
|
||||
@@ -47,20 +47,13 @@ import {
|
||||
|
||||
## Client configuration
|
||||
|
||||
The client takes a config object which contains an instance of the `discoveryApi` which is used to look up the `baseUrl` of the `proxy`, and a `eventUrl` which is defaulted to: "https://events.pagerduty.com/v2".
|
||||
If you want to override the default URL for events, you can add it to `app-config.yaml`.
|
||||
|
||||
In `apis.ts`:
|
||||
In `app-config.yaml`:
|
||||
|
||||
```ts
|
||||
createApiFactory({
|
||||
api: pagerDutyApiRef,
|
||||
deps: { discoveryApi: discoveryApiRef },
|
||||
factory: ({ discoveryApi }) =>
|
||||
new PagerDutyClient({
|
||||
discoveryApi: discoveryApi,
|
||||
eventUrl: "https://events.pagerduty.com/v2" //to override the default value
|
||||
}),
|
||||
}),
|
||||
```yaml
|
||||
pagerduty:
|
||||
eventsBaseUrl: 'https://events.pagerduty.com/v2'
|
||||
```
|
||||
|
||||
## Providing the API Token
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createApiRef } from '@backstage/core';
|
||||
import { createApiRef, DiscoveryApi, ConfigApi } from '@backstage/core';
|
||||
import { Service, Incident, OnCall } from '../components/types';
|
||||
import {
|
||||
PagerDutyApi,
|
||||
@@ -34,6 +34,15 @@ export const pagerDutyApiRef = createApiRef<PagerDutyApi>({
|
||||
});
|
||||
|
||||
export class PagerDutyClient implements PagerDutyApi {
|
||||
static fromConfig(configApi: ConfigApi, discoveryApi: DiscoveryApi) {
|
||||
const eventsBaseUrl: string =
|
||||
configApi.getOptionalString('pagerDuty.eventsBaseUrl') ??
|
||||
'https://events.pagerduty.com/v2';
|
||||
return new PagerDutyClient({
|
||||
eventsBaseUrl,
|
||||
discoveryApi,
|
||||
});
|
||||
}
|
||||
constructor(private readonly config: ClientApiConfig) {}
|
||||
|
||||
async getServiceByIntegrationKey(integrationKey: string): Promise<Service[]> {
|
||||
@@ -98,7 +107,8 @@ export class PagerDutyClient implements PagerDutyApi {
|
||||
};
|
||||
|
||||
return this.request(
|
||||
`${this.config.eventsUrl ?? 'https://events.pagerduty.com/v2'}/enqueue`,
|
||||
`${this.config.eventsBaseUrl ??
|
||||
'https://events.pagerduty.com/v2'}/enqueue`,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ export type OnCallsResponse = {
|
||||
};
|
||||
|
||||
export type ClientApiConfig = {
|
||||
eventsUrl?: string;
|
||||
eventsBaseUrl?: string;
|
||||
discoveryApi: DiscoveryApi;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import { render, waitFor, fireEvent } from '@testing-library/react';
|
||||
import { render, waitFor, fireEvent, act } from '@testing-library/react';
|
||||
import { PagerDutyCard } from './PagerDutyCard';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { wrapInTestApp } from '@backstage/test-utils';
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
} from '@backstage/core';
|
||||
import { pagerDutyApiRef, UnauthorizedError, PagerDutyClient } from '../api';
|
||||
import { Service } from './types';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
|
||||
const mockPagerDutyApi: Partial<PagerDutyClient> = {
|
||||
getServiceByIntegrationKey: async () => [],
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
import { render, fireEvent, act } from '@testing-library/react';
|
||||
import { wrapInTestApp } from '@backstage/test-utils';
|
||||
import {
|
||||
ApiRegistry,
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
} from '@backstage/core';
|
||||
import { pagerDutyApiRef } from '../../api';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { TriggerDialog } from './TriggerDialog';
|
||||
|
||||
describe('TriggerDialog', () => {
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
createPlugin,
|
||||
createRouteRef,
|
||||
discoveryApiRef,
|
||||
configApiRef,
|
||||
} from '@backstage/core';
|
||||
import { pagerDutyApiRef, PagerDutyClient } from './api';
|
||||
|
||||
@@ -31,11 +32,9 @@ export const plugin = createPlugin({
|
||||
apis: [
|
||||
createApiFactory({
|
||||
api: pagerDutyApiRef,
|
||||
deps: { discoveryApi: discoveryApiRef },
|
||||
factory: ({ discoveryApi }) =>
|
||||
new PagerDutyClient({
|
||||
discoveryApi: discoveryApi,
|
||||
}),
|
||||
deps: { discoveryApi: discoveryApiRef, configApi: configApiRef },
|
||||
factory: ({ configApi, discoveryApi }) =>
|
||||
PagerDutyClient.fromConfig(configApi, discoveryApi),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user