Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worked on JSON serializer helper #66

Merged
merged 2 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion acstore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
to read and write plaso storage files.
"""

__version__ = '20240406'
__version__ = '20240407'
28 changes: 18 additions & 10 deletions acstore/helpers/json_serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""Attribute container JSON serializer."""

from acstore.containers import interface as containers_interface
from acstore.containers import manager as containers_manager
from acstore.helpers import schema as schema_helper

Expand Down Expand Up @@ -45,11 +46,14 @@ def ConvertAttributeContainerToJSON(cls, attribute_container):

for attribute_name, attribute_value in attribute_container.GetAttributes():
data_type = schema.get(attribute_name, None)
serializer = schema_helper.SchemaHelper.GetAttributeSerializer(
data_type, 'json')

if serializer:
attribute_value = serializer.SerializeValue(attribute_value)
if data_type == 'AttributeContainerIdentifier' and isinstance(
attribute_value, containers_interface.AttributeContainerIdentifier):
attribute_value = attribute_value.CopyToString()
else:
serializer = schema_helper.SchemaHelper.GetAttributeSerializer(
data_type, 'json')
if serializer:
attribute_value = serializer.SerializeValue(attribute_value)

# JSON will not serialize certain runtime types like set, therefore
# these are cast to list first.
Expand Down Expand Up @@ -104,11 +108,15 @@ def ConvertJSONToAttributeContainer(cls, json_dict):
continue

data_type = schema.get(attribute_name, None)
serializer = schema_helper.SchemaHelper.GetAttributeSerializer(
data_type, 'json')

if serializer:
attribute_value = serializer.DeserializeValue(attribute_value)
if data_type == 'AttributeContainerIdentifier':
identifier = containers_interface.AttributeContainerIdentifier()
identifier.CopyFromString(attribute_value)
attribute_value = identifier
else:
serializer = schema_helper.SchemaHelper.GetAttributeSerializer(
data_type, 'json')
if serializer:
attribute_value = serializer.DeserializeValue(attribute_value)

setattr(attribute_container, attribute_name, attribute_value)

Expand Down
14 changes: 3 additions & 11 deletions acstore/sqlite_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,15 @@ class SQLiteAttributeContainerStore(

# The earliest format version, stored in-file, that this class
# is able to append (write).
_APPEND_COMPATIBLE_FORMAT_VERSION = 20221023
_APPEND_COMPATIBLE_FORMAT_VERSION = 20230312

# The earliest format version, stored in-file, that this class
# is able to upgrade (write new format features).
_UPGRADE_COMPATIBLE_FORMAT_VERSION = 20221023
_UPGRADE_COMPATIBLE_FORMAT_VERSION = 20230312

# The earliest format version, stored in-file, that this class
# is able to read.
_READ_COMPATIBLE_FORMAT_VERSION = 20221023

# TODO: kept for backwards compatibility.
_CONTAINER_SCHEMA_TO_SQLITE_TYPE_MAPPINGS = {
'AttributeContainerIdentifier': 'TEXT',
'bool': 'INTEGER',
'int': 'INTEGER',
'str': 'TEXT',
'timestamp': 'BIGINT'}
_READ_COMPATIBLE_FORMAT_VERSION = 20230312

_CREATE_METADATA_TABLE_QUERY = (
'CREATE TABLE metadata (key TEXT, value TEXT);')
Expand Down
4 changes: 2 additions & 2 deletions config/dpkg/changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
acstore (20240406-1) unstable; urgency=low
acstore (20240407-1) unstable; urgency=low

* Auto-generated

-- Log2Timeline maintainers <[email protected]> Sat, 06 Apr 2024 05:54:23 +0200
-- Log2Timeline maintainers <[email protected]> Sun, 07 Apr 2024 07:12:15 +0200
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = acstore
version = 20240406
version = 20240407
description = Attribute Container Storage (ACStore).
long_description = ACStore, or Attribute Container Storage, provides a stand-alone implementation to read and write attribute container storage files.
long_description_content_type = text/plain
Expand Down
Loading