Skip to content

Commit

Permalink
[Integration][Pagerduty] Port 12076 pagerduty oauth support (#1274)
Browse files Browse the repository at this point in the history
# Description

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

## Type of change

Please leave one option from the following and delete the rest:

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] New Integration (non-breaking change which adds a new integration)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Non-breaking change (fix of existing functionality that will not
change current behavior)
- [ ] Documentation (added/updated documentation)

<h4> All tests should be run against the port production
environment(using a testing org). </h4>

### Core testing checklist

- [ ] Integration able to create all default resources from scratch
- [ ] Resync finishes successfully
- [ ] Resync able to create entities
- [ ] Resync able to update entities
- [ ] Resync able to detect and delete entities
- [ ] Scheduled resync able to abort existing resync and start a new one
- [ ] Tested with at least 2 integrations from scratch
- [ ] Tested with Kafka and Polling event listeners
- [ ] Tested deletion of entities that don't pass the selector


### Integration testing checklist

- [x] Integration able to create all default resources from scratch
- [x] Resync able to create entities
- [x] Resync able to update entities
- [x] Resync able to detect and delete entities
- [x] Resync finishes successfully
- [ ] If new resource kind is added or updated in the integration, add
example raw data, mapping and expected result to the `examples` folder
in the integration directory.
- [ ] If resource kind is updated, run the integration with the example
data and check if the expected result is achieved
- [ ] If new resource kind is added or updated, validate that
live-events for that resource are working as expected
- [ ] Docs PR link [here](#)

### Preflight checklist

- [ ] Handled rate limiting
- [ ] Handled pagination
- [ ] Implemented the code in async
- [ ] Support Multi account

## Screenshots

Include screenshots from your environment showing how the resources of
the integration will look.

## API Documentation

Provide links to the API documentation used for this integration.
  • Loading branch information
omby8888 authored Dec 30, 2024
1 parent 904f3c2 commit 9f487f8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
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

0 comments on commit 9f487f8

Please sign in to comment.