Disable storageclient logs when setting admins (#1304)

This commit is contained in:
Cheick Keita
2021-10-01 11:36:04 -07:00
committed by GitHub
parent 1c497fcd52
commit 3264ddd175
2 changed files with 25 additions and 2 deletions

View File

@ -562,12 +562,14 @@ class Client:
)
def apply_migrations(self) -> None:
logger.info("applying database migrations")
name = self.results["deploy"]["func-name"]["value"]
key = self.results["deploy"]["func-key"]["value"]
table_service = TableService(account_name=name, account_key=key)
migrate(table_service, self.migrations)
def set_instance_config(self) -> None:
logger.info("setting instance config")
name = self.results["deploy"]["func-name"]["value"]
key = self.results["deploy"]["func-key"]["value"]
tenant = UUID(self.results["deploy"]["tenant_id"]["value"])

View File

@ -5,6 +5,7 @@
import argparse
import json
import logging
from typing import List, Optional
from uuid import UUID
@ -12,12 +13,32 @@ from azure.common.client_factory import get_client_from_cli_profile
from azure.cosmosdb.table.tableservice import TableService
from azure.mgmt.storage import StorageManagementClient
storage_client_logger = logging.getLogger("azure.cosmosdb.table.common.storageclient")
TABLE_NAME = "InstanceConfig"
## Disable logging from storageclient. This module displays an error message
## when a resource is not found even if the exception is raised and handled internally.
## This happen when a table does not exist. An error message is displayed but the exception is
## handled by the library.
def disable_storage_client_logging() -> None:
if storage_client_logger:
storage_client_logger.disabled = True
def enable_storage_client_logging() -> None:
if storage_client_logger:
storage_client_logger.disabled = False
def create_if_missing(table_service: TableService) -> None:
try:
disable_storage_client_logging()
if not table_service.exists(TABLE_NAME):
table_service.create_table(TABLE_NAME)
finally:
enable_storage_client_logging()
def update_allowed_aad_tenants(