-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into ponnia/upgrade-secrel
- Loading branch information
Showing
30 changed files
with
729 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
db-init/src/main/resources/database/migrations/V2.2__Tracked_Claim.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE IF NOT EXISTS "tracked_claims" ( | ||
id uuid NOT NULL, | ||
claim_id INT NOT NULL, | ||
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL, | ||
established_at TIMESTAMP WITHOUT TIME ZONE NOT NULL, | ||
feature_name VARCHAR NOT NULL, | ||
feature_enabled BOOLEAN NOT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
CREATE INDEX IF NOT EXISTS tracked_claims_id_index ON tracked_claims (id); | ||
CREATE INDEX IF NOT EXISTS tracked_claims_claim_id_index ON tracked_claims (claim_id); | ||
CREATE INDEX IF NOT EXISTS tracked_claims_feature_name_index ON tracked_claims (feature_name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Run pre-commit against all files by executing: pre-commit run --all-files | ||
# Auto-update the config to the latest repos' versions by executing: pre-commit autoupdate | ||
# Rather than disabling particular hooks (https://pre-commit.com/#temporarily-disabling-hooks), add an `exclude` | ||
|
||
repos: | ||
- repo: meta | ||
hooks: | ||
- id: check-useless-excludes | ||
|
||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.3.0 | ||
hooks: # https://github.com/pre-commit/pre-commit-hooks#hooks-available | ||
- id: check-merge-conflict | ||
- id: check-executables-have-shebangs | ||
- id: check-shebang-scripts-are-executable | ||
exclude: ^scripts/.*\.src$ | ||
- id: check-yaml | ||
- id: destroyed-symlinks | ||
- id: detect-private-key | ||
- id: end-of-file-fixer # https://stackoverflow.com/questions/2287967/why-is-it-recommended-to-have-empty-line-in-the-end-of-a-source-file | ||
- id: fix-byte-order-marker | ||
- id: mixed-line-ending | ||
- id: requirements-txt-fixer | ||
- id: trailing-whitespace | ||
|
||
- repo: https://github.com/pycqa/isort | ||
rev: 5.13.2 | ||
hooks: | ||
- id: isort | ||
args: [--profile, black] | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.4.4 | ||
hooks: | ||
# Run the linter. | ||
- id: ruff | ||
# Run the formatter. | ||
- id: ruff-format | ||
|
||
- repo: https://github.com/zricethezav/gitleaks | ||
rev: v8.15.0 | ||
hooks: | ||
- id: gitleaks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
plugins { | ||
id 'local.std.domain.folder-conventions' | ||
} | ||
|
||
dockerComposeUp { | ||
// Rebuild Docker images before docker-compose up | ||
// Run `docker` Gradle task on all subprojects | ||
dependsOn subprojects*.getTasksByName('docker', true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
version: '3.9' | ||
|
||
networks: | ||
# Put these services on the same `vro_intranet` network as VRO | ||
vro_intranet: | ||
# https://docs.docker.com/compose/networking/#use-a-pre-existing-network | ||
# Change this to true if running with app/src/docker/docker-compose.yml | ||
external: true | ||
|
||
# Reusable blocks | ||
# https://medium.com/@kinghuang/docker-compose-anchors-aliases-extensions-a1e4105d70bd | ||
# Also note https://yaml.org/type/merge.html | ||
|
||
x-common-vars: &common-vars | ||
# ENV determines which configuration settings to use. | ||
ENV: ${ENV:-local} | ||
|
||
x-common-security-opt: &common-security-opt | ||
security_opt: | ||
- no-new-privileges:true | ||
|
||
x-common-sde-security: &common-sde-security | ||
ulimits: | ||
nproc: 65535 | ||
|
||
x-rabbitmq-placeholder-vars: &rabbitmq-placeholder-vars | ||
RABBITMQ_PLACEHOLDERS_HOST: rabbitmq-database | ||
RABBITMQ_USERNAME: ${RABBITMQ_USERNAME} | ||
RABBITMQ_PASSWORD: ${RABBITMQ_PASSWORD} | ||
|
||
x-postgres-vars: &postgres-vars | ||
POSTGRES_URL: postgresql://postgres-service:5432/vro | ||
POSTGRES_HOST: postgres-service | ||
POSTGRES_PORT: 5432 | ||
POSTGRES_DB: ${POSTGRES_DB} | ||
POSTGRES_USER: ${POSTGRES_USER} | ||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} | ||
POSTGRES_SCHEMA: ${POSTGRES_SCHEMA} | ||
|
||
x-datadog-vars: &datadog-vars | ||
DD_SITE: ${DD_SITE} | ||
DD_API_KEY: ${DD_API_KEY} | ||
|
||
services: | ||
|
||
svc-claim-tracker: | ||
profiles: ["all", "bie-events"] | ||
image: va/abd_vro-svc-claim-tracker:latest | ||
<<: [*common-sde-security, *common-security-opt] | ||
environment: | ||
<<: [ *rabbitmq-placeholder-vars, *postgres-vars, *datadog-vars, *common-vars ] | ||
ports: | ||
- "8150:8150" | ||
networks: | ||
- vro_intranet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# Claim Tracker Service | ||
|
||
`/track/claim` track a claim by events | ||
|
||
## Getting started | ||
|
||
Install Python3.10 | ||
If you're on a Mac, you can use pyenv to handle multiple python versions | ||
|
||
``` | ||
brew install pyenv | ||
pyenv install python3.10 | ||
pyenv global python3.10 # or don't do this if you want a different version available globally for your system | ||
``` | ||
|
||
Create a virtual env: | ||
|
||
``` | ||
python -m venv ~/.virtualenvs/svc-claim-tracker # or wherever you want | ||
source ~/.virtualenvs/svc-claim-tracker/bin/activate | ||
``` | ||
|
||
Make sure your python path is set up to pull from your virtualenv: | ||
|
||
``` | ||
which python3 | ||
# /Users/<your_username>/.virtualenvs/svc-claim-tracker/bin/python | ||
``` | ||
|
||
Install dependencies and run webserver | ||
|
||
``` | ||
cd domain-bie-events/svc-claim-tracker/src | ||
pip install -r requirements.txt | ||
pip install -e . | ||
uvicorn api:app --port 8150 --reload | ||
``` | ||
|
||
## Testing it all together | ||
|
||
Run the Python webserver (uvicorn command above). Now you should be able to make a post request to the `/track/v1/claim` | ||
endpoint with a request body of the format: | ||
|
||
``` | ||
{ | ||
"claim_id": 123, | ||
"established_at": "2024-01-01T00:00:00Z", | ||
"feature_name":"feature", | ||
"feature_enabled":true | ||
} | ||
``` | ||
|
||
This should result in a response with the following body: | ||
|
||
``` | ||
{ | ||
"claim_id": 123, | ||
"established_at": "2024-01-01T00:00:00", | ||
"feature_name": "feature", | ||
"feature_enabled": true, | ||
"id": "d6c959f8-4106-4067-b65c-077c1a691222", | ||
"created_at": "2024-09-05T16:30:15.353744" | ||
} | ||
``` | ||
|
||
|
||
## Unit tests | ||
|
||
Make sure you're in your `.virtualenv`: | ||
|
||
Navigate to `domain-bie-events/svc-claim-tracker`: | ||
|
||
``` | ||
cd domain-bie-events/svc-claim-tracker | ||
``` | ||
|
||
Run the tests: | ||
|
||
``` | ||
pytest | ||
``` | ||
|
||
## Contributing | ||
|
||
### Install dev dependencies | ||
|
||
``` | ||
source ~/.virtualenvs/svc-claim-tracker/bin/activate | ||
pip install -r dev-requirements.txt | ||
# MAKE SURE you are in adb-vro/domain-bie-events to get the right pre-commit-config.yaml installed | ||
pre-commit install | ||
``` | ||
|
||
## Building docs | ||
|
||
``` | ||
source ~/.virtualenvs/svc-claim-tracker/bin/activate | ||
cd ./domain-bie-events/svc-claim-tracker | ||
python3 src/python_src/pull_api_documentation.py | ||
``` | ||
|
||
## Docker Stuff | ||
|
||
### Build the image | ||
|
||
Follow steps for | ||
[Platform Base](https://github.com/department-of-veterans-affairs/abd-vro/wiki/Docker-Compose#platform-base) | ||
then run the svc-claim-tracker with the following command from the `abd_vro` directory: | ||
|
||
``` | ||
COMPOSE_PROFILES="all" ./gradlew :domain-bie-events:dockerComposeUp | ||
``` | ||
|
||
### Verify API | ||
|
||
Navigate to [Swagger Docs](http://localhost:8150/docs) | ||
|
||
Try to send a request on the post endpoint with the following request body: | ||
|
||
``` | ||
{ | ||
"claim_id": 123, | ||
"established_at": "2024-01-01T00:00:00Z", | ||
"feature_name":"feature", | ||
"feature_enabled":true | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
plugins { | ||
id 'local.python.app-conventions' | ||
id 'local.python.container-service-conventions' | ||
} | ||
|
||
tasks.register('mypy', PythonTask) { | ||
module = 'mypy' | ||
command = 'src' | ||
dependsOn 'requirements' | ||
} | ||
|
||
tasks.register('isort', PythonTask) { | ||
module = 'isort' | ||
command = '.' | ||
dependsOn 'mypy' | ||
} | ||
|
||
tasks.register('ruff', PythonTask) { | ||
module = 'ruff' | ||
command = 'check' | ||
dependsOn 'isort' | ||
} | ||
|
||
tasks.register('appinstall', PythonTask) { | ||
module = 'pip' | ||
command = 'install -e .' | ||
dependsOn 'ruff' | ||
} | ||
|
||
// Override the pytest task in local.python.app-conventions to remove dependency on pyflake8 | ||
tasks.getByPath('pytest').configure { | ||
dependsOn.clear() | ||
dependsOn 'appinstall' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
exec uvicorn app.api:app --host 0.0.0.0 --port 8150 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# TODO: This should be changed to 8151 when this app is restructured to have multiple ports. | ||
# Currently uvicorn does not support bindings to multiple ports. | ||
healthcheck_port=8150 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# pyproject.toml | ||
[tool.pytest.ini_options] | ||
minversion = "6.0" | ||
addopts = "-ra --import-mode=importlib --cov=./src --cov-fail-under=80 --no-cov-on-fail --cov-report=term:skip-covered --cov-report=html:build/reports/coverage --cov-branch" | ||
testpaths = [ | ||
"tests" | ||
] | ||
|
||
[tool.coverage.run] | ||
# The following files are for development purposes and are not part of the coverage report | ||
omit = [ | ||
"src/app/pull_api_documentation.py", | ||
] | ||
|
||
[tool.isort] | ||
profile = "black" | ||
|
||
[tool.ruff] | ||
line-length = 160 | ||
|
||
[tool.ruff.lint] | ||
# Ruff enables Flake8's F rules, along with a subset of the E rules, omitting any stylistic rules that overlap with the use of Ruff formatter | ||
extend-select = [ | ||
# Add the `line-too-long` rule to the enforced rule set. | ||
"E501" | ||
] | ||
|
||
[tool.ruff.format] | ||
quote-style = "single" | ||
# Use `\n` line endings for all files | ||
line-ending = "lf" | ||
|
||
[tool.mypy] | ||
python_version = "3.10" | ||
strict = true | ||
ignore_missing_imports = true |
Empty file.
Oops, something went wrong.