Skip to content

Commit cb2b703

Browse files
[DPE-7510] Fix the auth username pattern (#987)
* Fix auth username pattern Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Fix unit test Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Fix another ocurrence of the pattern Signed-off-by: Marcelo Henrique Neppel <[email protected]> --------- Signed-off-by: Marcelo Henrique Neppel <[email protected]>
1 parent b1ab3cf commit cb2b703

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/charms/postgresql_k8s/v0/postgresql.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# Increment this PATCH version before using `charmcraft publish-lib` or reset
3737
# to 0 if you are raising the major API version
38-
LIBPATCH = 54
38+
LIBPATCH = 55
3939

4040
# Groups to distinguish HBA access
4141
ACCESS_GROUP_IDENTITY = "identity_access"
@@ -751,7 +751,7 @@ def list_users_from_relation(self, current_host=False) -> Set[str]:
751751
"SELECT usename "
752752
"FROM pg_catalog.pg_user "
753753
"WHERE usename LIKE 'relation_id_%' OR usename LIKE 'relation-%' "
754-
"OR usename LIKE 'pgbouncer_auth_relation_id_%' OR usename LIKE '%_user_%_%';"
754+
"OR usename LIKE 'pgbouncer_auth_relation_%' OR usename LIKE '%_user_%_%';"
755755
)
756756
usernames = cursor.fetchall()
757757
return {username[0] for username in usernames}
@@ -830,7 +830,7 @@ def set_up_database(self) -> None:
830830
END IF;
831831
END LOOP;
832832
-- Remove users that don't exist anymore from the pg_hba file.
833-
FOR rec IN SELECT h.lines FROM pg_hba AS h LEFT JOIN relation_users AS r ON SPLIT_PART(h.lines, ' ', 3) = r.user WHERE r.user IS NULL AND (SPLIT_PART(h.lines, ' ', 3) LIKE 'relation_id_%' OR SPLIT_PART(h.lines, ' ', 3) LIKE 'pgbouncer_auth_relation_id_%' OR SPLIT_PART(h.lines, ' ', 3) LIKE '%_user_%_%')
833+
FOR rec IN SELECT h.lines FROM pg_hba AS h LEFT JOIN relation_users AS r ON SPLIT_PART(h.lines, ' ', 3) = r.user WHERE r.user IS NULL AND (SPLIT_PART(h.lines, ' ', 3) LIKE 'relation_id_%' OR SPLIT_PART(h.lines, ' ', 3) LIKE 'pgbouncer_auth_relation_%' OR SPLIT_PART(h.lines, ' ', 3) LIKE '%_user_%_%')
834834
LOOP
835835
DELETE FROM pg_hba WHERE lines = rec.lines;
836836
changes := changes + 1;

tests/unit/test_postgresql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def test_grant_relation_access_group_memberships(harness):
227227
"SELECT usename "
228228
"FROM pg_catalog.pg_user "
229229
"WHERE usename LIKE 'relation_id_%' OR usename LIKE 'relation-%' "
230-
"OR usename LIKE 'pgbouncer_auth_relation_id_%' OR usename LIKE '%_user_%_%';"
230+
"OR usename LIKE 'pgbouncer_auth_relation_%' OR usename LIKE '%_user_%_%';"
231231
),
232232
])
233233

0 commit comments

Comments
 (0)