Esempio n. 1
0
 async def delete_entity(
         self,
         partition_key,  # type: str
         row_key,  # type: str
         **kwargs  # type: Any
 ):
     # type: (...) -> None
     """Deletes the specified entity in a table.
     :param partition_key: The partition key of the entity.
     :type partition_key: str
     :param row_key: The row key of the entity.
     :type row_key: str
     :keyword str etag: Etag of the entity
     :keyword  ~azure.core.MatchConditions match_condition: MatchCondition
     :return: None
     :rtype: None
     :raises: ~azure.core.exceptions.HttpResponseError
     """
     if_match, if_not_match = _get_match_headers(
         kwargs=dict(kwargs,
                     etag=kwargs.pop('etag', None),
                     match_condition=kwargs.pop('match_condition', None)),
         etag_param='etag',
         match_param='match_condition')
     try:
         await self._client.table.delete_entity(table=self.table_name,
                                                partition_key=partition_key,
                                                row_key=row_key,
                                                if_match=if_match
                                                or if_not_match or '*',
                                                **kwargs)
     except HttpResponseError as error:
         process_table_error(error)
Esempio n. 2
0
    async def set_table_access_policy(
            self,
            signed_identifiers,  # type: dict[str,AccessPolicy]
            **kwargs):
        # type: (...) -> None
        """Sets stored access policies for the table that may be used with Shared Access Signatures.

        :param signed_identifiers:
        :type signed_identifiers: dict[str,AccessPolicy]
        :return: None
        :rtype: None
        :raises: ~azure.core.exceptions.HttpResponseError
        """
        self._validate_signed_identifiers(signed_identifiers)
        identifiers = []
        for key, value in signed_identifiers.items():
            if value:
                value.start = serialize_iso(value.start)
                value.expiry = serialize_iso(value.expiry)
            identifiers.append(SignedIdentifier(id=key, access_policy=value))
        signed_identifiers = identifiers  # type: ignore
        try:
            await self._client.table.set_access_policy(
                table=self.table_name,
                table_acl=signed_identifiers or None,
                **kwargs)
        except HttpResponseError as error:
            process_table_error(error)
Esempio n. 3
0
 async def get_entity(
         self,
         partition_key,  # type: str
         row_key,  # type: str
         **kwargs  # type: Any
 ):
     # type: (...) -> TableEntity
     """Queries entities in a table.
     :param partition_key: The partition key of the entity.
     :type partition_key: str
     :param row_key: The row key of the entity.
     :type row_key: str
     :return: TableEntity mapping str to azure.data.tables.EntityProperty
     :rtype: ~azure.data.tables.TableEntity
     :raises: ~azure.core.exceptions.HttpResponseError
     """
     try:
         entity = await self._client.table.query_entities_with_partition_and_row_key(
             table=self.table_name,
             partition_key=partition_key,
             row_key=row_key,
             **kwargs)
         properties = _convert_to_entity(entity.additional_properties)
         return properties
     except HttpResponseError as error:
         process_table_error(error)
Esempio n. 4
0
    async def create_entity(
            self,
            entity,  # type: Union[TableEntity, dict[str,str]]
            **kwargs  # type: Any
    ):
        # type: (...) -> TableEntity
        """Insert entity in a table.
        :param entity: The properties for the table entity.
        :type entity: dict[str, str]
        :return: TableEntity mapping str to azure.data.tables.EntityProperty
        :rtype: ~azure.data.tables.TableEntity
        :raises: ~azure.core.exceptions.HttpResponseError
        """

        if entity:
            if "PartitionKey" in entity and "RowKey" in entity:
                entity = _add_entity_properties(entity)
            else:
                raise ValueError(
                    'PartitionKey and RowKey were not provided in entity')
        try:
            inserted_entity = await self._client.table.insert_entity(
                table=self.table_name,
                table_entity_properties=entity,
                **kwargs)
            properties = _convert_to_entity(inserted_entity)
            return properties
        except ResourceNotFoundError as error:
            process_table_error(error)
    async def set_service_properties(
            self,
            analytics_logging=None,  # type: Optional[TableAnalyticsLogging]
            hour_metrics=None,  # type: Optional[Metrics]
            minute_metrics=None,  # type: Optional[Metrics]
            cors=None,  # type: Optional[CorsRule]
            **kwargs  # type: Any
    ):
        # type: (...) -> None
        """Sets properties for an account's Table service endpoint,
        including properties for Analytics and CORS (Cross-Origin Resource Sharing) rules.

       :param analytics_logging: Properties for analytics
       :type analytics_logging: ~azure.data.tables.TableAnalyticsLogging
       :param hour_metrics: Hour level metrics
       :type hour_metrics: ~azure.data.tables.Metrics
       :param minute_metrics: Minute level metrics
       :type minute_metrics: ~azure.data.tables.Metrics
       :param cors: Cross-origin resource sharing rules
       :type cors: ~azure.data.tables.CorsRule
       :return: None
       :rtype: None
       :raises: ~azure.core.exceptions.HttpResponseError
        """
        props = TableServiceProperties(logging=analytics_logging,
                                       hour_metrics=hour_metrics,
                                       minute_metrics=minute_metrics,
                                       cors=cors)
        try:
            return await self._client.service.set_properties(props, **kwargs
                                                             )  # type: ignore
        except HttpResponseError as error:
            process_table_error(error)
 async def _get_next_cb(self, continuation_token, **kwargs):
     try:
         return await self._command(
             next_table_name=continuation_token or None,
             cls=kwargs.pop('cls', return_context_and_deserialized),
             use_location=self.location_mode)
     except HttpResponseError as error:
         process_table_error(error)
