add env file

This commit is contained in:
2025-03-21 16:18:40 -03:00
parent d21144e045
commit 9d7ff8abf1
9 changed files with 28 additions and 31 deletions

7
http-api/.env Normal file
View File

@@ -0,0 +1,7 @@
# If it does not load this file, try running `export UV_ENV_FILE=.env`
# See more details at https://docs.astral.sh/uv/configuration/files/#env
ELASTIC_HOSTS=http://127.0.0.1:9200
DYNAMODB_ENDPOINT_URL=http://127.0.0.1:8000
DYNAMODB_PARTITION_KEY=id
DYNAMODB_SORT_KEY=sk

View File

@@ -50,3 +50,9 @@ def exc_error(exc: ServiceError):
@tracer.capture_lambda_handler
def lambda_handler(event: dict, context: LambdaContext) -> dict:
return app.resolve(event, context)
if __name__ == '__main__':
print(
app.get_openapi_json_schema(),
)

View File

@@ -20,15 +20,15 @@ def search(
page_size: int = 25,
elastic_client: Elasticsearch,
) -> PaginatedResult:
if page_size > MAX_PAGE_SIZE:
page_size = MAX_PAGE_SIZE
s = Search(
using=elastic_client,
index=index,
)
s.update_from_dict(query)
if page_size > MAX_PAGE_SIZE:
page_size = MAX_PAGE_SIZE
s.extra(size=page_size)
s.extra(size=page_size)
try:
r = s.execute()

View File

@@ -10,7 +10,6 @@ dependencies = ["layercake"]
dev = [
"pytest>=8.3.4",
"pytest-cov>=6.0.0",
"pytest-env>=1.1.5",
"ruff>=0.9.1",
]

View File

@@ -1,5 +0,0 @@
[pytest]
env =
DYNAMODB_ENDPOINT_URL=http://127.0.0.1:8000
DYNAMODB_PARTITION_KEY=id
DYNAMODB_SORT_KEY=sk

View File

@@ -19,7 +19,7 @@ def get_courses():
query = event.get_query_string_value('query', '{}')
page_size = event.get_query_string_value('page_size', '25')
return elastic.search( # type: ignore
return elastic.search(
index=COURSE_TABLE,
page_size=int(page_size),
query=json.loads(query),

View File

@@ -7,7 +7,12 @@ COURSE_TABLE: str = os.getenv('COURSE_TABLE') # type: ignore
ELASTIC_CLOUD_ID = os.getenv('ELASTIC_CLOUD_ID')
ELASTIC_AUTH_PASS = os.getenv('ELASTIC_AUTH_PASS')
ELASTIC_CONN = {
'cloud_id': ELASTIC_CLOUD_ID,
'basic_auth': ('elastic', ELASTIC_AUTH_PASS),
}
ELASTIC_HOSTS = os.getenv('ELASTIC_HOSTS', None)
if ELASTIC_HOSTS:
ELASTIC_CONN = {'hosts': ELASTIC_HOSTS}
else:
ELASTIC_CONN = {
'cloud_id': ELASTIC_CLOUD_ID,
'basic_auth': ('elastic', ELASTIC_AUTH_PASS),
}

View File

@@ -132,8 +132,7 @@ def dynamodb_seeds(dynamodb_client):
@pytest.fixture
def mock_app(monkeypatch):
monkeypatch.setattr('settings.ELASTIC_CONN', {'hosts': 'http://127.0.0.1:9200'})
def mock_app():
import app
return app

14
http-api/uv.lock generated
View File

@@ -353,7 +353,6 @@ dependencies = [
dev = [
{ name = "pytest" },
{ name = "pytest-cov" },
{ name = "pytest-env" },
{ name = "ruff" },
]
@@ -364,7 +363,6 @@ requires-dist = [{ name = "layercake", directory = "../layercake" }]
dev = [
{ name = "pytest", specifier = ">=8.3.4" },
{ name = "pytest-cov", specifier = ">=6.0.0" },
{ name = "pytest-env", specifier = ">=1.1.5" },
{ name = "ruff", specifier = ">=0.9.1" },
]
@@ -641,18 +639,6 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/36/3b/48e79f2cd6a61dbbd4807b4ed46cb564b4fd50a76166b1c4ea5c1d9e2371/pytest_cov-6.0.0-py3-none-any.whl", hash = "sha256:eee6f1b9e61008bd34975a4d5bab25801eb31898b032dd55addc93e96fcaaa35", size = 22949 },
]
[[package]]
name = "pytest-env"
version = "1.1.5"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "pytest" },
]
sdist = { url = "https://files.pythonhosted.org/packages/1f/31/27f28431a16b83cab7a636dce59cf397517807d247caa38ee67d65e71ef8/pytest_env-1.1.5.tar.gz", hash = "sha256:91209840aa0e43385073ac464a554ad2947cc2fd663a9debf88d03b01e0cc1cf", size = 8911 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/de/b8/87cfb16045c9d4092cfcf526135d73b88101aac83bc1adcf82dfb5fd3833/pytest_env-1.1.5-py3-none-any.whl", hash = "sha256:ce90cf8772878515c24b31cd97c7fa1f4481cd68d588419fd45f10ecaee6bc30", size = 6141 },
]
[[package]]
name = "python-dateutil"
version = "2.9.0.post0"