Skip to content

[PostgreSQL] Create azure-postgresql-auth package#45655

Draft
pvaneck wants to merge 4 commits intoAzure:mainfrom
pvaneck:postgresql-auth
Draft

[PostgreSQL] Create azure-postgresql-auth package#45655
pvaneck wants to merge 4 commits intoAzure:mainfrom
pvaneck:postgresql-auth

Conversation

@pvaneck
Copy link
Member

@pvaneck pvaneck commented Mar 12, 2026

This is a migration of the azure-postgresql-auth extension package to the Azure SDK for Python repo.

@pvaneck pvaneck force-pushed the postgresql-auth branch 2 times, most recently from d6fbc94 to 876c9e1 Compare March 12, 2026 08:41
@pvaneck
Copy link
Member Author

pvaneck commented Mar 13, 2026

/azp run prepare-pipelines

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pvaneck
Copy link
Member Author

pvaneck commented Mar 13, 2026

/azp run python - postgresql

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pvaneck
Copy link
Member Author

pvaneck commented Mar 13, 2026

/azp run python - postgresql - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the azure-postgresql-auth package into azure-sdk-for-python, adding the library source, tests, samples, docs, and the service-directory CI/test-resource wiring needed to run validation/live tests in this repo.

Changes:

  • Added azure-postgresql-auth package implementation (core token/claim handling + psycopg2/psycopg3/SQLAlchemy helpers).
  • Added unit/live tests and runnable samples for supported drivers.
  • Added sdk/postgresql CI and test-resources (Bicep + pre-deployment script) to enable live testing in the service directory.

Reviewed changes

Copilot reviewed 41 out of 42 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
sdk/postgresql/tests.yml Service-directory test pipeline entry targeting azure-postgresql-auth.
sdk/postgresql/test-resources.bicep Azure PostgreSQL Flexible Server test resource deployment.
sdk/postgresql/test-resources-pre.ps1 Pre-deployment parameter preparation for test resources (principal name/type).
sdk/postgresql/cspell.yaml Postgresql service-directory spell-check configuration.
sdk/postgresql/ci.yml Service-directory CI configuration for azure-postgresql-auth artifact.
sdk/postgresql/azure-postgresql-auth/tests/utils.py Test utilities and mock credentials for sync/async tests.
sdk/postgresql/azure-postgresql-auth/tests/test_sqlalchemy_async.py SQLAlchemy async unit/live tests.
sdk/postgresql/azure-postgresql-auth/tests/test_sqlalchemy.py SQLAlchemy sync unit/live tests.
sdk/postgresql/azure-postgresql-auth/tests/test_psycopg3_async.py psycopg3 async unit/live tests.
sdk/postgresql/azure-postgresql-auth/tests/test_psycopg3.py psycopg3 sync unit/live tests.
sdk/postgresql/azure-postgresql-auth/tests/test_psycopg2.py psycopg2 unit/live tests.
sdk/postgresql/azure-postgresql-auth/tests/test_core_async.py Async core auth tests.
sdk/postgresql/azure-postgresql-auth/tests/test_core.py Core auth tests (decode/claim parsing/scopes).
sdk/postgresql/azure-postgresql-auth/tests/conftest.py Live-test fixtures (credential + connection strings).
sdk/postgresql/azure-postgresql-auth/sdk_packaging.toml Packaging automation configuration.
sdk/postgresql/azure-postgresql-auth/samples/sample_sqlalchemy_connection.py SQLAlchemy sync/async sample.
sdk/postgresql/azure-postgresql-auth/samples/sample_psycopg3_connection.py psycopg3 sync/async sample.
sdk/postgresql/azure-postgresql-auth/samples/sample_psycopg2_connection.py psycopg2 sample.
sdk/postgresql/azure-postgresql-auth/samples/.env.example Sample environment template.
sdk/postgresql/azure-postgresql-auth/pyproject.toml Project metadata, deps/extras, and build configuration.
sdk/postgresql/azure-postgresql-auth/doc/azure_postgresql_auth.sqlalchemy.rst Sphinx stub for sqlalchemy module docs.
sdk/postgresql/azure-postgresql-auth/doc/azure_postgresql_auth.rst Sphinx root package doc and toctree.
sdk/postgresql/azure-postgresql-auth/doc/azure_postgresql_auth.psycopg3.rst Sphinx stub for psycopg3 module docs.
sdk/postgresql/azure-postgresql-auth/doc/azure_postgresql_auth.psycopg2.rst Sphinx stub for psycopg2 module docs.
sdk/postgresql/azure-postgresql-auth/dev_requirements.txt Dev/test requirements for local development.
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/sqlalchemy/entra_connection.py SQLAlchemy sync event hook for credential injection.
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/sqlalchemy/async_entra_connection.py SQLAlchemy async engine event hook (sync token fetch via sync_engine).
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/sqlalchemy/init.py Public exports for SQLAlchemy helpers.
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/psycopg3/entra_connection.py psycopg3 sync connection subclass enabling Entra auth.
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/psycopg3/async_entra_connection.py psycopg3 async connection subclass enabling Entra auth.
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/psycopg3/init.py Public exports for psycopg3 helpers.
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/psycopg2/entra_connection.py psycopg2 connection subclass enabling Entra auth.
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/psycopg2/init.py Public exports for psycopg2 helpers.
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/errors.py Package exception types.
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/core.py Core token acquisition, JWT decode, and username extraction logic.
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/_version.py Package version constant.
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/init.py Package init + __version__.
sdk/postgresql/azure-postgresql-auth/azure_postgresql_auth/py.typed Marks package as typed.
sdk/postgresql/azure-postgresql-auth/README.md Package readme (concepts, examples, troubleshooting).
sdk/postgresql/azure-postgresql-auth/MANIFEST.in Packaging manifest for tests/samples/docs/typing marker.
sdk/postgresql/azure-postgresql-auth/LICENSE MIT license file.
sdk/postgresql/azure-postgresql-auth/CHANGELOG.md Release history for the migrated package.

Comment on lines +115 to +120
xms_mirid = db_claims.get("xms_mirid")
username = (
parse_principal_name(xms_mirid)
if isinstance(xms_mirid, str)
else None or db_claims.get("upn") or db_claims.get("preferred_username") or db_claims.get("unique_name")
)
Comment on lines +41 to +45
# Create a synchronous engine
engine = create_engine(
f"postgresql+psycopg://{SERVER}/{DATABASE}",
connect_args={"credential": DefaultAzureCredential()},
)
Comment on lines +43 to +50
pool = ConnectionPool(
conninfo=f"postgresql://{SERVER}:5432/{DATABASE}",
min_size=1,
max_size=5,
open=False,
connection_class=EntraConnection,
kwargs={"credential": DefaultAzureCredential()},
)
The `get_entra_token_async` function should not use the credential as a
context manager. This will close the underlying transport in several
credential types. The lifecycle of the credential should be maanged by
the caller.

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants