Skip to content

Commit

Permalink
Renamed SQLite-base storage reader and writer (log2timeline#4856)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz authored Mar 30, 2024
1 parent 48f7670 commit a7719c1
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 38 deletions.
8 changes: 6 additions & 2 deletions plaso/lib/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@
STORAGE_FORMAT_SQLITE = 'sqlite'
STORAGE_FORMAT_REDIS = 'redis'

SESSION_STORAGE_FORMATS = frozenset([STORAGE_FORMAT_SQLITE])
TASK_STORAGE_FORMATS = frozenset([STORAGE_FORMAT_SQLITE, STORAGE_FORMAT_REDIS])
SESSION_STORAGE_FORMATS = frozenset([
STORAGE_FORMAT_SQLITE])

TASK_STORAGE_FORMATS = frozenset([
STORAGE_FORMAT_SQLITE,
STORAGE_FORMAT_REDIS])

DEFAULT_STORAGE_FORMAT = STORAGE_FORMAT_SQLITE

Expand Down
10 changes: 5 additions & 5 deletions plaso/storage/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def CreateStorageReaderForFile(cls, path):
opened or the storage format is not supported.
"""
if sqlite_file.SQLiteStorageFile.CheckSupportedFormat(path):
return sqlite_reader.SQLiteStorageFileReader(path)
return sqlite_reader.SQLiteStorageReader(path)

return None

Expand All @@ -62,7 +62,7 @@ def CreateStorageWriter(cls, storage_format):
opened or the storage format is not supported.
"""
if storage_format == definitions.STORAGE_FORMAT_SQLITE:
return sqlite_writer.SQLiteStorageFileWriter()
return sqlite_writer.SQLiteStorageWriter()

if storage_format == definitions.STORAGE_FORMAT_REDIS and redis_writer:
return redis_writer.RedisStorageWriter()
Expand All @@ -81,7 +81,7 @@ def CreateStorageWriterForFile(cls, path):
opened or the storage format is not supported.
"""
if sqlite_file.SQLiteStorageFile.CheckSupportedFormat(path):
return sqlite_writer.SQLiteStorageFileWriter()
return sqlite_writer.SQLiteStorageWriter()

return None

Expand All @@ -99,7 +99,7 @@ def CreateTaskStorageReader(cls, storage_format, task, path):
opened or the storage format is not supported.
"""
if storage_format == definitions.STORAGE_FORMAT_SQLITE:
return sqlite_reader.SQLiteStorageFileReader(path)
return sqlite_reader.SQLiteStorageReader(path)

if storage_format == definitions.STORAGE_FORMAT_REDIS and redis_reader:
return redis_reader.RedisStorageReader(
Expand All @@ -119,7 +119,7 @@ def CreateTaskStorageWriter(cls, storage_format):
opened or the storage format is not supported.
"""
if storage_format == definitions.STORAGE_FORMAT_SQLITE:
return sqlite_writer.SQLiteStorageFileWriter(
return sqlite_writer.SQLiteStorageWriter(
storage_type=definitions.STORAGE_TYPE_TASK)

if storage_format == definitions.STORAGE_FORMAT_REDIS and redis_writer:
Expand Down
6 changes: 3 additions & 3 deletions plaso/storage/redis/reader.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-
"""Redis storage reader."""
"""Redis-based storage reader."""

from plaso.storage import reader
from plaso.storage.redis import redis_store


class RedisStorageReader(reader.StorageReader):
"""Redis storage file reader."""
"""Redis-based storage reader."""

def __init__(self, session_identifier, task_identifier, redis_client=None):
"""Initializes a Redis storage reader.
"""Initializes a storage reader.
Args:
session_identifier (str): session identifier.
Expand Down
2 changes: 1 addition & 1 deletion plaso/storage/redis/writer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""Storage writer for Redis."""
"""Redis-based storage writer."""

from plaso.storage import writer
from plaso.storage.redis import redis_store
Expand Down
12 changes: 6 additions & 6 deletions plaso/storage/sqlite/reader.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# -*- coding: utf-8 -*-
"""SQLite-based storage file reader."""
"""SQLite-based storage reader."""

from plaso.storage import reader
from plaso.storage.sqlite import sqlite_file


class SQLiteStorageFileReader(reader.StorageReader):
"""SQLite-based storage file reader."""
class SQLiteStorageReader(reader.StorageReader):
"""SQLite-based storage reader."""

def __init__(self, path):
"""Initializes a SQLite-based file storage reader.
"""Initializes a storage reader.
Args:
path (str): path to the input file.
path (str): path to the input SQLite database.
"""
super(SQLiteStorageFileReader, self).__init__()
super(SQLiteStorageReader, self).__init__()
self._path = path
self._store = sqlite_file.SQLiteStorageFile()
self._store.Open(path=path)
10 changes: 5 additions & 5 deletions plaso/storage/sqlite/writer.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# -*- coding: utf-8 -*-
"""Storage writer for SQLite storage files."""
"""SQLite-based storage writer."""

from plaso.lib import definitions
from plaso.storage import writer
from plaso.storage.sqlite import sqlite_file


class SQLiteStorageFileWriter(writer.StorageWriter):
"""SQLite-based storage file writer."""
class SQLiteStorageWriter(writer.StorageWriter):
"""SQLite-based storage writer."""

def __init__(self, storage_type=definitions.STORAGE_TYPE_SESSION):
"""Initializes a storage writer.
Args:
storage_type (Optional[str]): storage type.
"""
super(SQLiteStorageFileWriter, self).__init__()
super(SQLiteStorageWriter, self).__init__()
self._first_written_event_data_index = 0
self._first_written_event_source_index = 0
self._written_event_data_index = 0
Expand Down Expand Up @@ -112,7 +112,7 @@ def Open(self, path=None, **unused_kwargs):
"""Opens the storage writer.
Args:
path (Optional[str]): path to the output file.
path (Optional[str]): path to the output SQLite database.
Raises:
IOError: if the storage writer is already opened.
Expand Down
2 changes: 1 addition & 1 deletion tests/multi_process/extraction_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def testProcessSource(self):

with shared_test_lib.TempDirectory() as temp_directory:
temp_file = os.path.join(temp_directory, 'storage.plaso')
storage_writer = sqlite_writer.SQLiteStorageFileWriter()
storage_writer = sqlite_writer.SQLiteStorageWriter()
storage_writer.Open(path=temp_file)

try:
Expand Down
4 changes: 2 additions & 2 deletions tests/storage/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def testCreateStorageReaderForFile(self):

storage_reader = factory.StorageFactory.CreateStorageReaderForFile(
test_file_path)
self.assertIsInstance(storage_reader, sqlite_reader.SQLiteStorageFileReader)
self.assertIsInstance(storage_reader, sqlite_reader.SQLiteStorageReader)

def testCreateStorageWriterForFile(self):
"""Test the CreateStorageWriterForFile function."""
Expand All @@ -30,7 +30,7 @@ def testCreateStorageWriterForFile(self):

storage_reader = factory.StorageFactory.CreateStorageWriterForFile(
test_file_path)
self.assertIsInstance(storage_reader, sqlite_writer.SQLiteStorageFileWriter)
self.assertIsInstance(storage_reader, sqlite_writer.SQLiteStorageWriter)


if __name__ == '__main__':
Expand Down
8 changes: 4 additions & 4 deletions tests/storage/sqlite/reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Tests for the SQLite-based storage file reader."""
"""Tests for the SQLite-based storage reader."""

import unittest

Expand All @@ -9,13 +9,13 @@
from tests.storage import test_lib


class SQLiteStorageFileReaderTest(test_lib.StorageTestCase):
"""Tests for the SQLite-based storage file reader."""
class SQLiteStorageReaderTest(test_lib.StorageTestCase):
"""Tests for the SQLite-based storage reader."""

def testInitialization(self):
"""Tests the __init__ function."""
test_path = self._GetTestFilePath(['pinfo_test.plaso'])
test_reader = reader.SQLiteStorageFileReader(test_path)
test_reader = reader.SQLiteStorageReader(test_path)
self.assertIsNotNone(test_reader)


Expand Down
18 changes: 9 additions & 9 deletions tests/storage/sqlite/writer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Tests for the fake storage writer."""
"""Tests for the SQLite-based storage writer."""

import os
import unittest
Expand All @@ -14,16 +14,16 @@
from tests.containers import test_lib as containers_test_lib


class SQLiteStorageFileWriterTest(test_lib.StorageTestCase):
"""Tests for the fake storage writer."""
class SQLiteStorageWriterTest(test_lib.StorageTestCase):
"""Tests for the SQLite-based storage writer."""

# pylint: disable=protected-access

def _AddTestEvents(self, storage_writer):
"""Adds tests events to the storage writer.
Args:
storage_writer (SQLiteStorageFileWriter): storage writer.
storage_writer (SQLiteStorageWriter): storage writer.
Returns:
list[EventObject]: test events.
Expand All @@ -49,7 +49,7 @@ def testAddAttributeContainer(self):

with shared_test_lib.TempDirectory() as temp_directory:
test_path = os.path.join(temp_directory, 'plaso.sqlite')
storage_writer = sqlite_writer.SQLiteStorageFileWriter()
storage_writer = sqlite_writer.SQLiteStorageWriter()
storage_writer.Open(path=test_path)

try:
Expand All @@ -73,7 +73,7 @@ def testAddOrUpdateEventTag(self):
"""Tests the AddOrUpdateEventTag function."""
with shared_test_lib.TempDirectory() as temp_directory:
test_path = os.path.join(temp_directory, 'plaso.sqlite')
storage_writer = sqlite_writer.SQLiteStorageFileWriter()
storage_writer = sqlite_writer.SQLiteStorageWriter()
storage_writer.Open(path=test_path)

try:
Expand Down Expand Up @@ -134,7 +134,7 @@ def testGetSortedEvents(self):
"""Tests the GetSortedEvents function."""
with shared_test_lib.TempDirectory() as temp_directory:
test_path = os.path.join(temp_directory, 'plaso.sqlite')
storage_writer = sqlite_writer.SQLiteStorageFileWriter()
storage_writer = sqlite_writer.SQLiteStorageWriter()
storage_writer.Open(path=test_path)

try:
Expand All @@ -152,14 +152,14 @@ def testOpenClose(self):
"""Tests the Open and Close functions."""
with shared_test_lib.TempDirectory() as temp_directory:
test_path = os.path.join(temp_directory, 'plaso.sqlite')
storage_writer = sqlite_writer.SQLiteStorageFileWriter()
storage_writer = sqlite_writer.SQLiteStorageWriter()
storage_writer.Open(path=test_path)
storage_writer.Close()

storage_writer.Open(path=test_path)
storage_writer.Close()

storage_writer = sqlite_writer.SQLiteStorageFileWriter(
storage_writer = sqlite_writer.SQLiteStorageWriter(
storage_type=definitions.STORAGE_TYPE_TASK)
storage_writer.Open(path=test_path)
storage_writer.Close()
Expand Down

0 comments on commit a7719c1

Please sign in to comment.