Skip to content

Commit

Permalink
Return Azure AD auth token in correct format (#15701)
Browse files Browse the repository at this point in the history
* Return Azure AD auth token in correct format

* changelog
  • Loading branch information
jmeunier28 committed Sep 18, 2023
1 parent e5d0cda commit b5ce877
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 6 additions & 0 deletions postgres/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

***Fixed***:

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

Check failure on line 7 in postgres/CHANGELOG.md

View workflow job for this annotation

GitHub Actions / run / Check PR

The first line of every new changelog entry must end with a link to the associated PR: ` ([#15858](https://github.com/DataDog/integrations-core/pull/15858))`

## 14.2.0 / 2023-08-18

***Added***:

* Add support for sending `database_instance` metadata ([#15559](https://github.com/DataDog/integrations-core/pull/15559))

Check failure on line 13 in postgres/CHANGELOG.md

View workflow job for this annotation

GitHub Actions / run / Check PR

The first line of every new changelog entry must end with a link to the associated PR: ` ([#15858](https://github.com/DataDog/integrations-core/pull/15858))`
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
2 changes: 1 addition & 1 deletion postgres/datadog_checks/postgres/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def _new_connection(self, dbname):
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)

args = {
'host': self._config.host,
Expand Down

0 comments on commit b5ce877

Please sign in to comment.