# Path: ceagle/api_fake_data/base.py
# CONF = config.CONF
# def route(reg):
#     def decorator(method):
#     def __init__(self, name, endpoint):
#     def _setup_routing(self):
#     def _find_route(self, path):
#     def default(self, path, *args, **kwargs):
#     def get(self, path, **kwargs):
# def api_handler(fake):
#     def real_function_handler(real):
#         def choice_maker(*args, **kwargs):
# def randnum(from_num, to_num, round_by=2):
# class FakeClient(object):


import datetime
import flask
from ceagle.api_fake_data import base
REGION_R = r"(?P<region>[a-z\d\-\.\_]+)"
PERIOD_R = r"(?P<period>day|week|month)"


def _get_issues(region, period):
    issues = []
    if region:
        all_issues = FAKE_ISSUES.get(region)
        if all_issues is None:
            flask.abort(404)
    else:
        all_issues = sum(FAKE_ISSUES.values(), [])
    now = datetime.datetime.now()
    try:
        discovered_before = (now - datetime.timedelta(
            days=PERIOD_MAP[period])).isoformat("T")
    except KeyError:
        flask.abort(404)
    for issue in all_issues:
        if issue["discovered_at"] >= discovered_before:
            issues.append(issue)
    return issues


class Client(base.FakeClient):

    @base.route("/api/(?P<api>\w+)/regions")
    def _regions(self, query, api):
        return list(FAKE_ISSUES.keys()), 200


# Path: ceagle/api_fake_data/base.py
# CONF = config.CONF
# def route(reg):
#     def decorator(method):
#     def __init__(self, name, endpoint):
#     def _setup_routing(self):
#     def _find_route(self, path):
#     def default(self, path, *args, **kwargs):
#     def get(self, path, **kwargs):
# def api_handler(fake):
#     def real_function_handler(real):
#         def choice_maker(*args, **kwargs):
# def randnum(from_num, to_num, round_by=2):
# class FakeClient(object):


# Path: ceagle/api_fake_data/security.py
import datetime
import flask
from ceagle.api_fake_data import base

REGION_R = r"(?P<region>[a-z\d\-\.\_]+)"
PERIOD_R = r"(?P<period>day|week|month)"


def _get_issues(region, period):
    issues = []
    if region:
        all_issues = FAKE_ISSUES.get(region)
        if all_issues is None:
            flask.abort(404)
    else:
        all_issues = sum(FAKE_ISSUES.values(), [])
    now = datetime.datetime.now()
    try:
        discovered_before = (now - datetime.timedelta(
            days=PERIOD_MAP[period])).isoformat("T")
    except KeyError:
        flask.abort(404)
    for issue in all_issues:
        if issue["discovered_at"] >= discovered_before:
            issues.append(issue)
    return issues


class Client(base.FakeClient):

    @base.route("/api/(?P<api>\w+)/regions")
    def _regions(self, query, api):
        return list(FAKE_ISSUES.keys()), 200


    @base.route(r"/api/v1/region/%s/security/issues/%s" % (REGION_R, PERIOD_R))