From f53bf8b1893ed1742edbfcea72f2ef776e056b0b Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Sat, 6 Apr 2024 05:57:09 +0200 Subject: [PATCH] Worked on JSON serializer helper --- .github/workflows/test_docker.yml | 31 ++++++++++-------------------- acstore/__init__.py | 2 +- acstore/helpers/json_serializer.py | 12 ++++++++++++ acstore/sqlite_store.py | 6 +++--- config/dpkg/changelog | 4 ++-- setup.cfg | 2 +- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index 18f021c..31fb5cd 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -18,7 +18,7 @@ jobs: - name: Install dependencies run: | dnf copr -y enable @gift/dev - dnf install -y @development-tools python3 python3-devel python3-pyyaml python3-setuptools + dnf install -y @development-tools python3 python3-build python3-devel python3-pyyaml python3-setuptools python3-wheel - name: Run tests env: LANG: C.utf8 @@ -27,16 +27,12 @@ jobs: - name: Run end-to-end tests run: | if test -f tests/end-to-end.py; then PYTHONPATH=. python3 ./tests/end-to-end.py --debug -c config/end-to-end.ini; fi - - name: Build source distribution + - name: Build source distribution (sdist) run: | - python3 ./setup.py sdist - - name: Build binary distribution + python3 -m build --no-isolation --sdist + - name: Build binary distribution (wheel) run: | - python3 ./setup.py bdist - - name: Run build and install test - run: | - python3 ./setup.py build - python3 ./setup.py install + python3 -m build --no-isolation --wheel test_ubuntu: runs-on: ubuntu-latest strategy: @@ -58,7 +54,7 @@ jobs: run: | add-apt-repository -y ppa:gift/dev apt-get update -q - apt-get install -y build-essential python3 python3-dev python3-distutils python3-pip python3-setuptools python3-wheel python3-yaml + apt-get install -y build-essential python3 python3-build python3-dev python3-distutils python3-pip python3-setuptools python3-wheel python3-yaml - name: Run tests env: LANG: en_US.UTF-8 @@ -69,16 +65,9 @@ jobs: LANG: en_US.UTF-8 run: | if test -f tests/end-to-end.py; then PYTHONPATH=. python3 ./tests/end-to-end.py --debug -c config/end-to-end.ini; fi - - name: Update setuptools - run: | - python3 -m pip install -U setuptools - - name: Build source distribution - run: | - python3 ./setup.py sdist - - name: Build binary distribution + - name: Build source distribution (sdist) run: | - python3 ./setup.py bdist - - name: Run build and install test + python3 -m build --no-isolation --sdist + - name: Build binary distribution (wheel) run: | - python3 ./setup.py build - python3 ./setup.py install + python3 -m build --no-isolation --wheel diff --git a/acstore/__init__.py b/acstore/__init__.py index 35d2d69..523f88a 100644 --- a/acstore/__init__.py +++ b/acstore/__init__.py @@ -5,4 +5,4 @@ to read and write plaso storage files. """ -__version__ = '20240316' +__version__ = '20240406' diff --git a/acstore/helpers/json_serializer.py b/acstore/helpers/json_serializer.py index 287d8de..2632aad 100644 --- a/acstore/helpers/json_serializer.py +++ b/acstore/helpers/json_serializer.py @@ -89,6 +89,11 @@ def ConvertJSONToAttributeContainer(cls, json_dict): attribute_container = cls._CONTAINERS_MANAGER.CreateAttributeContainer( container_type) + try: + schema = cls._CONTAINERS_MANAGER.GetSchema(container_type) + except ValueError: + schema = {} + supported_attribute_names = attribute_container.GetAttributeNames() for attribute_name, attribute_value in json_dict.items(): if attribute_name in ('__container_type__', '__type__'): @@ -98,6 +103,13 @@ def ConvertJSONToAttributeContainer(cls, json_dict): if attribute_name not in supported_attribute_names: continue + data_type = schema.get(attribute_name, None) + serializer = schema_helper.SchemaHelper.GetAttributeSerializer( + data_type, 'json') + + if serializer: + attribute_value = serializer.DeserializeValue(attribute_value) + setattr(attribute_container, attribute_name, attribute_value) return attribute_container diff --git a/acstore/sqlite_store.py b/acstore/sqlite_store.py index 68c59a0..6891de6 100644 --- a/acstore/sqlite_store.py +++ b/acstore/sqlite_store.py @@ -666,7 +666,7 @@ def _WriteExistingAttributeContainer(self, container): f'Unsupported attribute container type: {container.CONTAINER_TYPE:s}') column_names = [] - values = [] + row_values = [] for name, data_type in sorted(schema.items()): attribute_value = getattr(container, name, None) try: @@ -679,7 +679,7 @@ def _WriteExistingAttributeContainer(self, container): f'{data_type:s}')) column_names.append(f'{name:s} = ?') - values.append(row_value) + row_values.append(row_value) column_names_string = ', '.join(column_names) @@ -690,7 +690,7 @@ def _WriteExistingAttributeContainer(self, container): self._storage_profiler.StartTiming('write_existing') try: - self._cursor.execute(query, values) + self._cursor.execute(query, row_values) except (sqlite3.InterfaceError, sqlite3.OperationalError) as exception: raise IOError(( diff --git a/config/dpkg/changelog b/config/dpkg/changelog index cad2777..71fbb16 100644 --- a/config/dpkg/changelog +++ b/config/dpkg/changelog @@ -1,5 +1,5 @@ -acstore (20240316-1) unstable; urgency=low +acstore (20240406-1) unstable; urgency=low * Auto-generated - -- Log2Timeline maintainers Sat, 16 Mar 2024 22:45:43 +0100 + -- Log2Timeline maintainers Sat, 06 Apr 2024 05:54:23 +0200 diff --git a/setup.cfg b/setup.cfg index cdfea02..59b1cfb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = acstore -version = 20240316 +version = 20240406 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