Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Integration][Pagerduty] Port 12076 pagerduty oauth support #1274

Merged
merged 5 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions integrations/pagerduty/.port/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,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"'
9 changes: 9 additions & 0 deletions integrations/pagerduty/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- towncrier release notes start -->

## 0.2.0 (2024-12-30)


### Improvements

- Added support for OAuth2.0 token
- Added OAuth installation specification for Port


## 0.1.132 (2026-12-30)


Expand Down
23 changes: 15 additions & 8 deletions integrations/pagerduty/clients/pagerduty.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

MAX_CONCURRENT_REQUESTS = 10
PAGE_SIZE = 100
OAUTH_TOKEN_PREFIX = "pd"


class PagerDutyClient:
Expand All @@ -20,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
Expand Down Expand Up @@ -63,13 +64,19 @@ def all_events(self) -> list[str]:
)

@property
def api_auth_param(self) -> dict[str, Any]:
return {
"headers": {
"Authorization": f"Token token={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
Expand Down
2 changes: 1 addition & 1 deletion integrations/pagerduty/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pagerduty"
version = "0.1.132"
version = "0.2.0"
description = "PagerDuty Integration"
authors = ["Port Team <support@getport.io>"]

Expand Down
Loading