Esempio n. 7
0
    async def update_entity(
            self,
            entity,  # type: Union[TableEntity, dict[str,str]]
            mode=UpdateMode.MERGE,  # type: UpdateMode
            **kwargs  # type: Any
    ):
        # type: (...) -> None
        """Update entity in a table.
        :param mode: Merge or Replace entity
        :type mode: ~azure.data.tables.UpdateMode
        :param entity: The properties for the table entity.
        :type entity: dict[str, str]
        :param partition_key: The partition key of the entity.
        :type partition_key: str
        :param row_key: The row key of the entity.
        :type row_key: str
        :param etag: Etag of the entity
        :type etag: str
        :param match_condition: MatchCondition
        :type match_condition: ~azure.core.MatchConditions
        :return: None
        :rtype: None
        :raises: ~azure.core.exceptions.HttpResponseError
        """
        if_match, if_not_match = _get_match_headers(
            kwargs=dict(kwargs,
                        etag=kwargs.pop('etag', None),
                        match_condition=kwargs.pop('match_condition', None)),
            etag_param='etag',
            match_param='match_condition')

        partition_key = entity['PartitionKey']
        row_key = entity['RowKey']
        entity = _add_entity_properties(entity)
        try:
            if mode is UpdateMode.REPLACE:
                await self._client.table.update_entity(
                    table=self.table_name,
                    partition_key=partition_key,
                    row_key=row_key,
                    table_entity_properties=entity,
                    if_match=if_match or if_not_match or "*",
                    **kwargs)
            elif mode is UpdateMode.MERGE:
                await self._client.table.merge_entity(
                    table=self.table_name,
                    partition_key=partition_key,
                    row_key=row_key,
                    if_match=if_match or if_not_match or "*",
                    table_entity_properties=entity,
                    **kwargs)
            else:
                raise ValueError('Mode type is not supported')
        except HttpResponseError as error:
            process_table_error(error)
Esempio n. 8
0
 async def delete_table(
         self,
         **kwargs  # type: Any
 ):
     # type: (...) -> None
     """Creates a new table under the given account.
     :return: None
     :rtype: None
     """
     try:
         await self._client.table.delete(table=self.table_name, **kwargs)
     except HttpResponseError as error:
         process_table_error(error)
Esempio n. 9
0
 async def create_table(
         self,
         **kwargs  # type: Any
 ):
     # type: (...) -> Table
     """Creates a new table under the given account.
     :return: Table created
     :rtype: Table
     :raises: ~azure.core.exceptions.HttpResponseError
     """
     table_properties = TableProperties(table_name=self.table_name,
                                        **kwargs)
     try:
         table = await self._client.table.create(table_properties)
         return Table(table)
     except HttpResponseError as error:
         process_table_error(error)
    async def get_service_properties(self, **kwargs):
        # type: (...) -> dict[str,Any]
        """Gets the properties of an account's Table service,
        including properties for Analytics and CORS (Cross-Origin Resource Sharing) rules.

        :keyword callable cls: A custom type or function that will be passed the direct response
        :return: TableServiceProperties, or the result of cls(response)
        :rtype: ~azure.data.tables.models.TableServiceProperties
        :raises: ~azure.core.exceptions.HttpResponseError
        """
        timeout = kwargs.pop('timeout', None)
        try:
            service_props = await self._client.service.get_properties(
                timeout=timeout, **kwargs)  # type: ignore
            return service_properties_deserialize(service_props)
        except HttpResponseError as error:
            process_table_error(error)
Esempio n. 11
0
 async def _get_next_cb(self, continuation_token):
     row_key = ""
     partition_key = ""
     for key, value in continuation_token.items():
         if key == "RowKey":
             row_key = value
         if key == "PartitionKey":
             partition_key = value
     try:
         return await self._command(query_options=self.results_per_page
                                    or None,
                                    next_row_key=row_key or None,
                                    next_partition_key=partition_key
                                    or None,
                                    table=self.table,
                                    cls=return_context_and_deserialized,
                                    use_location=self.location_mode)
     except HttpResponseError as error:
         process_table_error(error)
    async def get_service_stats(self, **kwargs):
        # type: (...) -> dict[str,object]
        """Retrieves statistics related to replication for the Table service. It is only available on the secondary
        location endpoint when read-access geo-redundant replication is enabled for the account.

                :keyword callable cls: A custom type or function that will be passed the direct response
                :return: TableServiceStats, or the result of cls(response)
                :rtype: ~azure.data.tables.models.TableServiceStats
                :raises: ~azure.core.exceptions.HttpResponseError
                """
        try:
            timeout = kwargs.pop('timeout', None)
            stats = await self._client.service.get_statistics(  # type: ignore
                timeout=timeout,
                use_location=LocationMode.SECONDARY,
                **kwargs)
            return service_stats_deserialize(stats)
        except HttpResponseError as error:
            process_table_error(error)
Esempio n. 13
0
 async def get_table_access_policy(
         self,
         **kwargs  # type: Any
 ):
     # type: (...) -> dict[str,AccessPolicy]
     """
     Retrieves details about any stored access policies specified on the table that may be
     used with Shared Access Signatures.
     :return: Dictionary of SignedIdentifiers
     :rtype: dict[str,~azure.data.tables.AccessPolicy]
     :raises: ~azure.core.exceptions.HttpResponseError
     """
     timeout = kwargs.pop('timeout', None)
     try:
         _, identifiers = await self._client.table.get_access_policy(
             table=self.table_name,
             timeout=timeout,
             cls=return_headers_and_deserialized,
             **kwargs)
     except HttpResponseError as error:
         process_table_error(error)
     return {s.id: s.access_policy or AccessPolicy() for s in identifiers}