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

[DPE-2278] Add libpq URI connection string to uri field in relation #527

Merged
merged 2 commits into from
Jul 15, 2024
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
6 changes: 6 additions & 0 deletions src/relations/postgresql_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None:
# Set the database name
self.database_provides.set_database(event.relation.id, database)

# Set connection string URI.
self.database_provides.set_uris(
event.relation.id,
f"postgresql://{user}:{password}@{self.charm.primary_endpoint}:{DATABASE_PORT}/{database}",
)

self._update_unit_status(event.relation)
except (
PostgreSQLCreateDatabaseError,
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/test_postgresql_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def request_database(_harness):
_harness.update_relation_data(
rel_id,
_harness.charm.app.name,
{"data": "", "username": "", "password": "", "version": "", "database": ""},
{"data": "", "username": "", "password": "", "uris": "", "version": "", "database": ""},
)

# Simulate the request of a new database plus extra user roles.
Expand Down Expand Up @@ -94,10 +94,11 @@ def test_on_database_requested(harness):
_member_started.side_effect = [False, True, True, True, True, True]
_primary_endpoint.side_effect = [
None,
{"1.1.1.1"},
{"1.1.1.1"},
{"1.1.1.1"},
{"1.1.1.1"},
"1.1.1.1",
"1.1.1.1",
"1.1.1.1",
"1.1.1.1",
"1.1.1.1",
]
postgresql_mock.create_user = PropertyMock(
side_effect=[None, PostgreSQLCreateUserError, None, None]
Expand Down Expand Up @@ -141,6 +142,7 @@ def test_on_database_requested(harness):
"data": f'{{"database": "{DATABASE}", "extra-user-roles": "{EXTRA_USER_ROLES}"}}',
"username": user,
"password": "test-password",
"uris": f"postgresql://{user}:[email protected]:5432/{DATABASE}",
"version": POSTGRESQL_VERSION,
"database": f"{DATABASE}",
}
Expand Down
Loading