import json


def load_configuration(path):
    """Loads the JSON configuration from a path and returns it as a
    dictionary, validating any required attributes.
    """
    data = json.load(open(path))

    if data["email"].get("business") is None:
        raise Exception(
            "Configuration failure: a business attribute is required")
    if data["email"]["business"].get("email_address") is None:
        raise Exception(
            "Configuration failure: a business email address is required")
    if data["email"]["business"].get("notification_address") is None:
        raise Exception(
            "Configuration failure: a notification address is required")
    if data["email"].get("templates_path") is None:
        raise Exception(
            "Configuration failure: email templates_path is required")
    if data["stripe"].get("endpoint_secret") is None:
        raise Exception(
            "Configuration failure: stripe endpoint secret is required")
    if data["smtp"].get("url") is None:
        raise Exception(
            "Configuration failure: smtp server url is required")

    return data