Skip to content

Commit

Permalink
feat: Enable support for yaml configuration files for DatagatewayAPI
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Remove support for json configuration files
  • Loading branch information
Reillyhewitson committed Sep 22, 2022
1 parent 2ae0a20 commit 46723de
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 39 deletions.
29 changes: 0 additions & 29 deletions datagateway_api/config.json.example

This file was deleted.

12 changes: 2 additions & 10 deletions datagateway_api/src/common/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json, yaml
import yaml
import logging
from pathlib import Path
import sys
Expand Down Expand Up @@ -186,17 +186,9 @@ def load(cls, path=Path(__file__).parent.parent.parent / "config.yaml"):
:param path: path to the configuration file
:return: APIConfig model object that contains the config data
"""
log = logging.getLogger()
try:
jpath = path.parent / "config.json" #Maybe move this to parameters? Will doing it like this break anything?
if path.exists():
with open(path, encoding="utf-8") as target:
with open(path, encoding="utf-8") as target:
data = yaml.safe_load(target)

elif jpath.exists():
log.warn("DEPRECATED: Using a JSON config file is deprecated and may be removed in an upcoming version. Please use a yaml config file instead.") #Does this message need to exist?
with open(jpath, encoding="utf-8") as target:
data = json.load(target)
return cls(**data)
except (IOError, ValidationError) as error:
sys.exit(f"An error occurred while trying to load the config data: {error}")
Expand Down

0 comments on commit 46723de

Please sign in to comment.