Skip to content

Commit

Permalink
[Core] Added warning for personal credentials (#1200)
Browse files Browse the repository at this point in the history
# Description

What - Added warning log

Why - To make sure we indicate that using personal tokens will lead to
unwanted behaviors, including logs not being shown in the UI

How - Added log

## Type of change

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

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] 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)
- [x] 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

- [x] Integration able to create all default resources from scratch
- [x] Resync finishes successfully
- [x] 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

- [ ] Integration able to create all default resources from scratch
- [ ] Resync able to create entities
- [ ] Resync able to update entities
- [ ] Resync able to detect and delete entities
- [ ] 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
matan84 authored Dec 4, 2024
1 parent 585cdab commit 3e3103d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

## 0.14.6 (2024-12-04)


### Improvements

- Added a warning log for cases where the Integrations are provided with a personal token and not with machine credentials.

## 0.14.5 (2024-12-03)


Expand Down
12 changes: 11 additions & 1 deletion port_ocean/clients/port/authentication.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Any

import httpx
Expand Down Expand Up @@ -46,7 +47,11 @@ def __init__(

async def _get_token(self, client_id: str, client_secret: str) -> TokenResponse:
logger.info(f"Fetching access token for clientId: {client_id}")

if self._is_personal_token(client_id):
logger.warning(
"Integration is using personal credentials, make sure to use machine credentials. "
"Usage of personal credentials might impose unexpected integration behavior."
)
credentials = {"clientId": client_id, "clientSecret": client_secret}
response = await self.client.post(
f"{self.api_url}/auth/access_token",
Expand Down Expand Up @@ -82,3 +87,8 @@ async def token(self) -> str:
self.client_id, self.client_secret
)
return self.last_token_object.full_token

@staticmethod
def _is_personal_token(client_id: str) -> bool:
email_regex = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
return re.match(email_regex, client_id) is not None
2 changes: 1 addition & 1 deletion port_ocean/tests/log/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_serialize_record_exc_info_group_exception() -> None:

def assert_extra(extra: dict[str, Any]) -> str:
exc_info = extra.get("exc_info", None)
assert type(exc_info) is str
assert isinstance(exc_info, str)
return exc_info


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "port-ocean"
version = "0.14.5"
version = "0.14.6"
description = "Port Ocean is a CLI tool for managing your Port projects."
readme = "README.md"
homepage = "https://app.getport.io"
Expand Down

0 comments on commit 3e3103d

Please sign in to comment.