Skip to content

Commit b801ac2

Browse files
#159 - Enable Connection to ENP DB (#168)
Co-authored-by: Corey Carvalho <[email protected]>
1 parent ab3115f commit b801ac2

14 files changed

+387
-42
lines changed

.env.local

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
export ACCESS_TOKEN_EXPIRE_SECONDS=60
44
export AWS_ACCESS_KEY_ID=test
55
export AWS_SECRET_ACCESS_KEY=test
6-
export ENP_DB_NAME=va-enp-api-db
7-
export NAPI_DB_READ_URI=postgresql+psycopg://postgres:LocalPassword@localhost:5432/notification_api
8-
export NAPI_DB_WRITE_URI=postgresql+psycopg://postgres:LocalPassword@localhost:5432/notification_api
9-
export ENP_DB_READ_URI=postgresql+psycopg://postgres:LocalPassword@localhost:5433/va-enp-api-db
10-
export ENP_DB_WRITE_URI=postgresql+psycopg://postgres:LocalPassword@localhost:5433/va-enp-api-db
6+
export DB_HOSTNAME=localhost
7+
export DB_HOSTNAME_READ=localhost
8+
export DB_NAME=va_enp_api
119
export ENP_ADMIN_SECRET_KEY=not-very-secret
12-
export ENV=local
10+
export ENP_DB_PORT=5433
11+
export ENV=local
12+
export NAPI_DB_READ_URI=postgresql+psycopg://postgres:LocalPassword@localhost:5432/notification_api
13+
export NAPI_DB_WRITE_URI=postgresql+psycopg://postgres:LocalPassword@localhost:5432/notification_api

.talismanrc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@ fileignoreconfig:
22
- filename: .env.example
33
checksum: f04bd8b8a51131d412bea4b8098e714ca01f4c7475eeb0a40d196d922070ba43
44
- filename: .env.local
5-
checksum: e64221548efb0246db08e35ce2122157d9a7e985f748367f42c9171f172884c0
5+
checksum: 60e7f10e36a8635b33bc26945e6336ae183fe603a15169e462027339360a00f4
66
- filename: app/auth.py
77
checksum: 06eb4b4c65191921104dc39381a937843a6ce155eeac7dc72990b5d10b5eb275
88
- filename: app/db/__init__.py
9-
checksum: 7373a948a440a47b385309ba07ec140a74c87fcfb6ce933544b0ccc8932da455
9+
checksum: 66575249d84eff02f539737ad2fa9f5a59b1b8982b5a3b8ff114e309ef62303d
1010
- filename: app/db/models.py
1111
checksum: 4ef96985d2353c00b229b30078f150ac80b15bd804b2d31c34784671793fec42
1212
- filename: app/providers/provider_aws.py
1313
checksum: f345ea8dea997d72c8d40a0cac2a2b1aacacef8959088ba5cc2ea9e5df57c9fd
14+
- filename: cd/dev.env
15+
checksum: 4c582cfb6a6b0a3dd9274c0fc8c7bfecc0b8c36eb46f1f09ddc21e66e6c786d1
16+
- filename: cd/perf.env
17+
checksum: 5c50afeea60016a131f94dacd3086db9cbb4c6af573be19c7de91bbb51e04db7
1418
- filename: ci/.env.docker
15-
checksum: 890be824556699720207a1465a09336cc1b48a4227152523401f7ba4f1d393b0
19+
checksum: 89c9897e4d29e36b9c001d98a0c0cd28b08858d367771b5e1ec50e398bc19e23
1620
- filename: ci/.env.local
17-
checksum: cd9c91e000ab1e53c5a89e9e2b316d7c12e7655843ce5af4b361b5edb328774c
21+
checksum: b9a695faea7f7f98ad3b1f221938144cc70667f70a8ab9e3828499fe1005d556
1822
- filename: ci/.local.env
1923
checksum: 47e9f19fdfb3655ceb51cfee25242e87d45bb05618a1cca6ac2bc8a709e0cdf9
2024
- filename: ci/docker-compose-local.yml
2125
checksum: c73beda98c39232441d86f6d6f6f2858274f9703f8a462eac1effacfbb9aa39d
2226
- filename: poetry.lock
23-
checksum: 0d37167f4fd23e1ace7119c3e7b6f3703785876d349897b3f56aed64eeedf237
27+
checksum: ff9d7c27a7784c0c340db4d302245ef9a951b62b9998a36d8408d49cdb0ee227
28+
- filename: postman/enp-api.postman_collection.json
29+
checksum: 06c086251fe022a3f42f4f88d316e2034044a53e6a6ce4f32bc4c56395f7485b
2430
- filename: scripts/run_tests.sh
2531
checksum: 80cd986074c12205493156f86b43e732777e2fae75683780006fb1baea90b82b
2632
- filename: tests/app/providers/__init__.py

