reduce how often list_containers is called (#196)

This commit is contained in:
bmc-msft
2020-10-23 09:43:45 -04:00
committed by GitHub
parent b675ee75df
commit 8a62830f2b
5 changed files with 47 additions and 31 deletions

View File

@ -10,10 +10,20 @@ from typing import Any, Dict, Optional, Union, cast
from azure.common import AzureHttpError, AzureMissingResourceHttpError
from azure.storage.blob import BlobPermissions, ContainerPermissions
from memoization import cached
from .creds import get_blob_service
@cached(ttl=5)
def container_exists(name: str, account_id: Optional[str] = None) -> bool:
try:
get_blob_service(account_id).get_container_properties(name)
return True
except AzureHttpError:
return False
def get_containers(account_id: Optional[str] = None) -> Dict[str, Dict[str, str]]:
return {
x.name: x.metadata
@ -27,8 +37,7 @@ def get_container_metadata(
) -> Optional[Dict[str, str]]:
try:
result = get_blob_service(account_id).get_container_metadata(name)
if result:
return cast(Dict[str, str], result)
return cast(Dict[str, str], result)
except AzureHttpError:
pass
return None