Skip to content

Commit d38d765

Browse files
[DPE-8473] Handle invalid database name (databases) (#1190)
* Update lib to handle new invalid database name and to handle storage ownership and permissions Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com> * Update lib Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com> * Update lib Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com> * Update lib Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com> * Update lib Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com> * Update lib Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com> * Update lib Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com> --------- Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
1 parent 782292f commit d38d765

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

poetry.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/charm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
REWIND_USER,
6565
SYSTEM_USERS,
6666
USER,
67+
Substrates,
6768
)
6869
from single_kernel_postgresql.utils.postgresql import (
6970
ACCESS_GROUP_IDENTITY,
@@ -79,7 +80,6 @@
7980
PostgreSQLGrantDatabasePrivilegesToUserError,
8081
PostgreSQLListUsersError,
8182
PostgreSQLUpdateUserPasswordError,
82-
Substrates,
8383
)
8484
from tenacity import RetryError, Retrying, retry, stop_after_attempt, stop_after_delay, wait_fixed
8585

src/relations/postgresql_provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
ACCESS_GROUP_RELATION,
1818
ACCESS_GROUPS,
1919
INVALID_DATABASE_NAME_BLOCKING_MESSAGE,
20+
INVALID_DATABASE_NAMES,
2021
INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE,
2122
PostgreSQLBaseError,
2223
PostgreSQLCreateDatabaseError,
@@ -417,7 +418,7 @@ def check_for_invalid_database_name(self, relation_id: int) -> bool:
417418
for data in relation.data.values():
418419
database = data.get("database")
419420
if database is not None and (
420-
len(database) > 49 or database in ["postgres", "template0", "template1"]
421+
len(database) > 49 or database in INVALID_DATABASE_NAMES
421422
):
422423
return True
423424
return False

tests/integration/test_invalid_database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def test_database(juju: jubilant.Juju, predefined_roles) -> None:
6666
"""Check that an invalid database name makes the database charm block."""
6767
del predefined_roles[""]
6868
invalid_database_names = [
69+
"databases",
6970
"postgres",
7071
"template0",
7172
"template1",

0 commit comments

Comments
 (0)