Skip to content

Commit

Permalink
Merge pull request #306 from fiaisis/specification-migration
Browse files Browse the repository at this point in the history
Move JSON specification files to the DB
  • Loading branch information
keiranjprice101 committed Aug 13, 2024
2 parents dbef157 + 3ac07cf commit 14ad59a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ jobs:
- name: Start e2e docker compose environment
run: |
cd test
docker-compose up -d
docker compose up -d
- name: Run e2e test
run: pytest -l -v --random-order --random-order-bucket=global test/test_e2e.py

- name: View logs on fail
if: failure()
run: |
cd test
docker-compose logs run-detection
docker-compose logs rabbit-mq
docker compose logs run-detection
docker compose logs rabbit-mq
2 changes: 0 additions & 2 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.7"

services:
rabbit-mq:
image: "rabbitmq:3.12-management"
Expand Down
41 changes: 41 additions & 0 deletions tools/specification_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
This script moves the all json specifications from this repository to the database via PUT calls to the FIA_API
It should be run from the root directory of this repository.
It expects 2 command line args, the FIA_API_URL and the FIA_API_API_KEY
"""

import json
import sys
from pathlib import Path

import requests

FIA_API_URL = sys.argv[1]
"""
The API key doesn't work when running in a bash terminal (due to the non
alpha-numeric characters). So it needs to be temporarily added below when running,
and removed after (DO NOT COMMIT the hardcoded FIA_API_API_KEY)
"""
FIA_API_API_KEY = sys.argv[2]

successful_update: int = 200
auth_headers: json = {"Authorization": f"Bearer {FIA_API_API_KEY}", "accept": "application/json"}

# locate specifications
specifications_path = Path("rundetection/specifications")
specifications_list = sorted(specifications_path.glob("*.json"))


for file_name in specifications_list:
instrument_name = file_name.stem.split("_")[0].upper()
with file_name.open(mode="r", encoding="utf-8") as specification:
json_spec = json.load(specification)

response = requests.put(
url=f"{FIA_API_URL}/instrument/{instrument_name}/specification",
json=json_spec,
headers=auth_headers,
timeout=2000,
)
print(f"PUT result, {instrument_name} - {response.status_code}") # noqa: T201

0 comments on commit 14ad59a

Please sign in to comment.