Example #1
0
def visualiser_item_get(request, id_):
    try:
        root_edge_object = PublisherEdgeObject.load(id_)
        if root_edge_object.ty == 'pkg':
            package = root_edge_object.obj
            validation_info = {}
        else:
            package = PackageGenerator.build_package(root_edge_object)
            validation_info = PackageValidationInfo.validate(
                package).validation_dict
        return JsonResponse(
            {
                "root_id": id_,
                "package": package.to_dict(),
                "validation_info": validation_info,
                "type_info": [{
                    "id_": id_,
                    "ty": root_edge_object.ty
                }]
            },
            status=200)
    except EdgeError as e:
        if e.message == id_ + " not found":
            return JsonResponse({'error': e.message}, status=404)
        else:
            return JsonResponse({'error': e.message}, status=500)
    except Exception as e:
        return JsonResponse({'error': e.message}, status=500)
 def test_PublisherEdgeObject_RootHasGrandChildrenFromDifferentNamespace_NamespacePresent(self):
     edge_object = PublisherEdgeObject.load('PurpleSecureSystems:indicator-02db75d2-77e2-4774-a219-293318051515')
     namespaces = edge_object.ns_dict()
     self.assertEqual(namespaces, {
         'http://www.purplesecure.com': 'PurpleSecureSystems',
         'http://www.fireeye.com': 'fireeye'
     })
Example #3
0
def visualiser_get(request, id_):
    try:
        root_edge_object = PublisherEdgeObject.load(id_)
        graph = create_graph([(0, None, root_edge_object, REL_TYPE_EDGE)], [],
                             [], [], [], [], request)
        return JsonResponse(graph, status=200)
    except Exception as e:
        return JsonResponse({'error': e.message}, status=500)
Example #4
0
def generate_partial_review_data(request, id, revision):
    root_edge_object = PublisherEdgeObject.load(id,
                                                filters=request.user.filters(),
                                                revision=revision,
                                                include_revision_index=True)
    package = PackageGenerator.build_package(root_edge_object)
    validation_info = PackageValidationInfo.validate(package)

    def user_loader(idref):
        return EdgeObject.load(idref, request.user.filters())

    edges = EdgeGenerator.gather_edges(root_edge_object.edges,
                                       load_by_id=user_loader)

    req_user = _get_request_username(request)
    if root_edge_object.created_by_username != req_user:
        validation_info.validation_dict.update({
            id: {
                "created_by": {
                    "status":
                    ValidationStatus.WARN,
                    "message":
                    "This object was created by %s not %s" %
                    (root_edge_object.created_by_username, req_user)
                }
            }
        })
    if any(item['is_external'] for item in edges):
        validation_info.validation_dict.update({
            id: {
                "external_references": {
                    "status":
                    ValidationStatus.ERROR,
                    "message":
                    "This object contains External References, clone "
                    "object and remove missing references before"
                    " publishing"
                }
            }
        })

    # add root object to edges for javascript to construct object
    edges.append({
        'ty': root_edge_object.ty,
        'id_': root_edge_object.id_,
        'is_external': False
    })

    return {
        'root_edge_object': root_edge_object,
        'package': package,
        "trust_groups": root_edge_object.tg,
        "validation_info": validation_info,
        "edges": edges,
        "revision": root_edge_object.version
    }
Example #5
0
def ajax_load_object(request, id_):
    root_edge_object = PublisherEdgeObject.load(id_)
    package = PackageGenerator.build_package(root_edge_object)
    return JsonResponse(
        {
            "root_id": id_,
            "package": package.to_dict(),
            "type_info": [{
                "id_": id_,
                "ty": root_edge_object.ty
            }]
        },
        status=200)
Example #6
0
def visualiser_get_extended(request):
    json_data = json.loads(request.body)
    root_id = json_data['id']
    bl_ids = json_data['id_bls']
    match_ids = json_data['id_matches']
    hide_edge_ids = json_data['hide_edge_ids']
    show_edge_ids = json_data['show_edge_ids']
    hidden_ids = json_data['hidden_ids']
    try:
        root_edge_object = PublisherEdgeObject.load(root_id)
        graph = create_graph([(0, None, root_edge_object, REL_TYPE_EDGE)],
                             bl_ids, match_ids, hide_edge_ids, show_edge_ids,
                             hidden_ids, request)
        return JsonResponse(graph, status=200)
    except Exception as e:
        return JsonResponse({'error': e.message}, status=500)
Example #7
0
def get_duplicates(request, id_):
    root_edge_object = PublisherEdgeObject.load(id_,
                                                filters=request.user.filters())
    duplicates = DuplicateFinder.find_duplicates(root_edge_object)

    return JsonResponse({"duplicates": duplicates})
 def test_PublisherEdgeObject_CreatedByUserNamePresent(self):
     edge_object = PublisherEdgeObject.load('PurpleSecureSystems:indicator-02db75d2-77e2-4774-a219-293318051515')
     username = edge_object.created_by_username
     self.assertEqual(username, 'admin')