Skip to content

Commit 78792d6

Browse files
authored
Tech debt: updating the project structure (#102)
* Tech debt changes: project file structure, documentation, getting rid of obsolete files
1 parent efc9000 commit 78792d6

File tree

17 files changed

+485
-564
lines changed

17 files changed

+485
-564
lines changed

.github/workflows/aquasec_repo_scan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: AquaSec Full Repository Scan
33
on:
44
workflow_dispatch:
55
pull_request:
6-
types: [ opened, synchronize ]
6+
types: [ opened ]
77

88
permissions:
99
contents: read

.github/workflows/check_python.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@ jobs:
3131
- name: Check if Python files changed
3232
id: changes
3333
shell: bash
34+
env:
35+
GH_TOKEN: ${{ github.token }}
3436
run: |
37+
set -euo pipefail
38+
3539
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
36-
RANGE="${{ github.event.pull_request.base.sha }}...${{ github.sha }}"
40+
CHANGED_FILES=$(gh api \
41+
"repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \
42+
--jq '.[].filename | select(endswith(".py"))')
3743
else
38-
RANGE="${{ github.sha }}~1...${{ github.sha }}"
44+
CHANGED_FILES=$(git diff --name-only "${{ github.sha }}~1" "${{ github.sha }}" -- '*.py')
3945
fi
40-
if git diff --name-only "$RANGE" -- '*.py' | grep -q .; then
46+
47+
if [[ -n "$CHANGED_FILES" ]]; then
4148
echo "python_changed=true" >> "$GITHUB_OUTPUT"
4249
else
4350
echo "python_changed=false" >> "$GITHUB_OUTPUT"

.github/workflows/check_terraform.yml

Lines changed: 0 additions & 82 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,5 @@ __pycache__
55
/dependencies
66
/lambda_function.zip
77

8-
# Terraform files
9-
/terraform/*.tfvars
10-
/terraform/*.tfstate*
11-
/terraform/.terraform*
12-
138
# Terraform Plan output files
149
*.sarif

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ RUN \
7373
COPY $SASL_SSL_ARTIFACTS /opt/sasl_ssl_artifacts/
7474
COPY src $LAMBDA_TASK_ROOT/src
7575
COPY conf $LAMBDA_TASK_ROOT/conf
76+
COPY api.yaml $LAMBDA_TASK_ROOT/api.yaml
7677

7778
# Mark librdkafka to LD_LIBRARY_PATH
7879
# Kerberos default CCACHE override due to KEYRING issues

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Python AWS Lambda that exposes a simple HTTP API (via API Gateway) for validatin
1919
- [Kafka Writer](#kafka-writer)
2020
- [EventBridge Writer](#eventbridge-writer)
2121
- [Postgres Writer](#postgres-writer)
22-
- [Scripts](#scripts)
2322
- [Troubleshooting](#troubleshooting)
2423
- [License](#license)
2524
<!-- tocstop -->
@@ -34,7 +33,7 @@ EventGate receives JSON payloads for registered topics, authorizes the caller vi
3433
- Runtime-configurable access rules (local or S3)
3534
- API-discoverable schema catalogue
3635
- Pluggable writer initialization via `config.json`
37-
- Terraform IaC examples for AWS deployment (API Gateway + Lambda)
36+
- Terraform IaC examples for AWS deployment (API Gateway + Lambda) in `terraform_examples/`
3837
- Supports both Zip-based and Container Image Lambda packaging (Container path enables custom `librdkafka` / SASL_SSL / Kerberos builds)
3938

4039
## Architecture
@@ -47,8 +46,9 @@ High-level flow:
4746

4847
Key files:
4948
- `src/event_gate_lambda.py` – main Lambda handler and routing
50-
- `conf/*.json` – configuration and topic schemas
51-
- `conf/api.yaml` – OpenAPI 3 definition served at `/api`
49+
- `conf/*.json` – configuration files
50+
- `conf/topic_schemas/` – JSON topic schemas
51+
- `api.yaml` – OpenAPI 3 definition served at `/api`
5252
- `writer_*.py` – individual sink implementations
5353

5454
## API
@@ -58,18 +58,21 @@ All responses are JSON unless otherwise noted. The POST endpoint requires a vali
5858
|--------|----------|------|-------------|
5959
| GET | `/api` | none | Returns OpenAPI 3 definition (raw YAML) |
6060
| GET | `/token` | none | 303 redirect to external token provider |
61+
| GET | `/health` | none | Returns service health and dependency status |
6162
| GET | `/topics` | none | Lists available topic names |
6263
| GET | `/topics/{topicName}` | none | Returns JSON Schema for the topic |
6364
| POST | `/topics/{topicName}` | JWT | Validates + forwards message to configured sinks |
6465
| POST | `/terminate` | (internal) | Forces Lambda process exit (used to trigger cold start & config reload) |
6566

6667
Status codes:
68+
- 200 – Health check pass
6769
- 202 – Accepted (all writers succeeded)
6870
- 400 – Schema validation failure
6971
- 401 – Token missing/invalid
7072
- 403 – Subject unauthorized for topic
7173
- 404 – Unknown topic or route
7274
- 500 – One or more writers failed / internal error
75+
- 503 – Service degraded (dependency not initialized)
7376

7477
## Configuration
7578
All core runtime configuration is driven by JSON files located in `conf/` unless S3 paths are specified.
@@ -100,14 +103,13 @@ Configuration keys:
100103

101104
Supporting configs:
102105
- `access.json` – map: topicName -> array of authorized subjects (JWT `sub`). May reside locally or at S3 path referenced by `access_config`.
103-
- `topic_*.json` – each file contains a JSON Schema for a topic. In the current code these are explicitly loaded inside `event_gate_lambda.py`. (Future enhancement: auto-discover or index file.)
104-
- `api.yaml` – OpenAPI spec served verbatim at runtime.
106+
- `topic_schemas/*.json` – each file contains a JSON Schema for a topic. In the current code these are explicitly loaded inside `event_gate_lambda.py`. (Future enhancement: auto-discover or index file.)
105107

106108
Environment variables:
107109
- `LOG_LEVEL` (optional) – defaults to `INFO`.
108110

109111
## Deployment
110-
Infrastructure-as-Code examples live in the `terraform/` directory. Variables are supplied via a `*.tfvars` file or CLI.
112+
Infrastructure-as-Code examples are provided in `terraform_examples/`. These are reference implementations that you can adapt to your environment. Variables are supplied via a `*.tfvars` file or CLI.
111113

112114
### Zip Lambda Package
113115
Use when no custom native libraries are needed.
@@ -169,18 +171,14 @@ Publishes events to the configured `event_bus_arn` using put events API.
169171
### Postgres Writer
170172
Example writer (currently a placeholder if no DSN present) demonstrating extensibility pattern.
171173

172-
## Scripts
173-
- `scripts/prepare.deplyoment.sh` – build Zip artifact for Lambda (typo in name retained for now; may rename later)
174-
- `scripts/notebook.ipynb` – exploratory invocation cells per endpoint
175-
- `scripts/get_token.http` – sample HTTP request for tooling (e.g., VSCode REST client)
176-
177174
## Troubleshooting
178175
| Symptom | Possible Cause | Action |
179176
|---------|----------------|--------|
180177
| 401 Unauthorized | Missing / malformed token header | Ensure `Authorization: Bearer` present |
181178
| 403 Forbidden | Subject not listed in access map | Update `access.json` and redeploy / reload |
182179
| 404 Topic not found | Wrong casing or not loaded in code | Verify loaded topics & file names |
183180
| 500 Writer failure | Downstream (Kafka / EventBridge / DB) unreachable | Check network / VPC endpoints / security groups |
181+
| 503 Service degraded | Dependency not initialized | Check `/health` response for specific failure |
184182
| Lambda keeps old config | Warm container | Call `/terminate` (internal) to force cold start |
185183

186184
## License

0 commit comments

Comments
 (0)