From c79913beec85259172b777956536492a79a01057 Mon Sep 17 00:00:00 2001 From: Mike Ball Date: Thu, 2 Feb 2023 09:21:28 -0500 Subject: [PATCH 1/5] enable 'readOnly' configuration for PagerDutyCard This exposes a `readOnly` configuration option for the `PagerDutyCard` to address issue #16147. Signed-off-by: Mike Ball --- plugins/pagerduty/README.md | 20 +++++++++++++++- .../components/PagerDutyCard/index.test.tsx | 23 +++++++++++++++++++ .../src/components/PagerDutyCard/index.tsx | 14 +++++++++-- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/plugins/pagerduty/README.md b/plugins/pagerduty/README.md index 7b3124ab0f..98f769e9f3 100644 --- a/plugins/pagerduty/README.md +++ b/plugins/pagerduty/README.md @@ -6,7 +6,7 @@ # How it Works - The Backstage PagerDuty plugin allows PagerDuty information about a Backstage entity to be displayed within Backstage. This includes active incidents, recent change events, as well as the current on-call responders' names, email addresses, and links to their profiles in PagerDuty. -- Incidents can be manually triggered via the plugin with a user-provided description, which will in turn notify the current on-call responders. +- Incidents can be manually triggered via the plugin with a user-provided description, which will in turn notify the current on-call responders (Alternatively, the plugin can be configured with an optional `readOnly` property to suppress the ability to trigger incidents from the plugin). - _Note: This feature is only available when providing the `pagerduty.com/integration-key` annotation_ - Change events will be displayed in a separate tab. If the change event payload has additional links the first link only will be rendered. @@ -145,6 +145,24 @@ pagerduty: eventsBaseUrl: 'https://events.pagerduty.com/v2' ``` +To suppress the rendering of the actionable incident-creation button, the `PagerDutyCard` can also be instantiated in `readOnly` mode: + +```ts + +``` + +**WARNING**: In current implementation, the PagerDuty plugin requires the `/pagerduty` proxy endpoint be exposed by the Backstage backend as an unprotected endpoint, in effect enabling PagerDuty API access using the configured `PAGERDUTY_TOKEN` for any user or process with access to the `/pagerduty` Backstage backend endpoint. If you regard this as problematic, consider using the plugin in `readOnly` mode (``) using the following proxy configuration: + +```yaml +proxy: + '/pagerduty': + target: https://api.pagerduty.com + headers: + Authorization: Token token=${PAGERDUTY_TOKEN} + # prohibit the `/pagerduty` proxy endpoint from servicing non-GET requests + allowedMethods: ['GET'] +``` + # How to Uninstall 1. Remove any configuration added in Backstage yaml files, such as the proxy configuration in `app-config.yaml` and the integration key in an entity's annotations. diff --git a/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx b/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx index 85202a9cfc..34c8914fde 100644 --- a/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx +++ b/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx @@ -356,4 +356,27 @@ describe('PageDutyCard', () => { expect(getByText('Empty escalation policy')).toBeInTheDocument(); }); }); + + describe('when entity has all annotations but the plugin has been configured to be "read only"', () => { + it('queries by integration key but does not render the "Create Incident" button', async () => { + mockPagerDutyApi.getServiceByEntity = jest + .fn() + .mockImplementationOnce(async () => ({ service })); + + const { getByText, queryByTestId } = render( + wrapInTestApp( + + + + + , + ), + ); + await waitFor(() => !queryByTestId('progress')); + expect(getByText('Service Directory')).toBeInTheDocument(); + expect(getByText('Nice! No incidents found!')).toBeInTheDocument(); + expect(getByText('Empty escalation policy')).toBeInTheDocument(); + expect(() => getByText('Create Incident')).toThrow(); + }); + }); }); diff --git a/plugins/pagerduty/src/components/PagerDutyCard/index.tsx b/plugins/pagerduty/src/components/PagerDutyCard/index.tsx index 15967fae01..fd23166d88 100644 --- a/plugins/pagerduty/src/components/PagerDutyCard/index.tsx +++ b/plugins/pagerduty/src/components/PagerDutyCard/index.tsx @@ -54,7 +54,13 @@ export const isPluginApplicableToEntity = (entity: Entity) => ); /** @public */ -export const PagerDutyCard = () => { +export type PagerDutyCardProps = { + readOnly?: boolean; +}; + +/** @public */ +export const PagerDutyCard = (props: PagerDutyCardProps) => { + const { readOnly } = props; const { entity } = useEntity(); const pagerDutyEntity = getPagerDutyEntity(entity); const api = useApi(pagerDutyApiRef); @@ -156,7 +162,11 @@ export const PagerDutyCard = () => { title="PagerDuty" subheader={ } /> From 804746dd58e7b7b0f1a0ee98068658f460d6f0db Mon Sep 17 00:00:00 2001 From: Mike Ball Date: Thu, 2 Feb 2023 09:27:34 -0500 Subject: [PATCH 2/5] add changeset noting PagerDutyCard `readOnly` prop Signed-off-by: Mike Ball --- .changeset/rich-bags-sleep.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rich-bags-sleep.md diff --git a/.changeset/rich-bags-sleep.md b/.changeset/rich-bags-sleep.md new file mode 100644 index 0000000000..68a7716ca1 --- /dev/null +++ b/.changeset/rich-bags-sleep.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-pagerduty': patch +--- + +The PagerDutyCard now supports an optional `readOnly` property (``) for the suppressing the rendering of the "Create Incident" button from the Backstage UI. From 3a0cf26a4a12af7e511c24e7d0886487303c8274 Mon Sep 17 00:00:00 2001 From: Mike Ball Date: Thu, 2 Feb 2023 12:31:14 -0500 Subject: [PATCH 3/5] add generated PagerDuty API report Signed-off-by: Mike Ball --- plugins/pagerduty/api-report.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/pagerduty/api-report.md b/plugins/pagerduty/api-report.md index 5bfe84e63f..2c8f9dea49 100644 --- a/plugins/pagerduty/api-report.md +++ b/plugins/pagerduty/api-report.md @@ -13,8 +13,10 @@ import { Entity } from '@backstage/catalog-model'; import { FetchApi } from '@backstage/core-plugin-api'; import { ReactNode } from 'react'; +// Warning: (ae-forgotten-export) The symbol "PagerDutyCardProps" needs to be exported by the entry point index.d.ts +// // @public (undocumented) -export const EntityPagerDutyCard: () => JSX.Element; +export const EntityPagerDutyCard: (props: PagerDutyCardProps) => JSX.Element; // @public (undocumented) const isPluginApplicableToEntity: (entity: Entity) => boolean; @@ -45,7 +47,7 @@ export type PagerDutyAssignee = { }; // @public (undocumented) -export const PagerDutyCard: () => JSX.Element; +export const PagerDutyCard: (props: PagerDutyCardProps) => JSX.Element; // @public (undocumented) export type PagerDutyChangeEvent = { From 960cbbc5d040c5bf2562de2f7325b49e1a09d748 Mon Sep 17 00:00:00 2001 From: Mike Ball Date: Thu, 2 Feb 2023 13:55:13 -0500 Subject: [PATCH 4/5] correct generated PagerDuty API report Signed-off-by: Mike Ball --- plugins/pagerduty/api-report.md | 7 +++++-- plugins/pagerduty/src/components/index.ts | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/pagerduty/api-report.md b/plugins/pagerduty/api-report.md index 2c8f9dea49..b460086976 100644 --- a/plugins/pagerduty/api-report.md +++ b/plugins/pagerduty/api-report.md @@ -13,8 +13,6 @@ import { Entity } from '@backstage/catalog-model'; import { FetchApi } from '@backstage/core-plugin-api'; import { ReactNode } from 'react'; -// Warning: (ae-forgotten-export) The symbol "PagerDutyCardProps" needs to be exported by the entry point index.d.ts -// // @public (undocumented) export const EntityPagerDutyCard: (props: PagerDutyCardProps) => JSX.Element; @@ -49,6 +47,11 @@ export type PagerDutyAssignee = { // @public (undocumented) export const PagerDutyCard: (props: PagerDutyCardProps) => JSX.Element; +// @public (undocumented) +export type PagerDutyCardProps = { + readOnly?: boolean; +}; + // @public (undocumented) export type PagerDutyChangeEvent = { id: string; diff --git a/plugins/pagerduty/src/components/index.ts b/plugins/pagerduty/src/components/index.ts index 17bb2c03dc..e7c1ff4e72 100644 --- a/plugins/pagerduty/src/components/index.ts +++ b/plugins/pagerduty/src/components/index.ts @@ -23,6 +23,8 @@ export type { PagerDutyUser, } from './types'; +export type { PagerDutyCardProps } from './PagerDutyCard'; + export { isPluginApplicableToEntity, isPluginApplicableToEntity as isPagerDutyAvailable, From 799fe4a97886684018bb34478072dd331fd3f9b5 Mon Sep 17 00:00:00 2001 From: Mike Ball Date: Thu, 2 Feb 2023 16:58:26 -0500 Subject: [PATCH 5/5] correct grammar typo in changeset Signed-off-by: Mike Ball --- .changeset/rich-bags-sleep.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/rich-bags-sleep.md b/.changeset/rich-bags-sleep.md index 68a7716ca1..14312ac7f4 100644 --- a/.changeset/rich-bags-sleep.md +++ b/.changeset/rich-bags-sleep.md @@ -2,4 +2,4 @@ '@backstage/plugin-pagerduty': patch --- -The PagerDutyCard now supports an optional `readOnly` property (``) for the suppressing the rendering of the "Create Incident" button from the Backstage UI. +The PagerDutyCard now supports an optional `readOnly` property (``) for suppressing the rendering of the "Create Incident" button from the Backstage UI.