Ejemplo n.º 1
0
def admin_data(req, path_vars):
    data = {
        "id": "322",
        "name": "Administrator",
        "email": "*****@*****.**",
        "roles": ["ROLE_ADMIN", "ROLE_USER"]
    }
    serialized_data = jsn.dumps(data, indent=4)
    return response.ok(serialized_data, 'application/json', {})
Ejemplo n.º 2
0
def file_exists(path, skip_rewrite=False, ignore_cache=False):
    if not skip_rewrite:
        rewritten_fp = rewriter.rewrite(path)
    else:
        rewritten_fp = path

    if log.is_tracing():
        log.trace("Accessing path: " + rewritten_fp)

    if not ignore_cache:
        cached_file = file_cache.get_file(rewritten_fp)
        if cached_file != None:
            response.ok("")

    file = open(rewritten_fp, 'rb')

    if file == None:
        return response.not_found("")

    return response.ok("")
Ejemplo n.º 3
0
def authenticate(req, body, path_vars):
    global FAKE_JWT
    credidentials = jsn.loads(body)
    log.info(credidentials)
    if 'user' not in credidentials or 'pass' not in credidentials:
        return response.bad_request("Missing credidentials", 'text/plain')

    if credidentials['user'] == 'admin' and credidentials['pass'] == 'admin':
        return response.ok("Authorization accepted for user Administrator",
                           'text/plain',
                           {'Authorization': 'Bearer ' + FAKE_JWT})
    return response.bad_request("Invalid credidentials", 'text/plain')
Ejemplo n.º 4
0
def json(req, body, path_vars):
    string_json = body
    parsed_json = jsn.loads(string_json)

    return response.ok(jsn.dumps(parsed_json, separators=(',', ':')))
Ejemplo n.º 5
0
def current_date(req, path_vars):
    today = date.today().strftime("%d %B  %Y")
    return response.ok(today, 'text/plain')
Ejemplo n.º 6
0
def hello(req, path_vars):
    print(req['GET'])
    return response.ok(req['GET'], 'text/plain', {'Test': '123-322'})
Ejemplo n.º 7
0
def test_post(req, body, path_var):
    return response.ok(str(req), 'text/plain', {'Test': '123-322'})
Ejemplo n.º 8
0
def multi_param_text(req, path_vars):
    print(path_vars)
    return response.ok(
        path_vars['v1'] + ' ' + path_vars['v2'] + ' ' + path_vars['v3'],
        'text/plain')