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

Return Azure AD auth token in correct format #15701

Merged
merged 2 commits into from
Aug 29, 2023
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
4 changes: 4 additions & 0 deletions postgres/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

***Fixed***:

* Return Azure AD auth token in correct format ([#15701](https://github.com/DataDog/integrations-core/pull/15701))

## 14.2.0 / 2023-08-18

***Added***:
Expand Down
7 changes: 1 addition & 6 deletions postgres/datadog_checks/postgres/azure.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# (C) Datadog, Inc. 2023-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import struct

from azure.identity import ManagedIdentityCredential

DEFAULT_PERMISSION_SCOPE = "https://ossrdbms-aad.database.windows.net/.default"
TOKEN_ENCODING = "UTF-16-LE"


# Use the azure identity API to generate a token that will be used
Expand All @@ -15,7 +13,4 @@ def generate_managed_identity_token(client_id: str, identity_scope: str = None):
credential = ManagedIdentityCredential(client_id=client_id)
if not identity_scope:
identity_scope = DEFAULT_PERMISSION_SCOPE
token_bytes = credential.get_token(identity_scope).token.encode(TOKEN_ENCODING)
token_struct = struct.pack(f'<I{len(token_bytes)}s', len(token_bytes), token_bytes)

return token_struct
return credential.get_token(identity_scope).token
1 change: 0 additions & 1 deletion postgres/datadog_checks/postgres/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def __init__(self, check: AgentCheck, connect_fn: Callable[[str, int, int], None
self.max_conns: int = max_conns
self._stats = self.Stats()
self._mu = threading.RLock()
self._query_lock = threading.Lock()
self._conns: Dict[str, ConnectionInfo] = {}

if hasattr(inspect, 'signature'):
Expand Down
2 changes: 1 addition & 1 deletion postgres/datadog_checks/postgres/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def _new_connection(self, dbname: str, min_pool_size: int = 1, max_pool_size: in
client_id = self._config.managed_identity.get('client_id', None)
scope = self._config.managed_identity.get('identity_scope', None)
if client_id is not None:
password = azure.generate_managed_identity_token(client_id=client_id, scope=scope)
password = azure.generate_managed_identity_token(client_id=client_id, identity_scope=scope)

conn_args = {
'host': self._config.host,
Expand Down
Loading