File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
stix2/datastore/relational_db Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ import datetime as dt
2+
3+ from database_backends .postgres_backend import PostgresBackend
4+ import sys
5+ import json
6+
7+ import stix2
8+ from stix2 .datastore .relational_db .relational_db import RelationalDBStore
9+ import stix2 .properties
10+
11+ # needed so the relational db code knows to create tables for this
12+ from incident import incident , event , task , impact
13+ from identity_contact_information import identity_contact_information
14+ from observed_string import observed_string
15+
16+
17+ def main ():
18+ with open (sys .argv [1 ], "r" ) as f :
19+ bundle = stix2 .parse (json .load (f ), allow_custom = True )
20+ store = RelationalDBStore (
21+ PostgresBackend ("postgresql://localhost/stix-data-sink" , force_recreate = True ),
22+ True ,
23+ None ,
24+ True ,
25+ print_sql = True ,
26+ )
27+
28+ if store .sink .db_backend .database_exists :
29+ for obj in bundle .objects :
30+ store .add (obj )
31+ else :
32+ print ("database does not exist" )
33+
34+
35+ if __name__ == '__main__' :
36+ main ()
You can’t perform that action at this time.
0 commit comments