Source code for integrateddatalake.clients.object_event_subscription_operations_client

# coding: utf-8

"""
    Data Lake API

    Service for storing Objects, download objects, add extended metadata tags,  subscribe for notifications, import tenant specific MindSphere Time Series data, and enable data access using cross account access and STS in Integrated MindSphere Data Lake. - Objects reside in user specified path like below example. Extension in object name is optional. Root path can be denoted as \"/\"       /basefolder/subfolder/objectname.objectext   - The following generic error codes might occur at any of the specified operations. Generic errors are prefixed with 'mdsp.core.generic.'.    - missingParameter   - invalidParameter   - missingRequestBodyProperty   - invalidRequestBodyProperty   - unauthorized   - forbidden   - noMatch   - unsupportedMediaType   - tooManyRequests   - internalServerError  # noqa: E501
"""


from __future__ import absolute_import

from mindsphere_core.mindsphere_core import logger
from mindsphere_core import mindsphere_core, exceptions, token_service
from mindsphere_core.token_service import init_credentials


[docs]class ObjectEventSubscriptionOperationsClient: __base_path__ = "/api/datalake/v3" __model_package__ = __name__.split(".")[0] def __init__(self, rest_client_config=None, mindsphere_credentials=None): self.rest_client_config = rest_client_config self.mindsphere_credentials = init_credentials(mindsphere_credentials)
[docs] def create_object_event_subscription(self, request_object): """Create object event subscription. Allows users to subscribe for event notifications generated when the objects of a tenant or subtenant are created, updated, or deleted. Multiple subscriptions for the same path can be created when each has a different destination. Similarly, multiple subscriptions for the same destination can be created when each has a different path. Maximum 15 subscriptions can be created for a tenant or for a subtenant. Path in request payload should be upto folders and not upto object e.g. \"myfolder/mysubfolder\" ### Notification Content Based on the configured subscriptions, event notification messages are published to the destination. The event notification content is formatted in JSON according to this example. If object operation happened in subtenant folder, both tenantId and subtenantId will be part of the message. If object operation happened in tenant folder, only tenantId will be part of the message.: { \"path\" : \"/myfolder/mysubfolder/myobj.ext\", \"storageAccount\" : \"dlbucketname\", \"storagePath\" : \"/data/ten=mytenid/myfolder/mysubfolder/myobj.ext\" \"tenantId\" : \"mytenid\", \"subtenantId\" : \"204a896c-a23a-11e9-a2a3-2a2ae2dbcce4\" \"eventType\" : \"MODIFY\", \"timestamp\" : \"2019-05-17T14:47:44.351Z\" } where - 'path' path applicable for supplying to Data Lake APIs like /objectMetadata - 'storageAccount' Bucket name in case of AWS S3 - 'storagePath' Complete S3 prefix path including the object name. Clients should not rely on a given path structure, but should treat storagePath as opaque. - 'tenantId' Tenant Id on whose bucket the object operation happened, resulting in notification message - 'subtenantId' Optional. Subtenant Id, in case the object operation happened for a subtenant, resuling in notification message - 'eventType' is either 'MODIFY' in case of creation or update, and 'DELETE' in case of object deletion. - 'timestamp' records the time when the event happened. It is formatted according to ISO 8601 extended date/time format 'YYYY-MM-DDThh:mm:ss.sssZ'. :param CreateObjectEventSubscriptionRequest request_object: It contains the below parameters --> |br| ( subscription* - object event subscrition details ) :return: SubscriptionResponse """ logger.info( "ObjectEventSubscriptionOperationsClient.create_object_event_subscription() invoked." ) if request_object is None: raise exceptions.MindsphereClientError( "`request_object` is not passed when calling `create_object_event_subscription`" ) if request_object.subscription is None: raise exceptions.MindsphereClientError( "The required parameter `subscription` is missing from `request_object`, when calling `create_object_event_subscription`" ) end_point_url = "/objectEventSubscriptions" end_point_url = end_point_url.format() token = token_service.fetch_token( self.rest_client_config, self.mindsphere_credentials ) api_url = mindsphere_core.build_url( self.__base_path__, end_point_url, self.rest_client_config ) headers = { "Accept": "application/json", "Content-Type": "application/json", "Authorization": "Bearer " + str(token), } query_params = {} form_params, local_var_files, body_params = {}, {}, request_object.subscription logger.info( "ObjectEventSubscriptionOperationsClient.create_object_event_subscription() --> Proceeding for API Invoker." ) return mindsphere_core.invoke_service( self.rest_client_config, api_url, headers, "POST", query_params, form_params, body_params, local_var_files, "SubscriptionResponse", self.__model_package__, )
[docs] def delete_object_event_subscription(self, request_object): """Delete object event subscription by id. Delete object event subscription (Unsubscribe). :param DeleteObjectEventSubscriptionRequest request_object: It contains the below parameters --> |br| ( id* - unique identifier of the subscription ), |br| ( If-Match* - ETag of the resource ) :return: None """ logger.info( "ObjectEventSubscriptionOperationsClient.delete_object_event_subscription() invoked." ) if request_object is None: raise exceptions.MindsphereClientError( "`request_object` is not passed when calling `delete_object_event_subscription`" ) if request_object.id is None: raise exceptions.MindsphereClientError( "The required parameter `id` is missing from `request_object`, when calling `delete_object_event_subscription`" ) if request_object.if_match is None: raise exceptions.MindsphereClientError( "The required parameter `If-Match` is missing from `request_object`, when calling `delete_object_event_subscription`" ) end_point_url = "/objectEventSubscriptions/{id}" end_point_url = end_point_url.format(id=request_object.id) token = token_service.fetch_token( self.rest_client_config, self.mindsphere_credentials ) api_url = mindsphere_core.build_url( self.__base_path__, end_point_url, self.rest_client_config ) headers = { "Accept": "application/json", "If-Match": request_object.if_match, "Authorization": "Bearer " + str(token), } query_params = {} form_params, local_var_files, body_params = {}, {}, None logger.info( "ObjectEventSubscriptionOperationsClient.delete_object_event_subscription() --> Proceeding for API Invoker." ) return mindsphere_core.invoke_service( self.rest_client_config, api_url, headers, "DELETE", query_params, form_params, body_params, local_var_files, None, self.__model_package__, )
[docs] def patch_object_event_subscription(self, request_object): """Update object event subscription by id. Update object event subscription. :param PatchObjectEventSubscriptionRequest request_object: It contains the below parameters --> |br| ( id* - unique identifier of the subscription ), |br| ( If-Match* - ETag of the resource ), |br| ( subscription* - object event subscrition details ) :return: SubscriptionResponse """ logger.info( "ObjectEventSubscriptionOperationsClient.patch_object_event_subscription() invoked." ) if request_object is None: raise exceptions.MindsphereClientError( "`request_object` is not passed when calling `patch_object_event_subscription`" ) if request_object.id is None: raise exceptions.MindsphereClientError( "The required parameter `id` is missing from `request_object`, when calling `patch_object_event_subscription`" ) if request_object.if_match is None: raise exceptions.MindsphereClientError( "The required parameter `If-Match` is missing from `request_object`, when calling `patch_object_event_subscription`" ) if request_object.subscription is None: raise exceptions.MindsphereClientError( "The required parameter `subscription` is missing from `request_object`, when calling `patch_object_event_subscription`" ) end_point_url = "/objectEventSubscriptions/{id}" end_point_url = end_point_url.format(id=request_object.id) token = token_service.fetch_token( self.rest_client_config, self.mindsphere_credentials ) api_url = mindsphere_core.build_url( self.__base_path__, end_point_url, self.rest_client_config ) headers = { "Content-Type": "application/json", "If-Match": request_object.if_match, "Authorization": "Bearer " + str(token), } query_params = {} form_params, local_var_files, body_params = {}, {}, request_object.subscription logger.info( "ObjectEventSubscriptionOperationsClient.patch_object_event_subscription() --> Proceeding for API Invoker." ) return mindsphere_core.invoke_service( self.rest_client_config, api_url, headers, "PATCH", query_params, form_params, body_params, local_var_files, "SubscriptionResponse", self.__model_package__, )
[docs] def query_object_event_subscriptions(self, request_object): """List event subscriptions for the tenant or subtenant. List object event subscriptions for the tenant or subtenant. If requester is tenant, all the subscriptions for the tenant as well as its all subtenants are returned. If requester is a subtenant, all the subscriptions for the subtenant are returned. If tenant wants to filter results for a particular subtenant, filter query parameter subtenantId can be used. This filter query parameter is applicable only if the requester is tenant. :param QueryObjectEventSubscriptionsRequest request_object: It contains the below parameters --> |br| ( page - Specifies the requested page index ), |br| ( size - Specifies the number of elements in a page ), |br| ( filter - JSON-based filter expression. Supported values: 'subtenantId'. Supported operations: 'eq'. Decoded example value: { \"subtenantId\": \"204a896c-a23a-11e9-a2a3-2a2ae2dbcce4\" } ) :return: SubscriptionListResource """ logger.info( "ObjectEventSubscriptionOperationsClient.query_object_event_subscriptions() invoked." ) end_point_url = "/objectEventSubscriptions" end_point_url = end_point_url.format() token = token_service.fetch_token( self.rest_client_config, self.mindsphere_credentials ) api_url = mindsphere_core.build_url( self.__base_path__, end_point_url, self.rest_client_config ) headers = { "Accept": "application/json", "Authorization": "Bearer " + str(token), } query_params = { "page": request_object.page, "size": request_object.size, "filter": request_object.filter, } form_params, local_var_files, body_params = {}, {}, None logger.info( "ObjectEventSubscriptionOperationsClient.query_object_event_subscriptions() --> Proceeding for API Invoker." ) return mindsphere_core.invoke_service( self.rest_client_config, api_url, headers, "GET", query_params, form_params, body_params, local_var_files, "SubscriptionListResource", self.__model_package__, )
[docs] def retrieve_object_event_subscription(self, request_object): """Read object event subscription by id. Read object event subscription for the tenant. :param RetrieveObjectEventSubscriptionRequest request_object: It contains the below parameters --> |br| ( id* - unique identifier of the subscrition ) :return: SubscriptionResponse """ logger.info( "ObjectEventSubscriptionOperationsClient.retrieve_object_event_subscription() invoked." ) if request_object is None: raise exceptions.MindsphereClientError( "`request_object` is not passed when calling `retrieve_object_event_subscription`" ) if request_object.id is None: raise exceptions.MindsphereClientError( "The required parameter `id` is missing from `request_object`, when calling `retrieve_object_event_subscription`" ) end_point_url = "/objectEventSubscriptions/{id}" end_point_url = end_point_url.format(id=request_object.id) token = token_service.fetch_token( self.rest_client_config, self.mindsphere_credentials ) api_url = mindsphere_core.build_url( self.__base_path__, end_point_url, self.rest_client_config ) headers = { "Accept": "application/json", "Authorization": "Bearer " + str(token), } query_params = {} form_params, local_var_files, body_params = {}, {}, None logger.info( "ObjectEventSubscriptionOperationsClient.retrieve_object_event_subscription() --> Proceeding for API Invoker." ) return mindsphere_core.invoke_service( self.rest_client_config, api_url, headers, "GET", query_params, form_params, body_params, local_var_files, "SubscriptionResponse", self.__model_package__, )