-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from fiaisis/specification-migration
Move JSON specification files to the DB
- Loading branch information
Showing
3 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
version: "3.7" | ||
|
||
services: | ||
rabbit-mq: | ||
image: "rabbitmq:3.12-management" | ||
|
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,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 |