Skip to content

Commit

Permalink
fix: Escape special characters in the Postgres password (feast-dev#4394)
Browse files Browse the repository at this point in the history
* Apply fix

Signed-off-by: Job Almekinders <job.almekinders@teampicnic.com>

* Add special characters to postgres online store test

Signed-off-by: Job Almekinders <job.almekinders@teampicnic.com>

* Fix linting error

Signed-off-by: Job Almekinders <job.almekinders@teampicnic.com>

---------

Signed-off-by: Job Almekinders <job.almekinders@teampicnic.com>
  • Loading branch information
job-almekinders authored Aug 8, 2024
1 parent 3a32e8a commit 419ca5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions sdk/python/feast/infra/utils/postgres/connection_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import psycopg
import pyarrow as pa
from psycopg import AsyncConnection, Connection
from psycopg.conninfo import make_conninfo
from psycopg_pool import AsyncConnectionPool, ConnectionPool

from feast.infra.utils.postgres.postgres_config import PostgreSQLConfig
Expand Down Expand Up @@ -55,13 +56,14 @@ async def _get_connection_pool_async(config: PostgreSQLConfig) -> AsyncConnectio

def _get_conninfo(config: PostgreSQLConfig) -> str:
"""Get the `conninfo` argument required for connection objects."""
return (
f"postgresql://{config.user}"
f":{config.password}"
f"@{config.host}"
f":{int(config.port)}"
f"/{config.database}"
)
psycopg_config = {
"user": config.user,
"password": config.password,
"host": config.host,
"port": int(config.port),
"dbname": config.database,
}
return make_conninfo(conninfo="", **psycopg_config)


def _get_conn_kwargs(config: PostgreSQLConfig) -> Dict[str, Any]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, project_name: str, **kwargs):
self.container = PostgresContainer(
"postgres:16",
username="root",
password="test",
password="test!@#$%",
dbname="test",
).with_exposed_ports(5432)

Expand All @@ -26,7 +26,7 @@ def create_online_store(self) -> Dict[str, str]:
"host": "localhost",
"type": "postgres",
"user": "root",
"password": "test",
"password": "test!@#$%",
"database": "test",
"port": self.container.get_exposed_port(5432),
}
Expand All @@ -42,7 +42,7 @@ def __init__(self, project_name: str, **kwargs):
self.container = (
DockerContainer("pgvector/pgvector:pg16")
.with_env("POSTGRES_USER", "root")
.with_env("POSTGRES_PASSWORD", "test")
.with_env("POSTGRES_PASSWORD", "test!@#$%")
.with_env("POSTGRES_DB", "test")
.with_exposed_ports(5432)
.with_volume_mapping(
Expand All @@ -65,7 +65,7 @@ def create_online_store(self) -> Dict[str, Any]:
"host": "localhost",
"type": "postgres",
"user": "root",
"password": "test",
"password": "test!@#$%",
"database": "test",
"pgvector_enabled": True,
"vector_len": 2,
Expand Down

0 comments on commit 419ca5e

Please sign in to comment.