app/db/__init__.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1+
import json
12
import os
23

3-
ENP_DB_NAME = os.getenv('DB_NAME', 'va-enp-api-db')
4-
ENP_DB_READ_URI = os.getenv(
5-
'ENP_DB_READ_URI', 'postgresql+psycopg://postgres:LocalPassword@localhost:5433/va-enp-api-db'
6-
)
7-
ENP_DB_WRITE_URI = os.getenv(
8-
'ENP_DB_WRITE_URI', 'postgresql+psycopg://postgres:LocalPassword@localhost:5433/va-enp-api-db'
9-
)
4+
DB_ENGINE = 'postgresql+psycopg'
5+
6+
ENP_DB_NAME = os.getenv('ENP_DB_NAME', 'va_enp_api')
7+
ENP_DB_PORT = os.getenv('ENP_DB_PORT', '5433')
8+
9+
# These configs require a change in infra to be updated
10+
DB_AUTH = json.loads(os.getenv('DB_AUTH', '{"username": "postgres", "password": "LocalPassword"}'))
11+
DB_USERNAME = DB_AUTH['username']
12+
DB_PASSWORD = DB_AUTH['password']
1013

14+
ENP_DB_HOSTNAME = os.getenv('DB_HOSTNAME', 'localhost')
15+
ENP_DB_HOSTNAME_READ = os.getenv('DB_HOSTNAME_READ', 'localhost')
16+
17+
# get the notification api database URI
1118
NAPI_DB_READ_URI = os.getenv(
12-
'NAPI_DB_READ_URI', 'postgresql+psycopg://postgres:LocalPassword@localhost:5432/notification_api'
19+
'NAPI_DB_READ_URI', f'{DB_ENGINE}://postgres:LocalPassword@localhost:5432/notification_api'
1320
)
1421
NAPI_DB_WRITE_URI = os.getenv(
15-
'NAPI_DB_WRITE_URI', 'postgresql+psycopg://postgres:LocalPassword@localhost:5432/notification_api'
22+
'NAPI_DB_WRITE_URI', f'{DB_ENGINE}://postgres:LocalPassword@localhost:5432/notification_api'
1623
)
24+
25+
# Ensure the correct DB_ENGINE is used. This is necessary when deployed.
26+
NAPI_DB_READ_URI = DB_ENGINE + '://' + NAPI_DB_READ_URI.split('://')[1]
27+
NAPI_DB_WRITE_URI = DB_ENGINE + '://' + NAPI_DB_WRITE_URI.split('://')[1]
28+
29+
# Construct the ENP database URIs
30+
ENP_DB_READ_URI = f'{DB_ENGINE}://{DB_USERNAME}:{DB_PASSWORD}@{ENP_DB_HOSTNAME_READ}:{ENP_DB_PORT}/{ENP_DB_NAME}'
31+
ENP_DB_WRITE_URI = f'{DB_ENGINE}://{DB_USERNAME}:{DB_PASSWORD}@{ENP_DB_HOSTNAME}:{ENP_DB_PORT}/{ENP_DB_NAME}'

app/db/db_init.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ async def init_db() -> None:
4040
# notification_api database connections
4141
await init_napi_metadata()
4242

43+
logger.info('...database engines initialized.')
44+
4345

4446
async def create_write_engine() -> None:
4547
"""Create the async write engine."""

app/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def simple_route() -> dict[str, str]:
111111
return {'Hello': 'World'}
112112

113113

