-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import datetime as dt | ||
|
||
from database_backends.postgres_backend import PostgresBackend | ||
import sys | ||
import json | ||
|
||
import stix2 | ||
from stix2.datastore.relational_db.relational_db import RelationalDBStore | ||
import stix2.properties | ||
|
||
# needed so the relational db code knows to create tables for this | ||
from incident import incident, event, task, impact | ||
from identity_contact_information import identity_contact_information | ||
from observed_string import observed_string | ||
|
||
|
||
def main(): | ||
with open(sys.argv[1], "r") as f: | ||
bundle = stix2.parse(json.load(f), allow_custom=True) | ||
store = RelationalDBStore( | ||
PostgresBackend("postgresql://localhost/stix-data-sink", force_recreate=True), | ||
True, | ||
None, | ||
True, | ||
print_sql=True, | ||
) | ||
|
||
if store.sink.db_backend.database_exists: | ||
for obj in bundle.objects: | ||
store.add(obj) | ||
else: | ||
print("database does not exist") | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |