-
Notifications
You must be signed in to change notification settings - Fork 20
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
[MISC] Merge update_tls_flag into update_endpoints #669
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,17 +108,6 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None: | |
# Set the database name | ||
self.database_provides.set_database(event.relation.id, database) | ||
|
||
# Set TLS flag | ||
self.database_provides.set_tls( | ||
event.relation.id, | ||
"True" if self.charm.is_tls_enabled else "False", | ||
) | ||
|
||
# Set TLS CA | ||
if self.charm.is_tls_enabled: | ||
_, ca, _ = self.charm.tls.get_tls_files() | ||
self.database_provides.set_tls_ca(event.relation.id, ca) | ||
|
||
Comment on lines
-111
to
-121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Endpoints will be updated anyway |
||
# Update the read/write and read-only endpoints. | ||
self.update_endpoints(event) | ||
|
||
|
@@ -201,6 +190,12 @@ def update_endpoints(self, event: DatabaseRequestedEvent = None) -> None: | |
else "" | ||
) | ||
|
||
tls = "True" if self.charm.is_tls_enabled else "False" | ||
if tls == "True": | ||
_, ca, _ = self.charm.tls.get_tls_files() | ||
else: | ||
ca = "" | ||
|
||
for relation_id in rel_data: | ||
user = f"relation-{relation_id}" | ||
database = rel_data[relation_id].get("database") | ||
|
@@ -226,17 +221,8 @@ def update_endpoints(self, event: DatabaseRequestedEvent = None) -> None: | |
f"postgresql://{user}:{password}@{self.charm.primary_endpoint}:{DATABASE_PORT}/{database}", | ||
) | ||
|
||
def update_tls_flag(self, tls: str) -> None: | ||
"""Update TLS flag and CA in relation databag.""" | ||
relations = self.model.relations[self.relation_name] | ||
if tls == "True": | ||
_, ca, _ = self.charm.tls.get_tls_files() | ||
else: | ||
ca = "" | ||
|
||
for relation in relations: | ||
self.database_provides.set_tls(relation.id, tls) | ||
self.database_provides.set_tls_ca(relation.id, ca) | ||
self.database_provides.set_tls(relation_id, tls) | ||
self.database_provides.set_tls_ca(relation_id, ca) | ||
|
||
def _check_multiple_endpoints(self) -> bool: | ||
"""Checks if there are relations with other endpoints.""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,6 @@ def test_on_database_requested(harness): | |
"password": "test-password", | ||
"version": POSTGRESQL_VERSION, | ||
"database": f"{DATABASE}", | ||
"tls": "False", | ||
} | ||
|
||
# Assert no BlockedStatus was set. | ||
|
@@ -154,7 +153,6 @@ def test_on_database_requested(harness): | |
# No data is set in the databag by the database. | ||
assert harness.get_relation_data(rel_id, harness.charm.app.name) == { | ||
"data": f'{{"database": "{DATABASE}", "extra-user-roles": "{EXTRA_USER_ROLES}"}}', | ||
"tls": "False", | ||
} | ||
|
||
# BlockedStatus due to a PostgreSQLCreateDatabaseError. | ||
|
@@ -163,7 +161,6 @@ def test_on_database_requested(harness): | |
# No data is set in the databag by the database. | ||
assert harness.get_relation_data(rel_id, harness.charm.app.name) == { | ||
"data": f'{{"database": "{DATABASE}", "extra-user-roles": "{EXTRA_USER_ROLES}"}}', | ||
"tls": "False", | ||
} | ||
|
||
# BlockedStatus due to a PostgreSQLGetPostgreSQLVersionError. | ||
|
@@ -256,6 +253,7 @@ def test_update_endpoints_with_event(harness): | |
"endpoints": "1.1.1.1:5432", | ||
"read-only-endpoints": "2.2.2.2:5432", | ||
"uris": "postgresql://relation-2:[email protected]:5432/test_db", | ||
"tls": "False", | ||
} | ||
assert harness.get_relation_data(another_rel_id, harness.charm.app.name) == {} | ||
_fetch_my_relation_data.assert_called_once_with([2], ["password"]) | ||
|
@@ -265,6 +263,7 @@ def test_update_endpoints_with_event(harness): | |
assert harness.get_relation_data(rel_id, harness.charm.app.name) == { | ||
"endpoints": "1.1.1.1:5432", | ||
"uris": "postgresql://relation-2:[email protected]:5432/test_db", | ||
"tls": "False", | ||
} | ||
assert harness.get_relation_data(another_rel_id, harness.charm.app.name) == {} | ||
|
||
|
@@ -331,11 +330,13 @@ def test_update_endpoints_without_event(harness): | |
"endpoints": "1.1.1.1:5432", | ||
"read-only-endpoints": "2.2.2.2:5432", | ||
"uris": "postgresql://relation-2:[email protected]:5432/test_db", | ||
"tls": "False", | ||
} | ||
assert harness.get_relation_data(another_rel_id, harness.charm.app.name) == { | ||
"endpoints": "1.1.1.1:5432", | ||
"read-only-endpoints": "2.2.2.2:5432", | ||
"uris": "postgresql://relation-3:[email protected]:5432/test_db2", | ||
"tls": "False", | ||
} | ||
_fetch_my_relation_data.assert_called_once_with(None, ["password"]) | ||
|
||
|
@@ -344,8 +345,10 @@ def test_update_endpoints_without_event(harness): | |
assert harness.get_relation_data(rel_id, harness.charm.app.name) == { | ||
"endpoints": "1.1.1.1:5432", | ||
"uris": "postgresql://relation-2:[email protected]:5432/test_db", | ||
"tls": "False", | ||
} | ||
assert harness.get_relation_data(another_rel_id, harness.charm.app.name) == { | ||
"endpoints": "1.1.1.1:5432", | ||
"uris": "postgresql://relation-3:[email protected]:5432/test_db2", | ||
"tls": "False", | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seen fail on ci: