Skip to content

Commit 007cc49

Browse files
committed
4.3 Release
1 parent cdb289b commit 007cc49

File tree

198 files changed

+3702
-2696
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+3702
-2696
lines changed

conversion/conversion.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
This directory contains scripts for migrating data from version 3 of SCOT to version 4. They are grouped into three categories: database migrations, file migrations, and extra (optional) migrations. Three bash shell scripts have been provided for you to run the applicable migrations in each category.
44

5+
## Necessary tools to run conversion
6+
You will need the following installed to run conversions:
7+
- python 3.11 with the contents of requirements-test.txt from this repo installed via pip
8+
- mysql-shell
9+
510
## Database Conversion
611
This set of scripts migrates the core database data to the SCOT4 database by pulling data directly from the SCOT3 mongodb database. Almost all SCOT3 installations migrating to SCOT4 will want to do this. The `database_conversion.sh` script will run all of the necessary scripts for you.
712

@@ -45,4 +50,4 @@ The following environment variables should be set when running `file_conversion.
4550
- SCOT_ADMIN_APIKEY - a SCOT4 API key with admin priveleges (see above for one way to create one)
4651
- SCOT3_FILE_PREFIX (needed for file migration) - the directory under which the files were stored in the SCOT3 database, this defaults to the default in SCOT3, which was `/opt/scotfiles/`
4752
- SCOT_FILES_DIR (needed for file migration) - the directory on the current machine in which the old SCOT3 files are stored (with the same file structure that the SCOT3 installation had)
48-
- SCOT_CACHED_IMAGES_DIR (needed for cached images migration) - the directory on the current machine that contains the SCOT3 cached images in their original file structure (this is usually the /cached_images/ directory in the SCOT3 files)
53+
- SCOT_CACHED_IMAGES_DIR (needed for cached images migration) - the directory on the current machine that contains the SCOT3 cached images in their original file structure (this is usually the /cached_images/ directory in the SCOT3 files)

conversion/database_migration/bulk_entries.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ def main(mongo_db=None, role_lookup=None):
7373
with tqdm.tqdm(total=scot3_entry_count) as pbar:
7474
bulk_array = []
7575
for entry in scot3_entries:
76+
if entry.get('target') is None or entry['target'].get('type') is None:
77+
pbar.update(1) # Malformed data
78+
continue
7679
if entry['target']['type'] == 'alert' or entry['target']['type'] == 'alertgroup' or entry['target']['type'] == 'feed':
7780
pbar.update(1)
7881
continue

conversion/database_migration/bulk_links.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def main(mongo_db=None):
1414
scot3_links = mongo_db.link.find()
1515
with tqdm.tqdm(total=scot3_link_count) as pbar:
1616
for link in scot3_links:
17+
if link.get('vertices') is None:
18+
pbar.update(1)
19+
continue
1720
if type(link.get('when')) is int:
1821
new_link = [ datetime.fromtimestamp(link['when']).astimezone(timezone.utc).replace(tzinfo=None), datetime.fromtimestamp(0).astimezone(timezone.utc).replace(tzinfo=None), link['id'], link['vertices'][1]['type'], link['vertices'][1]['id'], link['vertices'][0]['type'], link['vertices'][0]['id']]
1922
else:

conversion/database_migration/bulk_roles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def main(mongo_db=None):
2828
for count, role in enumerate(tqdm.tqdm(unique_roles)):
2929
if role == '':
3030
continue
31-
role_row = [count+2, role, 'migrated from SCOT3', datetime.fromtimestamp(0).astimezone(timezone.utc).replace(tzinfo=None), datetime.fromtimestamp(0).astimezone(timezone.utc).replace(tzinfo=None)] #Using an offset of 3 since we have two default groups: admin and everyone, created by default and taking up role ids 1 & 2 respectively
31+
role_row = [count+3, role, 'migrated from SCOT3', datetime.fromtimestamp(0).astimezone(timezone.utc).replace(tzinfo=None), datetime.fromtimestamp(0).astimezone(timezone.utc).replace(tzinfo=None)] #Using an offset of 3 since we have two default groups: admin and everyone, created by default and taking up role ids 1 & 2 respectively
3232
writer.writerow(role_row)
33-
role_lookup[role] = count+2
33+
role_lookup[role] = count+3
3434

3535
return role_lookup
3636

conversion/database_migration/conversion_utilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ def write_tag_source_links(thing=None, thing_type=None, tag_lookup=None, source_
2222
if thing_type == "signature":
2323
# Check if reference ID exists here
2424
target_data = thing.get('data').get('target')
25-
if target_data is not None:
25+
if target_data is not None and target_data.get('type') is not None and target_data.get('id') is not None:
2626
new_link = [thing_type, thing.get('id'), target_data['type'], target_data['id']]
2727
link_csv_writer.writerow(new_link)

conversion/database_migration/initial_scot4_database.sql

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ CREATE TABLE `auth_settings` (
271271
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
272272
/*!40101 SET character_set_client = @saved_cs_client */;
273273

274+
LOCK TABLES `auth_settings` WRITE;
275+
INSERT INTO `auth_settings` VALUES (1, 'local', '{}', 1, '2023-06-06 16:53:27','2023-06-06 16:53:27');
276+
UNLOCK TABLES;
277+
274278
--
275279
-- Table structure for table `auth_storage`
276280
--
@@ -840,9 +844,9 @@ LOCK TABLES `links` WRITE;
840844
/*!40000 ALTER TABLE `links` ENABLE KEYS */;
841845
UNLOCK TABLES;
842846

843-
---
844-
--- Table structure for table `metrics`
845-
---
847+
--
848+
-- Table structure for table `metrics`
849+
--
846850

847851
DROP TABLE IF EXISTS `metrics`;
848852
/*!40101 SET @saved_cs_client = @@character_set_client */;

conversion/database_migration/scot3_scot4_tsv_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@
7474
util.import_table(f"{staging_directory}/entity_class_associations.csv", {"table": "entity_class_entity_association", "columns": ['entity_id', 'entity_class_id'], "dialect": "tsv", 'fieldsEscapedBy': '\t', 'fieldsEnclosedBy': "'", 'fieldsEscapedBy': '\0', 'linesTerminatedBy': "\n", "skipRows": 1, "showProgress": True})
7575

7676
if os.path.isfile("./games.csv"):
77-
util.import_table("./games.csv", { "table": "games", "columns": [], "dialect": "tsv", 'fieldsEscapedBy': '\t', 'fieldsEnclosedBy': "'", 'fieldsEscapedBy': '\0', 'linesTerminatedBy': "\n", "skipRows": 1, "showProgress": True})
77+
util.import_table("./games.csv", { "table": "games", "columns": ["game_id", "game_name", "tooltip", "results", "created_date", "modified_date"], "dialect": "tsv", 'fieldsEscapedBy': '\t', 'fieldsEnclosedBy': "'", 'fieldsEscapedBy': '\0', 'linesTerminatedBy': "\n", "skipRows": 1, "showProgress": True})

conversion/extra_migration/update_admin_password_and_api_key.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def main(db_session):
88
new_admin_apikey = os.getenv('SCOT_ADMIN_APIKEY')
99
db_obj = db_session.query(User).filter(User.username=='scot-admin').one_or_none()
1010
if new_admin_pw:
11-
update_dict={'username':'scot-admin', 'password':os.environ['SCOT_ADMIN_PASSWORD'])
11+
update_dict={'username':'scot-admin', 'password':os.environ['SCOT_ADMIN_PASSWORD']}
1212
crud.user.update(db_session=db_session, db_obj=db_obj, obj_in=update_dict)
1313
else:
1414
print('SCOT_ADMIN_PASSWORD not set, not resetting scot-admin password')

conversion/file_migration/migrate_cached_images.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import pathlib
1010
import re
1111
import urllib3
12+
13+
from app.db.session import SessionLocal
14+
from app.models import Entry
1215
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
1316

1417
def rewrite_cached_images(html, flaired_html, entry_id):

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ tqdm==4.66.5
77
pymongo==4.8.0
88
splunk-sdk==2.0.2
99
pytest-xdist==3.6.1
10+
Faker==27.0.0
1011
-r requirements.txt

0 commit comments

Comments
 (0)