import json
import os


DEFAULT_CONFIG_FILE_PATH = os.environ.get('OP_DEV_CONFIG', '/var/www/.op-dev/config.json')


def load_config(config_file_path=DEFAULT_CONFIG_FILE_PATH):
  try:
    with open(config_file_path) as config_file:
      serialized_config = config_file.read()
    config = json.loads(serialized_config)
  except json.decoder.JSONDecodeError:
    logging.warn("Invalid JSON in config file at path: %s (ignoring)" % metadata_file_path)
  except Exception as e:
    raise Exception("Could not read config file at path '%s'" % config_file_path) from e
  # TODO: this should be a frozen dictionary, maybe by using MappingProxyType
  return config
