Skip to content

Commit a701a5a

Browse files
committed
Address PR Feedback
1 parent f18650f commit a701a5a

File tree

8 files changed

+40
-26
lines changed

8 files changed

+40
-26
lines changed

key-value/key-value-aio/src/key_value/aio/stores/elasticsearch/store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ class ElasticsearchStore(
138138
139139
Stores collections in their own indices and stores values in Flattened fields.
140140
141-
By default, keys and collections are not sanitized. This means that there are character and length restrictions on
142-
keys and collections that may cause errors when trying to get and put entries.
141+
This store has specific restrictions on what is allowed in keys and collections. Keys and collections are not sanitized
142+
by default which may result in errors when using the store.
143143
144144
To avoid issues, you may want to consider leveraging the `ElasticsearchV1KeySanitizationStrategy` and
145145
`ElasticsearchV1CollectionSanitizationStrategy` strategies.

key-value/key-value-aio/src/key_value/aio/stores/keyring/store.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Python keyring-based key-value store."""
22

3-
43
from key_value.shared.utils.compound import compound_key
54
from key_value.shared.utils.managed_entry import ManagedEntry
65
from key_value.shared.utils.sanitization import HybridSanitizationStrategy, PassthroughStrategy, SanitizationStrategy
@@ -22,7 +21,16 @@
2221
ALLOWED_KEY_COLLECTION_CHARACTERS: str = ALPHANUMERIC_CHARACTERS
2322

2423

25-
class KeyringV1SanitizationStrategy(HybridSanitizationStrategy):
24+
class KeyringV1KeySanitizationStrategy(HybridSanitizationStrategy):
25+
def __init__(self) -> None:
26+
super().__init__(
27+
replacement_character="_",
28+
max_length=MAX_KEY_COLLECTION_LENGTH,
29+
allowed_characters=ALLOWED_KEY_COLLECTION_CHARACTERS,
30+
)
31+
32+
33+
class KeyringV1CollectionSanitizationStrategy(HybridSanitizationStrategy):
2634
def __init__(self) -> None:
2735
super().__init__(
2836
replacement_character="_",
@@ -34,13 +42,14 @@ def __init__(self) -> None:
3442
class KeyringStore(BaseStore):
3543
"""Python keyring-based key-value store using keyring library.
3644
37-
This store uses the Python keyring to persist key-value pairs. Each entry is stored
45+
This store uses the system's keyring to persist key-value pairs. Each entry is stored
3846
as a password in the keychain with the combination of collection and key as the username.
3947
40-
By default, keys and collections are not sanitized. This means that there are character and length restrictions on
41-
keys and collections that may cause errors when trying to get and put entries.
48+
This store has specific restrictions on what is allowed in keys and collections. Keys and collections are not sanitized
49+
by default which may result in errors when using the store.
4250
43-
To avoid issues, you may want to consider leveraging the `KeyringV1SanitizationStrategy` strategy.
51+
To avoid issues, you may want to consider leveraging the `KeyringV1KeySanitizationStrategy`
52+
and `KeyringV1CollectionSanitizationStrategy` strategies.
4453
4554
Note: TTL is not natively supported by Python keyring, so TTL information is stored
4655
within the JSON payload and checked at retrieval time.

key-value/key-value-aio/src/key_value/aio/stores/mongodb/store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from bson.errors import InvalidDocument
66
from key_value.shared.errors import DeserializationError, SerializationError
77
from key_value.shared.utils.managed_entry import ManagedEntry
8-
from key_value.shared.utils.sanitization import HybridSanitizationStrategy, PassthroughStrategy, SanitizationStrategy
8+
from key_value.shared.utils.sanitization import HybridSanitizationStrategy, SanitizationStrategy
99
from key_value.shared.utils.sanitize import ALPHANUMERIC_CHARACTERS
1010
from key_value.shared.utils.serialization import SerializationAdapter
1111
from typing_extensions import Self, override
@@ -200,7 +200,7 @@ def __init__(
200200

201201
super().__init__(
202202
default_collection=default_collection,
203-
collection_sanitization_strategy=collection_sanitization_strategy or PassthroughStrategy(),
203+
collection_sanitization_strategy=collection_sanitization_strategy,
204204
)
205205

206206
@override

key-value/key-value-aio/src/key_value/aio/stores/windows_registry/store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class WindowsRegistryStore(BaseStore):
3939
This store uses the Windows Registry to persist key-value pairs. Each entry is stored
4040
as a string value in the registry under HKEY_CURRENT_USER\\Software\\{root}\\{collection}\\{key}.
4141
42-
By default, keys and collections are not sanitized. This means that there are character and length restrictions on
43-
keys and collections that may cause errors when trying to get and put entries.
42+
This store has specific restrictions on what is allowed in keys and collections. Keys and collections are not sanitized
43+
by default which may result in errors when using the store.
4444
4545
To avoid issues, you may want to consider leveraging the `WindowsRegistryV1SanitizationStrategy` strategy.
4646

key-value/key-value-sync/src/key_value/sync/code_gen/stores/elasticsearch/store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ class ElasticsearchStore(
117117
118118
Stores collections in their own indices and stores values in Flattened fields.
119119
120-
By default, keys and collections are not sanitized. This means that there are character and length restrictions on
121-
keys and collections that may cause errors when trying to get and put entries.
120+
This store has specific restrictions on what is allowed in keys and collections. Keys and collections are not sanitized
121+
by default which may result in errors when using the store.
122122
123123
To avoid issues, you may want to consider leveraging the `ElasticsearchV1KeySanitizationStrategy` and
124124
`ElasticsearchV1CollectionSanitizationStrategy` strategies.

key-value/key-value-sync/src/key_value/sync/code_gen/stores/keyring/store.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@
2424
ALLOWED_KEY_COLLECTION_CHARACTERS: str = ALPHANUMERIC_CHARACTERS
2525

2626

27-
class KeyringV1SanitizationStrategy(HybridSanitizationStrategy):
27+
class KeyringV1KeySanitizationStrategy(HybridSanitizationStrategy):
28+
def __init__(self) -> None:
29+
super().__init__(
30+
replacement_character="_", max_length=MAX_KEY_COLLECTION_LENGTH, allowed_characters=ALLOWED_KEY_COLLECTION_CHARACTERS
31+
)
32+
33+
34+
class KeyringV1CollectionSanitizationStrategy(HybridSanitizationStrategy):
2835
def __init__(self) -> None:
2936
super().__init__(
3037
replacement_character="_", max_length=MAX_KEY_COLLECTION_LENGTH, allowed_characters=ALLOWED_KEY_COLLECTION_CHARACTERS
@@ -34,13 +41,14 @@ def __init__(self) -> None:
3441
class KeyringStore(BaseStore):
3542
"""Python keyring-based key-value store using keyring library.
3643
37-
This store uses the Python keyring to persist key-value pairs. Each entry is stored
44+
This store uses the system's keyring to persist key-value pairs. Each entry is stored
3845
as a password in the keychain with the combination of collection and key as the username.
3946
40-
By default, keys and collections are not sanitized. This means that there are character and length restrictions on
41-
keys and collections that may cause errors when trying to get and put entries.
47+
This store has specific restrictions on what is allowed in keys and collections. Keys and collections are not sanitized
48+
by default which may result in errors when using the store.
4249
43-
To avoid issues, you may want to consider leveraging the `KeyringV1SanitizationStrategy` strategy.
50+
To avoid issues, you may want to consider leveraging the `KeyringV1KeySanitizationStrategy`
51+
and `KeyringV1CollectionSanitizationStrategy` strategies.
4452
4553
Note: TTL is not natively supported by Python keyring, so TTL information is stored
4654
within the JSON payload and checked at retrieval time.

key-value/key-value-sync/src/key_value/sync/code_gen/stores/mongodb/store.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from bson.errors import InvalidDocument
99
from key_value.shared.errors import DeserializationError, SerializationError
1010
from key_value.shared.utils.managed_entry import ManagedEntry
11-
from key_value.shared.utils.sanitization import HybridSanitizationStrategy, PassthroughStrategy, SanitizationStrategy
11+
from key_value.shared.utils.sanitization import HybridSanitizationStrategy, SanitizationStrategy
1212
from key_value.shared.utils.sanitize import ALPHANUMERIC_CHARACTERS
1313
from key_value.shared.utils.serialization import SerializationAdapter
1414
from typing_extensions import Self, override
@@ -196,10 +196,7 @@ def __init__(
196196
self._collections_by_name = {}
197197
self._adapter = MongoDBSerializationAdapter(native_storage=native_storage)
198198

199-
super().__init__(
200-
default_collection=default_collection,
201-
collection_sanitization_strategy=collection_sanitization_strategy or PassthroughStrategy(),
202-
)
199+
super().__init__(default_collection=default_collection, collection_sanitization_strategy=collection_sanitization_strategy)
203200

204201
@override
205202
def __enter__(self) -> Self:

key-value/key-value-sync/src/key_value/sync/code_gen/stores/windows_registry/store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class WindowsRegistryStore(BaseStore):
4545
This store uses the Windows Registry to persist key-value pairs. Each entry is stored
4646
as a string value in the registry under HKEY_CURRENT_USER\\Software\\{root}\\{collection}\\{key}.
4747
48-
By default, keys and collections are not sanitized. This means that there are character and length restrictions on
49-
keys and collections that may cause errors when trying to get and put entries.
48+
This store has specific restrictions on what is allowed in keys and collections. Keys and collections are not sanitized
49+
by default which may result in errors when using the store.
5050
5151
To avoid issues, you may want to consider leveraging the `WindowsRegistryV1SanitizationStrategy` strategy.
5252

0 commit comments

Comments
 (0)