Skip to content

Commit

Permalink
Changes to storage interface to enforce storage types (log2timeline#2939
Browse files Browse the repository at this point in the history
)
  • Loading branch information
joachimmetz authored May 19, 2020
1 parent 8f3ac14 commit a736570
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
35 changes: 28 additions & 7 deletions plaso/storage/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,16 @@ def WriteSessionCompletion(self, session_completion):
session_completion (SessionCompletion): session completion information.
Raises:
IOError: when the storage file is closed or read-only.
OSError: when the storage file is closed or read-only.
IOError: if the storage type does not support writing a session
completion or the storage file is closed or read-only.
OSError: if the storage type does not support writing a session
completion or the storage file is closed or read-only.
"""
self._RaiseIfNotWritable()

if self.storage_type != definitions.STORAGE_TYPE_SESSION:
raise IOError('Session completion not supported by storage type.')

self._WriteAttributeContainer(session_completion)

def WriteSessionStart(self, session_start):
Expand All @@ -459,11 +464,16 @@ def WriteSessionStart(self, session_start):
session_start (SessionStart): session start information.
Raises:
IOError: when the storage file is closed or read-only.
OSError: when the storage file is closed or read-only.
IOError: if the storage type does not support writing a session
start or the storage file is closed or read-only.
OSError: if the storage type does not support writing a session
start or the storage file is closed or read-only.
"""
self._RaiseIfNotWritable()

if self.storage_type != definitions.STORAGE_TYPE_SESSION:
raise IOError('Session start not supported by storage type.')

self._WriteAttributeContainer(session_start)

def WriteTaskCompletion(self, task_completion):
Expand All @@ -473,11 +483,16 @@ def WriteTaskCompletion(self, task_completion):
task_completion (TaskCompletion): task completion information.
Raises:
IOError: when the storage file is closed or read-only.
OSError: when the storage file is closed or read-only.
IOError: if the storage type does not support writing a task
completion or the storage file is closed or read-only.
OSError: if the storage type does not support writing a task
completion or the storage file is closed or read-only.
"""
self._RaiseIfNotWritable()

if self.storage_type != definitions.STORAGE_TYPE_TASK:
raise IOError('Task start not supported by storage type.')

self._WriteAttributeContainer(task_completion)

def WriteTaskStart(self, task_start):
Expand All @@ -487,10 +502,16 @@ def WriteTaskStart(self, task_start):
task_start (TaskStart): task start information.
Raises:
StorageNotReadableError: when the storage file is closed or read-only.
IOError: if the storage type does not support writing a task
start or the storage file is closed or read-only.
OSError: if the storage type does not support writing a task
start or the storage file is closed or read-only.
"""
self._RaiseIfNotWritable()

if self.storage_type != definitions.STORAGE_TYPE_TASK:
raise IOError('Task completion not supported by storage type.')

self._WriteAttributeContainer(task_start)

def _DeserializeAttributeContainer(self, container_type, serialized_data):
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/sqlite/sqlite_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def testWriteSessionStartAndCompletion(self):
with shared_test_lib.TempDirectory() as temp_directory:
temp_file = os.path.join(temp_directory, 'plaso.sqlite')
storage_file = sqlite_file.SQLiteStorageFile(
storage_type=definitions.STORAGE_TYPE_TASK)
storage_type=definitions.STORAGE_TYPE_SESSION)
storage_file.Open(path=temp_file, read_only=False)

storage_file.WriteSessionStart(session_start)
Expand Down

0 comments on commit a736570

Please sign in to comment.