From 55b302b6ade60307771f8079a39d7a8dace9f05c Mon Sep 17 00:00:00 2001 From: javierdelapuente Date: Thu, 3 Oct 2024 10:37:42 +0200 Subject: [PATCH] Remove prefix from integrations for Go and FastAPI (#53) --- examples/fastapi/app.py | 2 +- examples/go/main.go | 2 +- examples/go/migrate.sh | 2 +- paas_app_charmer/_gunicorn/wsgi_app.py | 1 - paas_app_charmer/app.py | 2 +- tests/unit/fastapi/test_charm.py | 24 ++++++++-------- tests/unit/go/test_app.py | 40 +++++++++++++------------- 7 files changed, 36 insertions(+), 37 deletions(-) diff --git a/examples/fastapi/app.py b/examples/fastapi/app.py index 48cd16a..5f46f85 100644 --- a/examples/fastapi/app.py +++ b/examples/fastapi/app.py @@ -9,7 +9,7 @@ app = FastAPI() -engine = create_engine(os.environ["APP_POSTGRESQL_DB_CONNECT_STRING"], echo=True) +engine = create_engine(os.environ["POSTGRESQL_DB_CONNECT_STRING"], echo=True) Session = scoped_session(sessionmaker(bind=engine)) diff --git a/examples/go/main.go b/examples/go/main.go index 87395be..4c751c1 100644 --- a/examples/go/main.go +++ b/examples/go/main.go @@ -77,7 +77,7 @@ func main() { Name: "request_count", Help: "No of request handled", }) - postgresqlURL := os.Getenv("APP_POSTGRESQL_DB_CONNECT_STRING") + postgresqlURL := os.Getenv("POSTGRESQL_DB_CONNECT_STRING") mux := http.NewServeMux() mainHandler := mainHandler{ diff --git a/examples/go/migrate.sh b/examples/go/migrate.sh index ee8a986..5a0f850 100755 --- a/examples/go/migrate.sh +++ b/examples/go/migrate.sh @@ -2,4 +2,4 @@ # Copyright 2024 Canonical Ltd. # See LICENSE file for licensing details. -PGPASSWORD="${APP_POSTGRESQL_DB_PASSWORD}" psql -h "${APP_POSTGRESQL_DB_HOSTNAME}" -U "${APP_POSTGRESQL_DB_USERNAME}" "${APP_POSTGRESQL_DB_NAME}" -c "CREATE TABLE IF NOT EXISTS USERS(NAME CHAR(50));" +PGPASSWORD="${POSTGRESQL_DB_PASSWORD}" psql -h "${POSTGRESQL_DB_HOSTNAME}" -U "${POSTGRESQL_DB_USERNAME}" "${POSTGRESQL_DB_NAME}" -c "CREATE TABLE IF NOT EXISTS USERS(NAME CHAR(50));" diff --git a/paas_app_charmer/_gunicorn/wsgi_app.py b/paas_app_charmer/_gunicorn/wsgi_app.py index 05dfe90..924bee3 100644 --- a/paas_app_charmer/_gunicorn/wsgi_app.py +++ b/paas_app_charmer/_gunicorn/wsgi_app.py @@ -43,7 +43,6 @@ def __init__( # pylint: disable=too-many-arguments database_migration=database_migration, configuration_prefix=f"{workload_config.framework.upper()}_", framework_config_prefix=f"{workload_config.framework.upper()}_", - integrations_prefix="", ) self._webserver = webserver diff --git a/paas_app_charmer/app.py b/paas_app_charmer/app.py index f13181e..707f8a9 100644 --- a/paas_app_charmer/app.py +++ b/paas_app_charmer/app.py @@ -79,7 +79,7 @@ def __init__( # pylint: disable=too-many-arguments database_migration: DatabaseMigration, framework_config_prefix: str = "APP_", configuration_prefix: str = "APP_", - integrations_prefix: str = "APP_", + integrations_prefix: str = "", ): """Construct the App instance. diff --git a/tests/unit/fastapi/test_charm.py b/tests/unit/fastapi/test_charm.py index f20aa8b..bae427c 100644 --- a/tests/unit/fastapi/test_charm.py +++ b/tests/unit/fastapi/test_charm.py @@ -54,18 +54,18 @@ "METRICS_PATH": "/othermetrics", "APP_SECRET_KEY": "foobar", "APP_USER_DEFINED_CONFIG": "userdefined", - "APP_POSTGRESQL_DB_CONNECT_STRING": "postgresql://test-username:test-password@test-postgresql:5432/test-database", - "APP_POSTGRESQL_DB_FRAGMENT": "", - "APP_POSTGRESQL_DB_HOSTNAME": "test-postgresql", - "APP_POSTGRESQL_DB_NAME": "test-database", - "APP_POSTGRESQL_DB_NETLOC": "test-username:test-password@test-postgresql:5432", - "APP_POSTGRESQL_DB_PARAMS": "", - "APP_POSTGRESQL_DB_PASSWORD": "test-password", - "APP_POSTGRESQL_DB_PATH": "/test-database", - "APP_POSTGRESQL_DB_PORT": "5432", - "APP_POSTGRESQL_DB_QUERY": "", - "APP_POSTGRESQL_DB_SCHEME": "postgresql", - "APP_POSTGRESQL_DB_USERNAME": "test-username", + "POSTGRESQL_DB_CONNECT_STRING": "postgresql://test-username:test-password@test-postgresql:5432/test-database", + "POSTGRESQL_DB_FRAGMENT": "", + "POSTGRESQL_DB_HOSTNAME": "test-postgresql", + "POSTGRESQL_DB_NAME": "test-database", + "POSTGRESQL_DB_NETLOC": "test-username:test-password@test-postgresql:5432", + "POSTGRESQL_DB_PARAMS": "", + "POSTGRESQL_DB_PASSWORD": "test-password", + "POSTGRESQL_DB_PATH": "/test-database", + "POSTGRESQL_DB_PORT": "5432", + "POSTGRESQL_DB_QUERY": "", + "POSTGRESQL_DB_SCHEME": "postgresql", + "POSTGRESQL_DB_USERNAME": "test-username", }, id="custom config", ), diff --git a/tests/unit/go/test_app.py b/tests/unit/go/test_app.py index faaabf8..70c0e82 100644 --- a/tests/unit/go/test_app.py +++ b/tests/unit/go/test_app.py @@ -45,26 +45,26 @@ "APP_BASE_URL": "https://paas.example.com", "HTTP_PROXY": "http://proxy.test", "http_proxy": "http://proxy.test", - "APP_REDIS_DB_CONNECT_STRING": "redis://10.1.88.132:6379", - "APP_REDIS_DB_FRAGMENT": "", - "APP_REDIS_DB_HOSTNAME": "10.1.88.132", - "APP_REDIS_DB_NETLOC": "10.1.88.132:6379", - "APP_REDIS_DB_PARAMS": "", - "APP_REDIS_DB_PATH": "", - "APP_REDIS_DB_PORT": "6379", - "APP_REDIS_DB_QUERY": "", - "APP_REDIS_DB_SCHEME": "redis", - "APP_RABBITMQ_HOSTNAME": "rabbitmq.example.com", - "APP_RABBITMQ_PASSWORD": "test-password", - "APP_RABBITMQ_USERNAME": "go-app", - "APP_RABBITMQ_VHOST": "/", - "APP_RABBITMQ_CONNECT_STRING": "amqp://go-app:test-password@rabbitmq.example.com/%2f", - "APP_RABBITMQ_FRAGMENT": "", - "APP_RABBITMQ_NETLOC": "go-app:test-password@rabbitmq.example.com", - "APP_RABBITMQ_PARAMS": "", - "APP_RABBITMQ_PATH": "/%2f", - "APP_RABBITMQ_QUERY": "", - "APP_RABBITMQ_SCHEME": "amqp", + "REDIS_DB_CONNECT_STRING": "redis://10.1.88.132:6379", + "REDIS_DB_FRAGMENT": "", + "REDIS_DB_HOSTNAME": "10.1.88.132", + "REDIS_DB_NETLOC": "10.1.88.132:6379", + "REDIS_DB_PARAMS": "", + "REDIS_DB_PATH": "", + "REDIS_DB_PORT": "6379", + "REDIS_DB_QUERY": "", + "REDIS_DB_SCHEME": "redis", + "RABBITMQ_HOSTNAME": "rabbitmq.example.com", + "RABBITMQ_PASSWORD": "test-password", + "RABBITMQ_USERNAME": "go-app", + "RABBITMQ_VHOST": "/", + "RABBITMQ_CONNECT_STRING": "amqp://go-app:test-password@rabbitmq.example.com/%2f", + "RABBITMQ_FRAGMENT": "", + "RABBITMQ_NETLOC": "go-app:test-password@rabbitmq.example.com", + "RABBITMQ_PARAMS": "", + "RABBITMQ_PATH": "/%2f", + "RABBITMQ_QUERY": "", + "RABBITMQ_SCHEME": "amqp", }, ), ],