stix2arango 1.0.0__py3-none-any.whl → 1.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of stix2arango might be problematic. Click here for more details.

@@ -146,14 +146,12 @@ class ArangoDBService:
146
146
  if isinstance(ret, arango.exceptions.DocumentInsertError):
147
147
  if ret.error_code == 1210:
148
148
  existing_objects[f'{obj["id"]};{obj["_record_md5_hash"]}'] = collection_name + '/' + re.search(r'conflicting key: (.*)', ret.message).group(1)
149
- if 'relationship--7a1682a3-fec3-53ed-8dd5-68f54b1d6f7a' in ret.message:
150
- print(1)
151
149
  else:
152
150
  raise ret
153
151
  return [obj["id"] for obj in new_insertions], existing_objects
154
152
 
155
153
  def insert_several_objects_chunked(
156
- self, objects, collection_name, chunk_size=1000, remove_duplicates=True
154
+ self, objects, collection_name, chunk_size=5000, remove_duplicates=True
157
155
  ):
158
156
  if remove_duplicates:
159
157
  original_length = len(objects)
@@ -183,7 +181,7 @@ class ArangoDBService:
183
181
  relationships: list[dict[str, Any]],
184
182
  id_to_key_map: dict[str, str],
185
183
  collection_name: str,
186
- chunk_size=1200,
184
+ chunk_size=5000,
187
185
  ):
188
186
  for relationship in relationships:
189
187
  source_key = id_to_key_map.get(relationship["source_ref"])
@@ -244,7 +242,7 @@ class ArangoDBService:
244
242
  progress_bar.update(len(chunk))
245
243
 
246
244
  logging.info(
247
- f"Updating relationship's _is_latest for {len(deprecated_key_ids)} items"
245
+ f"Deprecating _is_latest for {len(deprecated_key_ids)} items"
248
246
  )
249
247
  self.deprecate_relationships(deprecated_key_ids, edge_collection)
250
248
  return deprecated_key_ids
@@ -253,11 +251,19 @@ class ArangoDBService:
253
251
  self, deprecated_key_ids: list, edge_collection: str, chunk_size=5000
254
252
  ):
255
253
  keys = self.get_relationships_to_deprecate(deprecated_key_ids, edge_collection)
