def post_entities(body,
                  clazz,
                  array_name,
                  setup_function=None,
                  teardown_function=None):
    entity_name = clazz.__name__
    json_array = body[array_name]
    is_sensitive_data = entity_name in SENSITIVE_DATA_CLASSES
    if is_sensitive_data:
        for json_entity in json_array:
            body['action'] = ''
            body['instance'] = ''
            if "id" not in json_entity:
                json_entity[ID] = generate_uuid()
        json_entity, code = post_private_response(body)
        if code != 200 or entity_name in SENSITIVE_DATA_EXCLUDED_FROM_MERGE_CLASSES:
            return make_json_response(json_entity, code)

    with session_scope() as session:
        for json_entity in json_array:
            body['action'] = ''
            body['instance'] = ''
            if is_sensitive_data:
                entity_id = json_entity[ID]
                json_entity = empty_json_object()
                json_entity[ID] = entity_id
            elif setup_function is not None:
                setup_function(json_entity, session)
            merge_entity(clazz, json_entity, body, session)
        pop_token()
    return success('POST /' + array_name, 200, 'Success',
                   REST_GUIDE + entity_name, body['instance'], body['action'],
                   teardown_function)
Example #2
0
def get_entities(array_name, entities, get_relation_entity_function=None):
    json_entities = empty_json_array(array_name)
    json_entities[array_name] = to_json_array(entities)
    if get_relation_entity_function is not None:
        json_array = json_entities[array_name]
        get_relation_entity_function(json_array)
    return make_json_response(json_entities, 200)
Example #3
0
def get_nodes(token):
    with session_scope() as session:
        nodes = session.query(Node).all()
        nodes_json = to_json_array(nodes)
        enrich_nodes_json(nodes_json)
    json = empty_json_array('nodes')
    json['nodes'] = nodes_json
    return make_json_response(json, 200)
Example #4
0
def get_sensitive_data_by_ids(ids, array_name, get_relation_entity_function):
    request = empty_json_object()
    request[BYIDS_FILTER] = ids
    request['token'] = extract_private_token()
    json, code = post_private_response(request)
    if code == 200 and get_relation_entity_function is not None:
        json_array = json[array_name]
        get_relation_entity_function(json_array)
    return make_json_response(json, code)
Example #5
0
def get_health():
    returned_server_time = convert_date_to_string(now())
    query = '''select now() as current_time from dual'''
    returned_database_time = first(text(query))['current_time']
    info("server_time: %s; database_time: %s", returned_server_time,
         returned_database_time)
    processed = int(round(time.time() * 1000)) - g.requested_ms
    json = empty_json_object()
    json['processed_time_ms'] = processed
    json['returned_server_time'] = returned_server_time
    json['returned_database_time'] = returned_database_time
    return make_json_response(json, 200)
Example #6
0
def delete_entity(clazz, entity_id, token):
    entity_name = clazz.__name__
    instance = '/' + entity_name.lower() + '/' + str(entity_id)
    if entity_name in SENSITIVE_DATA_CLASSES:
        json, code = delete_private_response()
        if code != 200:
            return make_json_response(json, code)

    with session_scope() as session:
        entity_db = session.query(clazz).filter_by(id=uuid.UUID(entity_id))
        if entity_db.first() is None:
            response = fault(entity_name + ' not found', STORAGE_0003, 404,
                             RESOURCE_NOT_FOUND,
                             REST_GUIDE + entity_name + 's', instance,
                             'delete')
        else:
            entity_db.delete()
            response = success(
                'DELETE /' + entity_name.lower() + '/' + entity_id, 200,
                'Success', REST_GUIDE + entity_name + 's', instance, 'delete')
    return response
Example #7
0
def get_node_by_id(id, token):
    # TODO: Implement get by id function
    return make_json_response(empty_json_array('nodes'), 200)
Example #8
0
def search(body):
    # TODO: Implement search functions
    return make_json_response(empty_json_array('nodes'), 200)
Example #9
0
def get_version():
    json_version = {"version": REST_VERSION}
    return make_json_response(json_version, 200)
Example #10
0
def get_sensitive_data(array_name, get_relation_entity_function=None):
    json, code = get_private_response()
    if code == 200 and get_relation_entity_function is not None:
        json_array = json[array_name]
        get_relation_entity_function(json_array)
    return make_json_response(json, code)