mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-16 11:58:09 +00:00
reduce how often list_containers is called (#196)
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user