Skip to content

Commit

Permalink
fix: support for password special characters, fixes #440 (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeeva authored Apr 8, 2024
1 parent 3b663ba commit 71b0f9d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions pgbelt/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pydantic import BaseModel
from pydantic import ValidationError
from pydantic import field_validator
from urllib.parse import quote


def config_dir(db: str, dc: str) -> str:
Expand Down Expand Up @@ -86,15 +87,24 @@ def pglogical_dsn(self) -> str:

@property
def root_uri(self) -> str:
return f"postgresql://{self.root_user.name}:{self.root_user.pw}@{self.ip}:{self.port}/{self.db}"
password = quote(
self.root_user.pw
) # https://github.com/encode/databases/issues/145#issuecomment-1303792343 need this to handle special characters
return f"postgresql://{self.root_user.name}:{password}@{self.ip}:{self.port}/{self.db}"

@property
def owner_uri(self) -> str:
return f"postgresql://{self.owner_user.name}:{self.owner_user.pw}@{self.ip}:{self.port}/{self.db}"
password = quote(
self.owner_user.pw
) # https://github.com/encode/databases/issues/145#issuecomment-1303792343 need this to handle special characters
return f"postgresql://{self.owner_user.name}:{password}@{self.ip}:{self.port}/{self.db}"

@property
def pglogical_uri(self) -> str:
return f"postgresql://{self.pglogical_user.name}:{self.pglogical_user.pw}@{self.ip}:{self.port}/{self.db}"
password = quote(
self.pglogical_user.pw
) # https://github.com/encode/databases/issues/145#issuecomment-1303792343 need this to handle special characters
return f"postgresql://{self.pglogical_user.name}:{password}@{self.ip}:{self.port}/{self.db}"


class DbupgradeConfig(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ async def _create_dbupgradeconfigs() -> dict[str, DbupgradeConfig]:
pw="postgres",
),
# We will create the owner_user in the DBs via the integration test setup.
"owner_user": User(name="owner", pw="ownerpassword"),
# Due to issue #440, we're adding a special character to the password to ensure this still works.
"owner_user": User(name="owner", pw="owner#password"),
"pglogical_user": User(name="pglogical", pw="pglogicalpassword"),
"db": "testdb",
}
Expand Down

0 comments on commit 71b0f9d

Please sign in to comment.