Skip to content

Commit

Permalink
Move get_access_conditions to _serialize.py (#13105)
Browse files Browse the repository at this point in the history
* refactored get access conditions

* added newline spacing after refactor

* moved the method within serialize

* fixed linter
  • Loading branch information
tasherif-msft authored Aug 14, 2020
1 parent 8ef0bb0 commit 87a6e32
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
get_api_version,
serialize_blob_tags_header,
serialize_blob_tags,
serialize_query_format
serialize_query_format, get_access_conditions
)
from ._deserialize import get_page_ranges_result, deserialize_blob_properties, deserialize_blob_stream, parse_tags
from ._quick_query_helper import BlobQueryReader
Expand All @@ -54,7 +54,7 @@
upload_page_blob)
from ._models import BlobType, BlobBlock, BlobProperties, BlobQueryError
from ._download import StorageStreamDownloader
from ._lease import BlobLeaseClient, get_access_conditions
from ._lease import BlobLeaseClient

if TYPE_CHECKING:
from datetime import datetime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
StorageErrorException,
SignedIdentifier)
from ._deserialize import deserialize_container_properties
from ._serialize import get_modify_conditions, get_container_cpk_scope_info, get_api_version
from ._serialize import get_modify_conditions, get_container_cpk_scope_info, get_api_version, get_access_conditions
from ._models import ( # pylint: disable=unused-import
ContainerProperties,
BlobProperties,
BlobType)
from ._list_blobs_helper import BlobPrefix, BlobPropertiesPaged
from ._lease import BlobLeaseClient, get_access_conditions
from ._lease import BlobLeaseClient
from ._blob_client import BlobClient

if TYPE_CHECKING:
Expand Down
16 changes: 3 additions & 13 deletions sdk/storage/azure-storage-blob/azure/storage/blob/_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,22 @@
import uuid

from typing import ( # pylint: disable=unused-import
Union, Optional, Any, IO, Iterable, AnyStr, Dict, List, Tuple,
TypeVar, TYPE_CHECKING
Union, Optional, Any, TypeVar, TYPE_CHECKING
)

from azure.core.tracing.decorator import distributed_trace

from ._shared.response_handlers import return_response_headers, process_storage_error
from ._generated.models import StorageErrorException, LeaseAccessConditions
from ._generated.models import StorageErrorException
from ._serialize import get_modify_conditions

if TYPE_CHECKING:
from datetime import datetime
from ._generated.operations import BlobOperations, ContainerOperations

BlobClient = TypeVar("BlobClient")
ContainerClient = TypeVar("ContainerClient")


def get_access_conditions(lease):
# type: (Optional[Union[BlobLeaseClient, str]]) -> Union[LeaseAccessConditions, None]
try:
lease_id = lease.id # type: ignore
except AttributeError:
lease_id = lease # type: ignore
return LeaseAccessConditions(lease_id=lease_id) if lease_id else None


class BlobLeaseClient(object):
"""Creates a new BlobLeaseClient.
Expand Down
11 changes: 10 additions & 1 deletion sdk/storage/azure-storage-blob/azure/storage/blob/_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
JsonTextConfiguration,
QueryFormatType,
BlobTag,
BlobTags
BlobTags, LeaseAccessConditions
)


Expand Down Expand Up @@ -63,6 +63,15 @@ def _get_match_headers(kwargs, match_param, etag_param):
return if_match, if_none_match


def get_access_conditions(lease):
# type: (Optional[Union[BlobLeaseClient, str]]) -> Union[LeaseAccessConditions, None]
try:
lease_id = lease.id # type: ignore
except AttributeError:
lease_id = lease # type: ignore
return LeaseAccessConditions(lease_id=lease_id) if lease_id else None


def get_modify_conditions(kwargs):
# type: (Dict[str, Any]) -> ModifiedAccessConditions
if_match, if_none_match = _get_match_headers(kwargs, 'match_condition', 'etag')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .._shared.policies_async import ExponentialRetry
from .._shared.response_handlers import return_response_headers, process_storage_error
from .._deserialize import get_page_ranges_result, parse_tags
from .._serialize import get_modify_conditions, get_api_version
from .._serialize import get_modify_conditions, get_api_version, get_access_conditions
from .._generated import VERSION
from .._generated.aio import AzureBlobStorage
from .._generated.models import StorageErrorException, CpkInfo
Expand All @@ -27,7 +27,6 @@
upload_append_blob,
upload_page_blob)
from .._models import BlobType, BlobBlock, BlobProperties
from .._lease import get_access_conditions
from ._lease_async import BlobLeaseClient
from ._download_async import StorageStreamDownloader

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
StorageErrorException,
SignedIdentifier)
from .._deserialize import deserialize_container_properties
from .._serialize import get_modify_conditions, get_container_cpk_scope_info, get_api_version
from .._serialize import get_modify_conditions, get_container_cpk_scope_info, get_api_version, get_access_conditions
from .._container_client import ContainerClient as ContainerClientBase, _get_blob_name
from .._lease import get_access_conditions
from .._models import ContainerProperties, BlobType, BlobProperties # pylint: disable=unused-import
from ._list_blobs_helper import BlobPropertiesPaged, BlobPrefix
from ._lease_async import BlobLeaseClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get_source_conditions(kwargs):
source_if_none_match=if_none_match or kwargs.pop('source_if_none_match', None)
)


def get_access_conditions(lease):
# type: (Optional[Union[ShareLeaseClient, str]]) -> Union[LeaseAccessConditions, None]
try:
Expand Down

0 comments on commit 87a6e32

Please sign in to comment.