114-
@app.post('/db/test', status_code=status.HTTP_201_CREATED, dependencies=[Depends(JWTBearer())])
114+
@app.post('/enp/db/test', status_code=status.HTTP_201_CREATED, dependencies=[Depends(JWTBearer())])
115115
async def db_create_test(
116116
*,
117117
data: str = 'hello',
@@ -220,7 +220,7 @@ async def fetch_notifications(session: AsyncSession, year_list: List[int]) -> Li
220220
return notifications
221221

222222

223-
@app.get('/db/test', status_code=status.HTTP_200_OK, dependencies=[Depends(JWTBearer())])
223+
@app.get('/enp/db/test', status_code=status.HTTP_200_OK, dependencies=[Depends(JWTBearer())])
224224
async def db_read_test(
225225
db_session: Annotated[async_scoped_session[AsyncSession], Depends(get_read_session_with_depends)],
226226
years: str | None = Query(

cd/dev.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ENP_ALGORITHM=HS256
22
ENP_ACCESS_TOKEN_EXPIRE_SECONDS=60
3+
ENP_DB_NAME=va_enp_api
4+
ENP_DB_PORT=5433
35
MAX_RETRIES=2886
4-
DB_NAME=va_enp_api

cd/perf.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ENP_ALGORITHM=HS256
22
ENP_ACCESS_TOKEN_EXPIRE_SECONDS=60
3+
ENP_DB_NAME=va_enp_api
4+
ENP_DB_PORT=5433
35
MAX_RETRIES=2886
4-
DB_NAME=va_enp_api

cd/va-enp-api-task-definition.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
{
3333
"name": "DD_SERVICE",
3434
"value": "va-enp-api"
35-
},
36-
{
37-
"name": "FLASK_APP",
38-
"value": "application.py"
3935
}
4036
],
4137
"secrets": ${TASK_DEFINITION_SECRETS_JSON},

ci/.env.docker

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
AWS_ACCESS_KEY_ID=test
33
AWS_REGION_NAME=us-east-1
44
AWS_SECRET_ACCESS_KEY=test
5-
ENP_DB_NAME=va-enp-api-db
6-
NAPI_DB_READ_URI=postgresql+psycopg://postgres:[email protected]:5432/notification_api
7-
NAPI_DB_WRITE_URI=postgresql+psycopg://postgres:[email protected]:5432/notification_api
8-
ENP_DB_READ_URI=postgresql+psycopg://postgres:LocalPassword@enp-db:5432/va-enp-api-db
9-
ENP_DB_WRITE_URI=postgresql+psycopg://postgres:LocalPassword@enp-db:5432/va-enp-api-db
5+
DB_HOSTNAME=enp-db
6+
DB_HOSTNAME_READ=enp-db
107
ENP_ADMIN_SECRET_KEY=not-very-secret
11-
ENV=local
8+
ENP_DB_NAME=va_enp_api
9+
ENP_DB_PORT=5432
10+
ENV=local
11+
NAPI_DB_READ_URI=postgresql://postgres:[email protected]:5432/notification_api
12+
NAPI_DB_WRITE_URI=postgresql://postgres:[email protected]:5432/notification_api

ci/Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
3535

3636
WORKDIR /app
3737

38+
# need bash for running scripts
39+
RUN apk add --no-cache bash
40+
3841
# add user and give ownership of app dir
3942
RUN adduser -h /app -D vanotify
4043

4144
# From context and only what is necessary, importing relative to WORKDIR
4245
COPY app/ app
4346

4447
# necessary files for mkdocs
45-
COPY scripts/create_mkdoc_files.py /app/scripts/create_mkdoc_files.py
48+
COPY scripts/* /app/scripts/
4649
COPY mkdocs.yml /app/mkdocs.yml
4750

4851
# Tests, using glob pattern to avoid copying
@@ -51,8 +54,6 @@ COPY $TEST_FOLDER/ tests
5154
# Copy builder files - venv
5255
COPY --from=builder /app/.venv /app/.venv
5356

54-
RUN echo "$POETRY_ARGS"
55-
5657
# these need to run only when POETRY_ARGS contain the proper setting
5758
RUN if echo "$POETRY_ARGS" | grep -q "mkdocs"; then \
5859
poetry run python scripts/create_mkdoc_files.py \
@@ -63,4 +64,4 @@ RUN if echo "$POETRY_ARGS" | grep -q "mkdocs"; then \
6364
USER vanotify
6465

6566
# CMD here for running when deployed to infra
66-
CMD ["gunicorn", "app.main:app", "-b", "0.0.0.0:8000", "-k", "uvicorn_worker.UvicornWorker", "-w", "4"]
67+
CMD ["gunicorn", "app.main:app", "-b", "0.0.0.0:6012", "-k", "uvicorn_worker.UvicornWorker", "-w", "4"]

0 commit comments

Comments
 (0)