add env file
This commit is contained in:
7
http-api/.env
Normal file
7
http-api/.env
Normal 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
|
||||||
@@ -50,3 +50,9 @@ def exc_error(exc: ServiceError):
|
|||||||
@tracer.capture_lambda_handler
|
@tracer.capture_lambda_handler
|
||||||
def lambda_handler(event: dict, context: LambdaContext) -> dict:
|
def lambda_handler(event: dict, context: LambdaContext) -> dict:
|
||||||
return app.resolve(event, context)
|
return app.resolve(event, context)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print(
|
||||||
|
app.get_openapi_json_schema(),
|
||||||
|
)
|
||||||
|
|||||||
@@ -20,15 +20,15 @@ def search(
|
|||||||
page_size: int = 25,
|
page_size: int = 25,
|
||||||
elastic_client: Elasticsearch,
|
elastic_client: Elasticsearch,
|
||||||
) -> PaginatedResult:
|
) -> PaginatedResult:
|
||||||
|
if page_size > MAX_PAGE_SIZE:
|
||||||
|
page_size = MAX_PAGE_SIZE
|
||||||
|
|
||||||
s = Search(
|
s = Search(
|
||||||
using=elastic_client,
|
using=elastic_client,
|
||||||
index=index,
|
index=index,
|
||||||
)
|
)
|
||||||
s.update_from_dict(query)
|
s.update_from_dict(query)
|
||||||
|
s.extra(size=page_size)
|
||||||
if page_size > MAX_PAGE_SIZE:
|
|
||||||
page_size = MAX_PAGE_SIZE
|
|
||||||
s.extra(size=page_size)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = s.execute()
|
r = s.execute()
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ dependencies = ["layercake"]
|
|||||||
dev = [
|
dev = [
|
||||||
"pytest>=8.3.4",
|
"pytest>=8.3.4",
|
||||||
"pytest-cov>=6.0.0",
|
"pytest-cov>=6.0.0",
|
||||||
"pytest-env>=1.1.5",
|
|
||||||
"ruff>=0.9.1",
|
"ruff>=0.9.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
[pytest]
|
|
||||||
env =
|
|
||||||
DYNAMODB_ENDPOINT_URL=http://127.0.0.1:8000
|
|
||||||
DYNAMODB_PARTITION_KEY=id
|
|
||||||
DYNAMODB_SORT_KEY=sk
|
|
||||||
@@ -19,7 +19,7 @@ def get_courses():
|
|||||||
query = event.get_query_string_value('query', '{}')
|
query = event.get_query_string_value('query', '{}')
|
||||||
page_size = event.get_query_string_value('page_size', '25')
|
page_size = event.get_query_string_value('page_size', '25')
|
||||||
|
|
||||||
return elastic.search( # type: ignore
|
return elastic.search(
|
||||||
index=COURSE_TABLE,
|
index=COURSE_TABLE,
|
||||||
page_size=int(page_size),
|
page_size=int(page_size),
|
||||||
query=json.loads(query),
|
query=json.loads(query),
|
||||||
|
|||||||
@@ -7,7 +7,12 @@ COURSE_TABLE: str = os.getenv('COURSE_TABLE') # type: ignore
|
|||||||
|
|
||||||
ELASTIC_CLOUD_ID = os.getenv('ELASTIC_CLOUD_ID')
|
ELASTIC_CLOUD_ID = os.getenv('ELASTIC_CLOUD_ID')
|
||||||
ELASTIC_AUTH_PASS = os.getenv('ELASTIC_AUTH_PASS')
|
ELASTIC_AUTH_PASS = os.getenv('ELASTIC_AUTH_PASS')
|
||||||
ELASTIC_CONN = {
|
ELASTIC_HOSTS = os.getenv('ELASTIC_HOSTS', None)
|
||||||
'cloud_id': ELASTIC_CLOUD_ID,
|
|
||||||
'basic_auth': ('elastic', ELASTIC_AUTH_PASS),
|
if ELASTIC_HOSTS:
|
||||||
}
|
ELASTIC_CONN = {'hosts': ELASTIC_HOSTS}
|
||||||
|
else:
|
||||||
|
ELASTIC_CONN = {
|
||||||
|
'cloud_id': ELASTIC_CLOUD_ID,
|
||||||
|
'basic_auth': ('elastic', ELASTIC_AUTH_PASS),
|
||||||
|
}
|
||||||
|
|||||||
@@ -132,8 +132,7 @@ def dynamodb_seeds(dynamodb_client):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_app(monkeypatch):
|
def mock_app():
|
||||||
monkeypatch.setattr('settings.ELASTIC_CONN', {'hosts': 'http://127.0.0.1:9200'})
|
|
||||||
import app
|
import app
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|||||||
14
http-api/uv.lock
generated
14
http-api/uv.lock
generated
@@ -353,7 +353,6 @@ dependencies = [
|
|||||||
dev = [
|
dev = [
|
||||||
{ name = "pytest" },
|
{ name = "pytest" },
|
||||||
{ name = "pytest-cov" },
|
{ name = "pytest-cov" },
|
||||||
{ name = "pytest-env" },
|
|
||||||
{ name = "ruff" },
|
{ name = "ruff" },
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -364,7 +363,6 @@ requires-dist = [{ name = "layercake", directory = "../layercake" }]
|
|||||||
dev = [
|
dev = [
|
||||||
{ name = "pytest", specifier = ">=8.3.4" },
|
{ name = "pytest", specifier = ">=8.3.4" },
|
||||||
{ name = "pytest-cov", specifier = ">=6.0.0" },
|
{ name = "pytest-cov", specifier = ">=6.0.0" },
|
||||||
{ name = "pytest-env", specifier = ">=1.1.5" },
|
|
||||||
{ name = "ruff", specifier = ">=0.9.1" },
|
{ 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 },
|
{ 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]]
|
[[package]]
|
||||||
name = "python-dateutil"
|
name = "python-dateutil"
|
||||||
version = "2.9.0.post0"
|
version = "2.9.0.post0"
|
||||||
|
|||||||
Reference in New Issue
Block a user