-
Notifications
You must be signed in to change notification settings - Fork 67
Removing confusing field from CosmosDBStorageConfig #377
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,33 +53,41 @@ def __init__(self, config: CosmosDBStorageConfig): | |
| self._lock: asyncio.Lock = asyncio.Lock() | ||
|
|
||
| def _create_client(self) -> CosmosClient: | ||
| if self._config.url: | ||
| if not self._config.credential: | ||
| raise ValueError( | ||
| storage_errors.InvalidConfiguration.format( | ||
| "Credential is required when using a custom service URL" | ||
| ) | ||
|
|
||
| if not self._config.cosmos_db_endpoint: | ||
| raise ValueError( | ||
| storage_errors.InvalidConfiguration.format( | ||
| "Cosmos DB Endpoint is required." | ||
| ) | ||
| return CosmosClient( | ||
| url=self._config.url, credential=self._config.credential | ||
| ) | ||
|
|
||
| connection_policy = self._config.cosmos_client_options.get( | ||
| "connection_policy", documents.ConnectionPolicy() | ||
| ) | ||
| if self._config.credential or self._config.auth_key: | ||
| cred = ( | ||
| self._config.credential | ||
| if self._config.credential | ||
| else self._config.auth_key | ||
| ) | ||
|
|
||
| # kwargs 'connection_verify' is to handle CosmosClient overwriting the | ||
| # ConnectionPolicy.DisableSSLVerification value. | ||
| return CosmosClient( | ||
| self._config.cosmos_db_endpoint, | ||
| self._config.auth_key, | ||
| consistency_level=self._config.cosmos_client_options.get( | ||
| "consistency_level", None | ||
| ), | ||
| **{ | ||
| "connection_policy": connection_policy, | ||
| "connection_verify": not connection_policy.DisableSSLVerification, | ||
| }, | ||
| connection_policy = self._config.cosmos_client_options.get( | ||
| "connection_policy", documents.ConnectionPolicy() | ||
| ) | ||
|
|
||
| return CosmosClient( | ||
| url=self._config.cosmos_db_endpoint, | ||
| credential=cred, | ||
| consistency_level=self._config.cosmos_client_options.get( | ||
| "consistency_level", None | ||
| ), | ||
| **{ | ||
| "connection_policy": connection_policy, | ||
| "connection_verify": not connection_policy.DisableSSLVerification, | ||
| }, | ||
| ) | ||
|
|
||
| raise ValueError( | ||
| storage_errors.InvalidConfiguration.format( | ||
| "Either Cosmos DB Credential or Auth Key is required." | ||
| ) | ||
| ) | ||
|
Comment on lines
+57
to
91
|
||
|
|
||
| def _sanitize(self, key: str) -> str: | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -20,7 +20,6 @@ def __init__( | |||
| container_throughput: int | None = None, | ||||
| key_suffix: str = "", | ||||
| compatibility_mode: bool = False, | ||||
| url: str = "", | ||||
| credential: Union[AsyncTokenCredential, None] = None, | ||||
| **kwargs, | ||||
| ): | ||||
|
|
@@ -37,7 +36,6 @@ def __init__( | |||
| key characters. (e.g. not: '\\', '?', '/', '#', '*') | ||||
| :param compatibility_mode: True if keys should be truncated in order to support previous CosmosDb | ||||
| max key length of 255. | ||||
| :param url: The URL to the CosmosDB resource. | ||||
| :param credential: The TokenCredential to use for authentication. | ||||
| :return CosmosDBConfig: | ||||
|
||||
| :return CosmosDBConfig: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -253,9 +253,9 @@ async def test_cosmos_db_from_azure_cred(self): | |
| load_dotenv() | ||
|
|
||
| cred = DefaultAzureCredential() | ||
| url = os.environ.get("TEST_COSMOS_DB_ENDPOINT") | ||
| url = os.environ.get("TEST_COSMOS_DB_ENDPOINT", "") | ||
| config = CosmosDBStorageConfig( | ||
| url=url, | ||
| cosmos_db_endpoint=url, | ||
| credential=cred, | ||
|
Comment on lines
+256
to
259
|
||
| database_id="test-db", | ||
| container_id="bot-storage", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new missing-endpoint/auth validation uses
storage_errors.InvalidConfiguration(error code -61012), but this package already defines dedicatedCosmosDbEndpointRequired(-61001) andCosmosDbAuthKeyRequired(-61002) messages. Using the dedicated resources would preserve more specific error codes and align with how other required fields are reported (e.g., database_id/container_id).