# 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 ObjectAccessOperationsClient:
__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_cross_account(self, request_object):
"""Create a cross account
Create a cross account on which access needs to be given for paths. * If, in request body subtenant is denoted as \"**\", it is a special cross account. In this case, on this cross account, tenant implicitly gets Read Only access to the storage account's root level data path for itself and for all its subtenants. For this case, the authorization token should be that of the tenant.
:param CreateCrossAccountRequest request_object: It contains the below parameters --> |br| ( crossAccountRequest* - Cross Account Request )
:return: CrossAccount
"""
logger.info("ObjectAccessOperationsClient.create_cross_account() invoked.")
if request_object is None:
raise exceptions.MindsphereClientError(
"`request_object` is not passed when calling `create_cross_account`"
)
if request_object.cross_account_request is None:
raise exceptions.MindsphereClientError(
"The required parameter `crossAccountRequest` is missing from `request_object`, when calling `create_cross_account`"
)
end_point_url = "/crossAccounts"
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.cross_account_request,
)
logger.info(
"ObjectAccessOperationsClient.create_cross_account() --> 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,
"CrossAccount",
self.__model_package__,
)
[docs] def create_cross_account_access(self, request_object):
"""Create a cross account access
Create a cross account access. If the cross account is created for tenant and all subtenants (**), then this operation is implicitly handled and not allowed through API. Maximum 5 cross account accesses can be created with ENABLED status. Maximum 10 cross accounts can be created with DISABLED status.
:param CreateCrossAccountAccessRequest request_object: It contains the below parameters --> |br| ( id* - unique identifier of the cross account ), |br| ( crossAccountAccessRequest* - Cross Account Access Request )
:return: CrossAccountAccess
"""
logger.info(
"ObjectAccessOperationsClient.create_cross_account_access() invoked."
)
if request_object is None:
raise exceptions.MindsphereClientError(
"`request_object` is not passed when calling `create_cross_account_access`"
)
if request_object.id is None:
raise exceptions.MindsphereClientError(
"The required parameter `id` is missing from `request_object`, when calling `create_cross_account_access`"
)
if request_object.cross_account_access_request is None:
raise exceptions.MindsphereClientError(
"The required parameter `crossAccountAccessRequest` is missing from `request_object`, when calling `create_cross_account_access`"
)
end_point_url = "/crossAccounts/{id}/accesses"
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",
"Content-Type": "application/json",
"Authorization": "Bearer " + str(token),
}
query_params = {}
form_params, local_var_files, body_params = (
{},
{},
request_object.cross_account_access_request,
)
logger.info(
"ObjectAccessOperationsClient.create_cross_account_access() --> 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,
"CrossAccountAccess",
self.__model_package__,
)
[docs] def delete_cross_account(self, request_object):
"""Delete cross account and corresponding accesses.
Delete cross account and corresponding accesses.
:param DeleteCrossAccountRequest request_object: It contains the below parameters --> |br| ( id* - unique identifier of the cross account ), |br| ( If-Match* - ETag of the resource )
:return: None
"""
logger.info("ObjectAccessOperationsClient.delete_cross_account() invoked.")
if request_object is None:
raise exceptions.MindsphereClientError(
"`request_object` is not passed when calling `delete_cross_account`"
)
if request_object.id is None:
raise exceptions.MindsphereClientError(
"The required parameter `id` is missing from `request_object`, when calling `delete_cross_account`"
)
if request_object.if_match is None:
raise exceptions.MindsphereClientError(
"The required parameter `If-Match` is missing from `request_object`, when calling `delete_cross_account`"
)
end_point_url = "/crossAccounts/{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(
"ObjectAccessOperationsClient.delete_cross_account() --> 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 delete_cross_account_access(self, request_object):
"""Delete a cross account access.
Delete a cross account access. If the cross account is created for tenant and all subtenants (**), then this operation is implicitly handled by deletion of cross account and not allowed through API
:param DeleteCrossAccountAccessRequest request_object: It contains the below parameters --> |br| ( id* - unique identifier of the cross account ), |br| ( accessId* - unique identifier of the cross account ), |br| ( If-Match* - ETag of the resource )
:return: None
"""
logger.info(
"ObjectAccessOperationsClient.delete_cross_account_access() invoked."
)
if request_object is None:
raise exceptions.MindsphereClientError(
"`request_object` is not passed when calling `delete_cross_account_access`"
)
if request_object.id is None:
raise exceptions.MindsphereClientError(
"The required parameter `id` is missing from `request_object`, when calling `delete_cross_account_access`"
)
if request_object.access_id is None:
raise exceptions.MindsphereClientError(
"The required parameter `accessId` is missing from `request_object`, when calling `delete_cross_account_access`"
)
if request_object.if_match is None:
raise exceptions.MindsphereClientError(
"The required parameter `If-Match` is missing from `request_object`, when calling `delete_cross_account_access`"
)
end_point_url = "/crossAccounts/{id}/accesses/{accessId}"
end_point_url = end_point_url.format(
id=request_object.id, accessId=request_object.access_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(
"ObjectAccessOperationsClient.delete_cross_account_access() --> 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 generate_download_object_urls(self, request_object):
"""Generate signed URLs to download for single object.
Generate signed URLs to download for single object.
:param GenerateDownloadObjectUrlsRequest request_object: It contains the below parameters --> |br| ( generateUrlPayload - download payload with path details array and optional subtenat id )
:return: SignedUrlResponse
"""
logger.info(
"ObjectAccessOperationsClient.generate_download_object_urls() invoked."
)
end_point_url = "/generateDownloadObjectUrls"
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 = {}
form_params, local_var_files, body_params = (
{},
{},
request_object.generate_url_payload,
)
logger.info(
"ObjectAccessOperationsClient.generate_download_object_urls() --> 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,
"SignedUrlResponse",
self.__model_package__,
)
[docs] def generate_upload_object_urls(self, request_object):
"""Generate signed URLs to upload an object.
Generate signed URLs to upload one or more objects.
:param GenerateUploadObjectUrlsRequest request_object: It contains the below parameters --> |br| ( generateUrlPayload - upload payload with path details array and optional subtenat id )
:return: SignedUrlResponse
"""
logger.info(
"ObjectAccessOperationsClient.generate_upload_object_urls() invoked."
)
end_point_url = "/generateUploadObjectUrls"
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 = {}
form_params, local_var_files, body_params = (
{},
{},
request_object.generate_url_payload,
)
logger.info(
"ObjectAccessOperationsClient.generate_upload_object_urls() --> 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,
"SignedUrlResponse",
self.__model_package__,
)
[docs] def get_cross_account(self, request_object):
"""Get details of selected cross account
Get details of selected cross account.
:param GetCrossAccountRequest request_object: It contains the below parameters --> |br| ( id* - unique identifier of the cross account )
:return: CrossAccount
"""
logger.info("ObjectAccessOperationsClient.get_cross_account() invoked.")
if request_object is None:
raise exceptions.MindsphereClientError(
"`request_object` is not passed when calling `get_cross_account`"
)
if request_object.id is None:
raise exceptions.MindsphereClientError(
"The required parameter `id` is missing from `request_object`, when calling `get_cross_account`"
)
end_point_url = "/crossAccounts/{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(
"ObjectAccessOperationsClient.get_cross_account() --> 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,
"CrossAccount",
self.__model_package__,
)
[docs] def get_cross_account_access(self, request_object):
"""Get a selected access for a selected cross account
Get a selected access for a selected cross account.
:param GetCrossAccountAccessRequest request_object: It contains the below parameters --> |br| ( id* - unique identifier of the cross account ), |br| ( accessId* - unique identifier of the cross account access )
:return: CrossAccountAccess
"""
logger.info("ObjectAccessOperationsClient.get_cross_account_access() invoked.")
if request_object is None:
raise exceptions.MindsphereClientError(
"`request_object` is not passed when calling `get_cross_account_access`"
)
if request_object.id is None:
raise exceptions.MindsphereClientError(
"The required parameter `id` is missing from `request_object`, when calling `get_cross_account_access`"
)
if request_object.access_id is None:
raise exceptions.MindsphereClientError(
"The required parameter `accessId` is missing from `request_object`, when calling `get_cross_account_access`"
)
end_point_url = "/crossAccounts/{id}/accesses/{accessId}"
end_point_url = end_point_url.format(
id=request_object.id, accessId=request_object.access_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(
"ObjectAccessOperationsClient.get_cross_account_access() --> 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,
"CrossAccountAccess",
self.__model_package__,
)
[docs] def list_cross_account(self, request_object):
"""Get a list of cross accounts
Get list of cross accounts on which access was given. * If requester is tenant, all the cross account for the tenant as well as its all subtenants are returned. * If requester is a subtenant, all the cross accounts 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 ListCrossAccountRequest 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: CrossAccountListResource
"""
logger.info("ObjectAccessOperationsClient.list_cross_account() invoked.")
end_point_url = "/crossAccounts"
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(
"ObjectAccessOperationsClient.list_cross_account() --> 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,
"CrossAccountListResource",
self.__model_package__,
)
[docs] def list_cross_account_access(self, request_object):
"""Get a list of cross account accesses
Get list of cross account accesses.
:param ListCrossAccountAccessRequest request_object: It contains the below parameters --> |br| ( id* - unique identifier of the cross account ), |br| ( page - Specifies the requested page index ), |br| ( size - Specifies the number of elements in a page )
:return: CrossAccountAccessListResource
"""
logger.info("ObjectAccessOperationsClient.list_cross_account_access() invoked.")
if request_object is None:
raise exceptions.MindsphereClientError(
"`request_object` is not passed when calling `list_cross_account_access`"
)
if request_object.id is None:
raise exceptions.MindsphereClientError(
"The required parameter `id` is missing from `request_object`, when calling `list_cross_account_access`"
)
end_point_url = "/crossAccounts/{id}/accesses"
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 = {"page": request_object.page, "size": request_object.size}
form_params, local_var_files, body_params = {}, {}, None
logger.info(
"ObjectAccessOperationsClient.list_cross_account_access() --> 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,
"CrossAccountAccessListResource",
self.__model_package__,
)
[docs] def update_cross_account(self, request_object):
"""Update a cross account
Update a cross account on which access needs to be managed.
:param UpdateCrossAccountRequest request_object: It contains the below parameters --> |br| ( id* - unique identifier of the cross account ), |br| ( If-Match* - ETag of the resource ), |br| ( crossAccountRequest* - Cross Account Request )
:return: CrossAccount
"""
logger.info("ObjectAccessOperationsClient.update_cross_account() invoked.")
if request_object is None:
raise exceptions.MindsphereClientError(
"`request_object` is not passed when calling `update_cross_account`"
)
if request_object.id is None:
raise exceptions.MindsphereClientError(
"The required parameter `id` is missing from `request_object`, when calling `update_cross_account`"
)
if request_object.if_match is None:
raise exceptions.MindsphereClientError(
"The required parameter `If-Match` is missing from `request_object`, when calling `update_cross_account`"
)
if request_object.cross_account_request is None:
raise exceptions.MindsphereClientError(
"The required parameter `crossAccountRequest` is missing from `request_object`, when calling `update_cross_account`"
)
end_point_url = "/crossAccounts/{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",
"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.cross_account_request,
)
logger.info(
"ObjectAccessOperationsClient.update_cross_account() --> 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,
"CrossAccount",
self.__model_package__,
)
[docs] def update_cross_account_access(self, request_object):
"""Update a cross account access
Update a cross account access. This operation is not allowed when the cross account is created for special case of tenant and all subtenants (**). Maximum 5 cross account accesses can be present with ENABLED status. Maximum 10 cross accounts can be present with DISABLED status.
:param UpdateCrossAccountAccessRequest request_object: It contains the below parameters --> |br| ( id* - unique identifier of the cross account ), |br| ( accessId* - unique identifier of the cross account access ), |br| ( If-Match* - ETag of the resource ), |br| ( crossAccountAccessRequest* - Cross Account Access Request )
:return: CrossAccountAccess
"""
logger.info(
"ObjectAccessOperationsClient.update_cross_account_access() invoked."
)
if request_object is None:
raise exceptions.MindsphereClientError(
"`request_object` is not passed when calling `update_cross_account_access`"
)
if request_object.id is None:
raise exceptions.MindsphereClientError(
"The required parameter `id` is missing from `request_object`, when calling `update_cross_account_access`"
)
if request_object.access_id is None:
raise exceptions.MindsphereClientError(
"The required parameter `accessId` is missing from `request_object`, when calling `update_cross_account_access`"
)
if request_object.if_match is None:
raise exceptions.MindsphereClientError(
"The required parameter `If-Match` is missing from `request_object`, when calling `update_cross_account_access`"
)
if request_object.cross_account_access_request is None:
raise exceptions.MindsphereClientError(
"The required parameter `crossAccountAccessRequest` is missing from `request_object`, when calling `update_cross_account_access`"
)
end_point_url = "/crossAccounts/{id}/accesses/{accessId}"
end_point_url = end_point_url.format(
id=request_object.id, accessId=request_object.access_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",
"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.cross_account_access_request,
)
logger.info(
"ObjectAccessOperationsClient.update_cross_account_access() --> 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,
"CrossAccountAccess",
self.__model_package__,
)