From fa48fe97a3ef3996f0fa8f61c902d98d2fcf3a3d Mon Sep 17 00:00:00 2001 From: omribarouch Date: Mon, 30 Dec 2024 09:51:34 +0200 Subject: [PATCH 1/4] Added OAuth support for pagerduty --- integrations/pagerduty/.port/spec.yaml | 10 ++++++++++ integrations/pagerduty/CHANGELOG.md | 9 +++++++++ integrations/pagerduty/clients/pagerduty.py | 4 +++- integrations/pagerduty/pyproject.toml | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/integrations/pagerduty/.port/spec.yaml b/integrations/pagerduty/.port/spec.yaml index 8d2fac7ea0..bf6f5cc0b3 100644 --- a/integrations/pagerduty/.port/spec.yaml +++ b/integrations/pagerduty/.port/spec.yaml @@ -25,3 +25,13 @@ configurations: required: false type: string description: The host of the Port Ocean app. Used to set up the integration endpoint as the target for Webhooks created in PagerDuty +saas: + enabled: true + oauthConfiguration: + requiredSecrets: + - name: token + value: '.oauthData.accessToken' + description: '"Access Token for Pagerduty OAuth2 integration"' + valuesOverride: + integrationSpec: + appUrl: '"https://api.pagerduty.com"' diff --git a/integrations/pagerduty/CHANGELOG.md b/integrations/pagerduty/CHANGELOG.md index 55e6eaf218..0a13619b9a 100644 --- a/integrations/pagerduty/CHANGELOG.md +++ b/integrations/pagerduty/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +## 0.2.0 (2024-12-30) + + +### Improvements + +- Added support for OAuth2.0 token +- Added OAuth installation specification for Port + + ## 0.1.131 (2024-12-26) diff --git a/integrations/pagerduty/clients/pagerduty.py b/integrations/pagerduty/clients/pagerduty.py index 250d3d6fd7..fd9896a66d 100644 --- a/integrations/pagerduty/clients/pagerduty.py +++ b/integrations/pagerduty/clients/pagerduty.py @@ -12,6 +12,7 @@ MAX_CONCURRENT_REQUESTS = 10 PAGE_SIZE = 100 +OAUTH_TOKEN_PREFIX = 'pd' class PagerDutyClient: @@ -64,9 +65,10 @@ def all_events(self) -> list[str]: @property def api_auth_param(self) -> dict[str, Any]: + auth_prefix = "Bearer " if self.token.startswith(OAUTH_TOKEN_PREFIX) else f"Token token=" return { "headers": { - "Authorization": f"Token token={self.token}", + "Authorization": f"{auth_prefix}{self.token}", "Content-Type": "application/json", } } diff --git a/integrations/pagerduty/pyproject.toml b/integrations/pagerduty/pyproject.toml index a20d0d406e..22cab2109e 100644 --- a/integrations/pagerduty/pyproject.toml +++ b/integrations/pagerduty/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pagerduty" -version = "0.1.131" +version = "0.2.0" description = "Pagerduty Integration" authors = ["Port Team "] From 56516561258dae516c9839fdb42c7fbe3aff3917 Mon Sep 17 00:00:00 2001 From: omribarouch Date: Mon, 30 Dec 2024 10:02:56 +0200 Subject: [PATCH 2/4] lint fix --- integrations/pagerduty/clients/pagerduty.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/integrations/pagerduty/clients/pagerduty.py b/integrations/pagerduty/clients/pagerduty.py index fd9896a66d..9a5b53ef33 100644 --- a/integrations/pagerduty/clients/pagerduty.py +++ b/integrations/pagerduty/clients/pagerduty.py @@ -12,7 +12,7 @@ MAX_CONCURRENT_REQUESTS = 10 PAGE_SIZE = 100 -OAUTH_TOKEN_PREFIX = 'pd' +OAUTH_TOKEN_PREFIX = "pd" class PagerDutyClient: @@ -65,7 +65,9 @@ def all_events(self) -> list[str]: @property def api_auth_param(self) -> dict[str, Any]: - auth_prefix = "Bearer " if self.token.startswith(OAUTH_TOKEN_PREFIX) else f"Token token=" + auth_prefix = ( + "Bearer " if self.token.startswith(OAUTH_TOKEN_PREFIX) else "Token token=" + ) return { "headers": { "Authorization": f"{auth_prefix}{self.token}", From 0e83b40dfc67ea88ebbaf589274f0848fc0974fc Mon Sep 17 00:00:00 2001 From: omribarouch Date: Mon, 30 Dec 2024 10:15:19 +0200 Subject: [PATCH 3/4] added required header when using oauth token --- integrations/pagerduty/clients/pagerduty.py | 23 +++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/integrations/pagerduty/clients/pagerduty.py b/integrations/pagerduty/clients/pagerduty.py index 9a5b53ef33..c5ebd4c952 100644 --- a/integrations/pagerduty/clients/pagerduty.py +++ b/integrations/pagerduty/clients/pagerduty.py @@ -21,7 +21,7 @@ def __init__(self, token: str, api_url: str, app_host: str | None): self.api_url = api_url self.app_host = app_host self.http_client = http_async_client - self.http_client.headers.update(self.api_auth_param["headers"]) + self.http_client.headers.update(self.headers) self._semaphore = asyncio.Semaphore(MAX_CONCURRENT_REQUESTS) @property @@ -64,16 +64,17 @@ def all_events(self) -> list[str]: ) @property - def api_auth_param(self) -> dict[str, Any]: - auth_prefix = ( - "Bearer " if self.token.startswith(OAUTH_TOKEN_PREFIX) else "Token token=" - ) - return { - "headers": { - "Authorization": f"{auth_prefix}{self.token}", - "Content-Type": "application/json", - } - } + def headers(self) -> dict[str, Any]: + headers = {"Content-Type": "application/json"} + if self.token.startswith(OAUTH_TOKEN_PREFIX): + headers.update({ + "Authorization": f"Bearer {self.token}", + "Accept": "application/vnd.pagerduty+json;version=2", + }) + else: + headers["Authorization"] = f"Token token={self.token}" + + return headers async def paginate_request_to_pager_duty( self, resource: str, params: dict[str, Any] | None = None From 0deb68fbbc91553ccbb014e60c50d79e790f1e53 Mon Sep 17 00:00:00 2001 From: omribarouch Date: Mon, 30 Dec 2024 10:23:06 +0200 Subject: [PATCH 4/4] lint fix --- integrations/pagerduty/clients/pagerduty.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/integrations/pagerduty/clients/pagerduty.py b/integrations/pagerduty/clients/pagerduty.py index c5ebd4c952..70d30e702f 100644 --- a/integrations/pagerduty/clients/pagerduty.py +++ b/integrations/pagerduty/clients/pagerduty.py @@ -67,10 +67,12 @@ def all_events(self) -> list[str]: def headers(self) -> dict[str, Any]: headers = {"Content-Type": "application/json"} if self.token.startswith(OAUTH_TOKEN_PREFIX): - headers.update({ - "Authorization": f"Bearer {self.token}", - "Accept": "application/vnd.pagerduty+json;version=2", - }) + headers.update( + { + "Authorization": f"Bearer {self.token}", + "Accept": "application/vnd.pagerduty+json;version=2", + } + ) else: headers["Authorization"] = f"Token token={self.token}"