# Path: shelf/utils.py
# def create_path(*args):
# def get_host_from_uri(uri):
# def validate_against_schema(schema_path, data):
# def get_bucket_config(config, bucket_name):
# def validate_bucket_config(config):
# def assign_reference_name(config):


from jsonschema import ValidationError
from shelf import utils
from shelf.logger_creator import LoggerCreator
from shelf.request_log_filter import RequestLogFilter
import os
import yaml


def app_config(existing_config, config_path):
    try:
        with open(config_path, "r") as f:
            content = f.read()
            config = yaml.load(content)
    except IOError:
        raise ValueError("Could not find or open file {0}".format(config_path))
    except:
        raise ValueError("{0} contained invalid yaml".format(config_path))

    try:
        utils.validate_against_schema("schemas/config.json", config)
    except ValidationError:
        raise ValueError(
            "{0} did not pass validation of json schema at schemas/config.json."
            " The original ValidationError was swallowed to prevent logging of sensitive data.".format(config_path)
        )
    utils.validate_bucket_config(config)

# Path: shelf/utils.py
# def create_path(*args):
# def get_host_from_uri(uri):
# def validate_against_schema(schema_path, data):
# def get_bucket_config(config, bucket_name):
# def validate_bucket_config(config):
# def assign_reference_name(config):


# Path: shelf/configure.py
from jsonschema import ValidationError
from shelf import utils
from shelf.logger_creator import LoggerCreator
from shelf.request_log_filter import RequestLogFilter
import os
import yaml



def app_config(existing_config, config_path):
    try:
        with open(config_path, "r") as f:
            content = f.read()
            config = yaml.load(content)
    except IOError:
        raise ValueError("Could not find or open file {0}".format(config_path))
    except:
        raise ValueError("{0} contained invalid yaml".format(config_path))

    try:
        utils.validate_against_schema("schemas/config.json", config)
    except ValidationError:
        raise ValueError(
            "{0} did not pass validation of json schema at schemas/config.json."
            " The original ValidationError was swallowed to prevent logging of sensitive data.".format(config_path)
        )
    utils.validate_bucket_config(config)

    config = utils.assign_reference_name(config)