@@ -89,6 +89,15 @@ def __init__(self, opencti, file):
89
89
}
90
90
}
91
91
}
92
+ importFiles {
93
+ edges {
94
+ node {
95
+ id
96
+ name
97
+ size
98
+ }
99
+ }
100
+ }
92
101
... on AttackPattern {
93
102
platform
94
103
required_permission
@@ -486,32 +495,45 @@ def delete(self, **kwargs):
486
495
:return void
487
496
"""
488
497
489
- def upload_file (self , ** kwargs ):
498
+ def add_file (self , ** kwargs ):
490
499
id = kwargs .get ("id" , None )
491
500
file_name = kwargs .get ("file_name" , None )
492
501
data = kwargs .get ("data" , None )
493
502
mime_type = kwargs .get ("mime_type" , "text/plain" )
494
503
if id is not None and file_name is not None :
495
- self .opencti .log (
496
- "info" , "Uploading a file in Stix-Domain-Entity {" + id + "}."
497
- )
498
- query = """
499
- mutation StixDomainEntityEdit($id: ID!, $file: Upload!) {
500
- stixDomainEntityEdit(id: $id) {
501
- importPush(file: $file) {
502
- id
503
- name
504
+ stix_domain_entity = self .read (id = id )
505
+ if stix_domain_entity is None :
506
+ self .opencti .log (
507
+ "error" , "Cannot add File, entity not found"
508
+ )
509
+ return False
510
+ final_file_name = os .path .basename (file_name )
511
+ current_files = {}
512
+ for file in stix_domain_entity ['importFiles' ]:
513
+ current_files [file ['name' ]] = file
514
+ if final_file_name in current_files :
515
+ return current_files [final_file_name ]
516
+ else :
517
+ self .opencti .log (
518
+ "info" , "Uploading a file in Stix-Domain-Entity {" + id + "}."
519
+ )
520
+ query = """
521
+ mutation StixDomainEntityEdit($id: ID!, $file: Upload!) {
522
+ stixDomainEntityEdit(id: $id) {
523
+ importPush(file: $file) {
524
+ id
525
+ name
526
+ }
504
527
}
505
528
}
506
- }
507
- """
508
- if data is None :
509
- data = open (file_name , "rb" )
510
- mime_type = magic .from_file (file_name , mime = True )
529
+ """
530
+ if data is None :
531
+ data = open (file_name , "rb" )
532
+ mime_type = magic .from_file (file_name , mime = True )
511
533
512
- return self .opencti .query (
513
- query , {"id" : id , "file" : (self .file (file_name , data , mime_type ))}
514
- )
534
+ return self .opencti .query (
535
+ query , {"id" : id , "file" : (self .file (final_file_name , data , mime_type ))}
536
+ )
515
537
else :
516
538
self .opencti .log (
517
539
"error" ,
0 commit comments