From 3b52859074ae74ff91271e9373d0621888525ba4 Mon Sep 17 00:00:00 2001 From: Artem Maslov Date: Wed, 10 Apr 2024 14:23:28 +0300 Subject: [PATCH] fix: updated __repr__ to hide account key for AzureLibraryAdapter Update __repr__ to censor sensitive information. Signed-Off By Artem Maslov maslovartem2012@gmail.com. By including this sign-off line I agree to the terms of the Contributor License Agreement --- python/arcticdb/adapters/azure_library_adapter.py | 3 ++- python/tests/integration/arcticdb/test_arctic.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/python/arcticdb/adapters/azure_library_adapter.py b/python/arcticdb/adapters/azure_library_adapter.py index 1f14717953..05d1eee07e 100644 --- a/python/arcticdb/adapters/azure_library_adapter.py +++ b/python/arcticdb/adapters/azure_library_adapter.py @@ -62,7 +62,8 @@ def __init__(self, uri: str, encoding_version: EncodingVersion, *args, **kwargs) super().__init__(uri, self._encoding_version) def __repr__(self): - return "azure(endpoint=%s, container=%s)" % (self._endpoint, self._container) + censored_endpoint = re.sub(r"AccountKey=.+?;", "AccountKey=...;", self._endpoint) + return "azure(endpoint=%s, container=%s)" % (censored_endpoint, self._container) @property def config_library(self): diff --git a/python/tests/integration/arcticdb/test_arctic.py b/python/tests/integration/arcticdb/test_arctic.py index b5a9703409..5feb38e09d 100644 --- a/python/tests/integration/arcticdb/test_arctic.py +++ b/python/tests/integration/arcticdb/test_arctic.py @@ -351,6 +351,12 @@ def test_delete_date_range(arctic_library): assert lib["symbol"].version == 1 +def test_azure_repr_body_censored(arctic_library): + ac_library_repr = repr(arctic_library) + if "AccountKey=" in ac_library_repr: + assert "AccountKey=..." in ac_library_repr.split(";") + + def _test_mongo_repr_body(mongo_storage: MongoDatabase): # The arctic_uri has the PrefixingLibraryAdapterDecorator logic in it, so use mongo_uri ac = Arctic(f"{mongo_storage.mongo_uri}/?maxPoolSize=10")