def post(self): args = unit_step1_fields.parse_args() unit, analytical_data = self._service_unit.unit_upload(args["file"]) return escape(dict( id_unit=unit.id_unit, analytical_data=analytical_data ))
def post(self): data = escape(request.json) self._service_unit.unit_annotate( id_unit=data["id_unit"], name=data["name"], description=data["description"] if "description" in data else None, labels=data["labels"] if "labels" in data else None, ) return dict()
def test_escape(): assert escape(None) is None assert escape(1) == 1 assert escape([]) == [] assert escape([{"a": 3}]) == [{"a": 3}] assert escape([{">": 3}]) == [{">": 3}] assert escape(["abc", "<script>aaa"]) == ["abc", "<script>aaa"]
def post(self): data = escape(request.json) mac_mapping = Mapping.create_from_dict(data["mac_mapping"], keys=("mac","ips")) tcp_timestamp_mapping = Mapping.create_from_dict(data["tcp_timestamp_mapping"], keys=("ip","min")) id_annotated_unit = self._service_unit.unit_normalize( id_unit=data["id_unit"], mac_mapping=mac_mapping, ip_details=IPDetails( data["ips"]["target_nodes"], data["ips"]["intermediate_nodes"], data["ips"]["source_nodes"] ), tcp_timestamp_mapping=tcp_timestamp_mapping ) return dict(id_annotated_unit=id_annotated_unit.id_annotated_unit)
def unit_upload(self, file): if file.filename.endswith(".pcapng"): format = "pcapng" else: format = "pcap" file_path = self._file_storage.save_file(file.stream, format) unit = ModelUnit(creation_time=datetime.now(), last_update_time=datetime.now(), uploaded_file_location=file_path, stage="upload") self._session.add(unit) self._session.commit() return unit, escape( self._trace_analyzer.analyze( self._file_storage.get_file(file_path).location))
def post(self): data = escape(request.json) ip_mapping = Mapping.create_from_dict(data["ip_mapping"]) mac_mapping = Mapping.create_from_dict(data["mac_mapping"]) id_annotated_unit = self._service_unit.unit_normalize( id_unit=data["id_unit"], ip_mapping=ip_mapping, mac_mapping=mac_mapping, ip_details=IPDetails( data["ips"]["target_nodes"], data["ips"]["intermediate_nodes"], data["ips"]["source_nodes"] ), timestamp=data["timestamp"] ) return dict(id_annotated_unit=id_annotated_unit.id_annotated_unit)
def create_annotated_unit(self, name, description, mac_mapping, tcp_timestamp_mapping, ip_details, unit_file, labels): """ New annotated unit will be crated, normalized and saved into database :param name: Name of annotated unit :param description: Description of annotated unit :param mac_mapping: :param timestamp: :param ip_details: :param unit_file: :param labels: Annotated unit labels :return: new annotated unit """ new_ann_unit_file = File.create_new() configuration = self._trace_normalizer.prepare_configuration(ip_details, mac_mapping, tcp_timestamp_mapping) norm_out = self._trace_normalizer.normalize(unit_file.location, new_ann_unit_file.location, configuration) analyzed_data:dict = escape(self._trace_analyzer.analyze(new_ann_unit_file.location)) del analyzed_data['ip.groups'] with open(new_ann_unit_file.location, "rb") as f: ann_unit_file_name = self._file_storage.save_file(f, format=unit_file.format) annotated_unit = ModelAnnotatedUnit( name=name, description=description, creation_time=datetime.now(), stats=json.dumps(analyzed_data), ip_details=json.dumps( { "source_nodes" : norm_out["ip"]["ip.source"], "intermediate_nodes" : norm_out["ip"]["ip.intermediate"], "target_nodes" : norm_out["ip"]["ip.destination"] } ), file_location=ann_unit_file_name, labels=[ModelAnnotatedUnitLabel(label=l.lower()) for l in labels] ) self._session.add(annotated_unit) return annotated_unit
def post(self): params = escape(request.json.copy()) data = self._service_unit.get_units(**params) return escape(dict(data=[d.dict() for d in data]))
def post(self): params = escape(request.json.copy()) if "operator" in params: params["operator"] = OperatorEnum(params["operator"]) data = self._service_mix.get_mixes(**params) return escape(dict(data=[d.dict() for d in data]))
def get(self, id_mix): ann_unit = self._service_mix.get_mix(id_mix) return escape(ann_unit.dict())
def post(self, id_mix): self._service_mix.update_mix(id_mix, **escape(request.json)) return dict()
def post(self): mix = self._service_mix.create_mix(**escape(request.json)) return dict(id_mix=mix.id_mix)
def post(self, id_annotated_unit): self._service_ann_unit.update_annotated_unit(id_annotated_unit, **escape(request.json)) return dict()
def get(self, id_annotated_unit): ann_unit = self._service_ann_unit.get_annotated_unit(id_annotated_unit) if not ann_unit: raise AnnotatedUnitDoesntExistsException() return escape(ann_unit.dict())