256
- self.db.collection(edge_collection).update_many(
257
- tuple(dict(_key=_key, _is_latest=False) for _key in keys),
258
- silent=True,
259
- raise_on_document_error=True,
254
+
255
+ progress_bar = tqdm(
256
+ utils.chunked(keys, chunk_size),
257
+ total=len(keys),
258
+ desc="deprecate_relationships",
260
259
  )
260
+ for chunk in progress_bar:
261
+ self.db.collection(edge_collection).update_many(
262
+ tuple(dict(_key=_key, _is_latest=False) for _key in chunk),
263
+ silent=True,
264
+ raise_on_document_error=True,
265
+ )
266
+ progress_bar.update(len(chunk))
261
267
  return len(keys)
262
268
 
263
269
  def get_relationships_to_deprecate(
@@ -451,15 +451,20 @@ class Stix2Arango:
451
451
  )
452
452
 
453
453
  self.alter_objects(objects)
454
- with self.arango.transactional(exclusive=[self.core_collection_edge, self.core_collection_vertex]):
455
- inserted_object_ids, existing_objects = (
456
- self.arango.insert_relationships_chunked(
457
- objects, self.object_key_mapping, self.core_collection_edge
454
+ inserted_object_ids = []
455
+ existing_objects = {}
456
+ for chunk in utils.chunked(objects, 20_000):
457
+ with self.arango.transactional(exclusive=[self.core_collection_edge, self.core_collection_vertex]):
458
+ inserted, existing = (
459
+ self.arango.insert_relationships_chunked(
460
+ chunk, self.object_key_mapping, self.core_collection_edge
461
+ )
458
462
  )
459
- )
460
- self.arango.update_is_latest_several_chunked(
461
- inserted_object_ids, self.core_collection_edge, self.core_collection_edge
462
- )
463
+ inserted_object_ids.extend(inserted)
464
+ existing_objects.update(existing)
465
+ self.arango.update_is_latest_several_chunked(
466
+ inserted_object_ids, self.core_collection_edge, self.core_collection_edge
467
+ )
463
468
  return inserted_object_ids, existing_objects
464
469
 
465
470
  def import_default_objects(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stix2arango
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: stix2arango is a command line tool that takes a group of STIX 2.1 objects in a bundle and inserts them into ArangoDB. It can also handle updates to existing objects in ArangoDB imported in a bundle.
5
5
  Project-URL: Homepage, https://github.com/muchdogesec/stix2arango
6
6
  Project-URL: Issues, https://github.com/muchdogesec/stix2arango/issues
@@ -3,14 +3,14 @@ stix2arango/__main__.py,sha256=wbR_iO70Vld2NYiml6Kz4rH396uOiNwTtjNBl4AHZEg,1987
3
3
  stix2arango/config.py,sha256=NZFrcnEfz-0QBrut2Rh7xMF78v0bk6U6y2TY_7mHxSs,1407
4
4
  stix2arango/utils.py,sha256=heln_kXBSTLo0R4n1IrfCHbRnCHTQf9Y2URhvwQ0Smc,4845
5
5
  stix2arango/services/__init__.py,sha256=E87fB-dxI4mPxMVs00jdLhjp9jFhkVfjhMKIqGLRJlY,45
6
- stix2arango/services/arangodb_service.py,sha256=ipuWmhttAoZl1SyCqA2U2jpmdNxkpyqGQ4fUBzA5u1M,11585
6
+ stix2arango/services/arangodb_service.py,sha256=mXBQUeKR9IHErmvuZ73AiASZKawZOpuRiJQXWaN8bx8,11706
7
7
  stix2arango/services/version_annotator.py,sha256=Sd1MIaXzK0fpNopNxRoB_3etodzAjX5D_p3uGQSWzOI,2946
8
8
  stix2arango/stix2arango/__init__.py,sha256=OqxWEEsHqR1QQpznM5DbFJ5bO5numKYtoYhjXYJMEyg,36
9
9
  stix2arango/stix2arango/bundle_loader.py,sha256=qi-0E_bMIMPZXzISvjhrWX8K-f7iFv9vOekldOGVczU,4603
10
- stix2arango/stix2arango/stix2arango.py,sha256=AWObgUYS1rc1XpR1qgH1PhBMO_kQg2JcqlVzw08_fzY,20559
10
+ stix2arango/stix2arango/stix2arango.py,sha256=UVv1OVy_BzqXYN9cWzjKK3QUSRuS-7jf3n_IgGQwx_8,20769
11
11
  stix2arango/templates/marking-definition.json,sha256=0q9y35mUmiF6xIWSLpkATL4JTHGSCNyLbejqZiQ0AuE,3113
12
- stix2arango-1.0.0.dist-info/METADATA,sha256=NLfyjCW0z4ERKXj4-vQBLmFyj7_CmVLDKZRmcPuUW7M,6873
13
- stix2arango-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- stix2arango-1.0.0.dist-info/entry_points.txt,sha256=k2WnxMsHFLoyC6rqfvjhIMS1zwtWin51-MbNCGmSMYE,58
15
- stix2arango-1.0.0.dist-info/licenses/LICENSE,sha256=BK8Ppqlc4pdgnNzIxnxde0taoQ1BgicdyqmBvMiNYgY,11364
16
- stix2arango-1.0.0.dist-info/RECORD,,
12
+ stix2arango-1.0.2.dist-info/METADATA,sha256=uuH8tlqansoJvxNkqCxf4h_h1MteaRUQIlSQQG2DNOA,6873
13
+ stix2arango-1.0.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ stix2arango-1.0.2.dist-info/entry_points.txt,sha256=k2WnxMsHFLoyC6rqfvjhIMS1zwtWin51-MbNCGmSMYE,58
15
+ stix2arango-1.0.2.dist-info/licenses/LICENSE,sha256=BK8Ppqlc4pdgnNzIxnxde0taoQ1BgicdyqmBvMiNYgY,11364
16
+ stix2arango-1.0.2.dist-info/RECORD,,