Skip to content

Commit

Permalink
add implementation for checkpointstoretable (#19905)
Browse files Browse the repository at this point in the history
* add implementation

add the test cases

add the test file

fix test file

* fix pylint

* fix pylint

* fix pylint

* fix pylint

* fix pylint

* fix pylint

* fix pylint

* fix pylint

* fix pylint

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* new update

* Update shared_requirements.txt

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* environment

* redo

* redo

* redo

* changed variable name

* changed variable name

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/tests/test_storage_table_partition_manager.py

Co-authored-by: Sean Kane <68240067+seankane-msft@users.noreply.github.com>

* update on test file

* update on test file

* update on test file

* update based on feedack

* new update

* update

* update

* update

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: chradek <51000525+chradek@users.noreply.github.com>

* new update

* new

* new

* new

* new

* new

* update on spacing

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: chradek <51000525+chradek@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: chradek <51000525+chradek@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: chradek <51000525+chradek@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: chradek <51000525+chradek@users.noreply.github.com>

* new update

* update

* update on test file

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* update

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* update

* update

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/tests/test_storage_table_partition_manager.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/tests/test_storage_table_partition_manager.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* update

* update

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* update

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/tests/test_storage_table_partition_manager.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* update

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/tests/test_storage_table_partition_manager.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* update

* update

* update

* update

* update

* update

* Revert "update"

This reverts commit d2dbb2a.

* update

* update

* update

* newupdate

* update

* update

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/samples/receive_events_using_checkpoint_store.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/setup.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/tests/test_storage_table_partition_manager.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/tests/test_storage_table_partition_manager.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* update

* update

* update

* update

* update

* update

* p

* update

* update

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/tests/test_storage_table_partition_manager.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/tests/test_storage_table_partition_manager.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/tests/test_storage_table_partition_manager.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* Update sdk/eventhub/azure-eventhub-checkpointstoretable/azure/eventhub/extensions/checkpointstoretable/_tablestoragecs.py

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>

* update

* update

* update

Co-authored-by: Josue Garcia <t-jgarcia@microsoft.com>
Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>
Co-authored-by: Sean Kane <68240067+seankane-msft@users.noreply.github.com>
Co-authored-by: chradek <51000525+chradek@users.noreply.github.com>
  • Loading branch information
5 people authored Aug 14, 2021
1 parent e1ecaf0 commit c252444
Show file tree
Hide file tree
Showing 54 changed files with 11,900 additions and 34 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from ._entity import TableEntity, EntityProperty, EdmType
from ._error import RequestTooLargeError, TableTransactionError, TableErrorCode
from ._table_shared_access_signature import generate_table_sas, generate_account_sas
from ._table_client import TableClient
from ._table_service_client import TableServiceClient
from ._models import (
TableAccessPolicy,
TableMetrics,
TableRetentionPolicy,
TableAnalyticsLogging,
TableSasPermissions,
TableCorsRule,
UpdateMode,
SASProtocol,
TableItem,
ResourceTypes,
AccountSasPermissions,
TransactionOperation
)
from ._version import VERSION

__version__ = VERSION

__all__ = [
"TableClient",
"TableServiceClient",
"ResourceTypes",
"AccountSasPermissions",
"TableErrorCode",
"TableSasPermissions",
"TableAccessPolicy",
"TableAnalyticsLogging",
"TableMetrics",
"generate_account_sas",
"TableCorsRule",
"UpdateMode",
"TableItem",
"TableEntity",
"EntityProperty",
"EdmType",
"TableRetentionPolicy",
"generate_table_sas",
"SASProtocol",
"TableTransactionError",
"TransactionOperation",
"RequestTooLargeError",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

import logging
from typing import TYPE_CHECKING

try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse # type: ignore

from azure.core.exceptions import ClientAuthenticationError
from azure.core.pipeline.policies import SansIOHTTPPolicy

try:
from azure.core.pipeline.transport import AsyncHttpTransport
except ImportError:
AsyncHttpTransport = None # type: ignore

try:
from yarl import URL
except ImportError:
pass

from ._common_conversion import (
_sign_string,
)

from ._error import (
_wrap_exception,
)

if TYPE_CHECKING:
from azure.core.pipeline import PipelineRequest # pylint: disable=ungrouped-imports


logger = logging.getLogger(__name__)


class AzureSigningError(ClientAuthenticationError):
"""
Represents a fatal error when attempting to sign a request.
In general, the cause of this exception is user error. For example, the given account key is not valid.
Please visit https://docs.microsoft.com/en-us/azure/storage/common/storage-create-storage-account for more info.
"""


# pylint: disable=no-self-use
class SharedKeyCredentialPolicy(SansIOHTTPPolicy):
def __init__(self, credential, is_emulated=False):
self._credential = credential
self.is_emulated = is_emulated

def _get_headers(self, request, headers_to_sign):
headers = dict(
(name.lower(), value) for name, value in request.headers.items() if value
)
if "content-length" in headers and headers["content-length"] == "0":
del headers["content-length"]
return "\n".join(headers.get(x, "") for x in headers_to_sign) + "\n"

def _get_verb(self, request):
return request.method + "\n"

def _get_canonicalized_resource(self, request):
uri_path = urlparse(request.http_request.url).path
try:
if (
isinstance(request.context.transport, AsyncHttpTransport)
or isinstance(
getattr(request.context.transport, "_transport", None),
AsyncHttpTransport,
)
or isinstance(
getattr(
getattr(request.context.transport, "_transport", None),
"_transport",
None,
),
AsyncHttpTransport,
)
):
uri_path = URL(uri_path)
return "/" + self._credential.named_key.name + str(uri_path)
except TypeError:
pass
return "/" + self._credential.named_key.name + uri_path

def _get_canonicalized_headers(self, request):
string_to_sign = ""
x_ms_headers = []
for name, value in request.headers.items():
if name.startswith("x-ms-"):
x_ms_headers.append((name.lower(), value))
x_ms_headers.sort()
for name, value in x_ms_headers:
if value is not None:
string_to_sign += "".join([name, ":", value, "\n"])
return string_to_sign

def _add_authorization_header(self, request, string_to_sign):
try:
signature = _sign_string(self._credential.named_key.key, string_to_sign)
auth_string = "SharedKey " + self._credential.named_key.name + ":" + signature
request.headers["Authorization"] = auth_string
except Exception as ex:
# Wrap any error that occurred as signing error
# Doing so will clarify/locate the source of problem
raise _wrap_exception(ex, AzureSigningError)

def on_request(self, request):
# type: (PipelineRequest) -> None
self.sign_request(request)

def sign_request(self, request):
string_to_sign = (
self._get_verb(request.http_request)
+ self._get_headers(
request.http_request,
["content-md5", "content-type", "x-ms-date"],
)
+ self._get_canonicalized_resource(request)
+ self._get_canonicalized_resource_query(request.http_request)
)
self._add_authorization_header(request.http_request, string_to_sign)
logger.debug("String_to_sign=%s", string_to_sign)

def _get_canonicalized_resource_query(self, request):
for name, value in request.query.items():
if name == "comp":
return "?comp=" + value
return ""
Loading

0 comments on commit c252444

Please sign in to comment.