Skip to content

Commit af09a09

Browse files
committed
added demo.py
1 parent c635275 commit af09a09

File tree

1 file changed

+36
-0
lines changed
  • stix2/datastore/relational_db

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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()

0 commit comments

Comments
 (0)