mindsphere_core package

Submodules

mindsphere_core.commonutil module

exception APIError(status_code, message)[source]

Bases: Exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception APIErrorResponse(status_code=None, message=None, log_ref=None, time_stamp=None, error=None, exception=None, path=None)[source]

Bases: Exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception UnAuthorisedErrorResponse(stack_trace=None, message=None, log_ref=None)[source]

Bases: Exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

_check_for_bearer(token)[source]
_check_for_mock_token(token)[source]
_decode_jwt(token)[source]
_is_issuer_valid(payload)[source]
_is_token_active(token_expiry_time, is_technical_token)[source]
_is_token_valid_without_issuer_validation(token)[source]
_validate_claim(payload)[source]
_validate_issuer(payload)[source]
append_bearer(token)[source]
extract_env_var(var_name)[source]
get_tenant_from_token(authorization)[source]
is_token_valid(token, is_technical_token)[source]
parse_exception(response)[source]

mindsphere_core.constants module

mindsphere_core.error_messages module

mindsphere_core.exceptions module

exception MindsphereClientConfigurationError(message, error=None, http_status=None, log_ref=None)[source]

Bases: mindsphere_core.exceptions.MindsphereClientError

Class for exceptions raised because of any incorrect/missing client configuration.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception MindsphereClientError(message, error=None, http_status=None, log_ref=None)[source]

Bases: mindsphere_core.exceptions.MindsphereError

Class for exceptions raised during any error caused by client input.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception MindsphereError(message, error=None, http_status=None, log_ref=None)[source]

Bases: Exception

Base class for mindspshere exceptions.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception MindsphereForbiddenAccessError(message, error=None, http_status=None, log_ref=None)[source]

Bases: mindsphere_core.exceptions.MindsphereClientError

Class for exceptions raised during any authorization error.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception MindsphereServerError(message, error=None, http_status=None, log_ref=None)[source]

Bases: mindsphere_core.exceptions.MindsphereError

Class for exceptions raised during any error received from api server.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

mindsphere_core.identification module

Technical Token Manager API

This API provides operations to manage your access to customer IoT data. The operations return a Technical Token, which gives access to the tenant’s IoT data. # noqa: E501

class Identification(app_name=None, app_version=None, host_tenant=None, user_tenant=None)[source]

Bases: object

Attributes:
attribute_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
app_name

Gets the app_name of this Identification. Name of the application from Operator/Developer Cockpit

Returns:The app_name of this Identification.
Return type:str
app_version

Gets the app_version of this Identification. Version of the application as given in Operation/Developer Cockpit.

Returns:The app_version of this Identification.
Return type:str
attribute_map = {'app_name': 'appName', 'app_version': 'appVersion', 'host_tenant': 'hostTenant', 'user_tenant': 'userTenant'}
attribute_types = {'app_name': 'str', 'app_version': 'str', 'host_tenant': 'str', 'user_tenant': 'str'}
host_tenant

Gets the host_tenant of this Identification. Tenant ID of the developer/operator tenant hosting the application.

Returns:The host_tenant of this Identification.
Return type:str
to_dict()[source]

Returns the model properties as a dict

to_str()[source]

Returns the string representation of the model

user_tenant

Gets the user_tenant of this Identification. Tenant ID of the tenant owning the data to be accessed with the Technical Token.

Returns:The user_tenant of this Identification.
Return type:str

mindsphere_core.log_config module

default_logging()[source]

Default config : using logging.StreamHandler class for handler and level : INFO and formatter : extended :return:

setup_logging(level=20, format='%(message)s')[source]
setup logging : using logging.StreamHandler class as default for handler, level : custom and formatter : custom
Returns:

mindsphere_core.mindsphere_core module

This module implements the common features of sdk used by all clients.

Copyright (C), Siemens AG 2018 Licensed under the MindSphere Developer License, see LICENSE.md.

class RestClientConfig(proxy_host=None, proxy_port=None, proxy_username=None, proxy_password=None, connection_timeout_in_seconds=100, socket_timeout_in_seconds=100, proxy_schema='http', host_environment=None)[source]

Bases: object

This class allows to configure proxy , timeout and hosting environment.

proxy_host : str
Proxy host
proxy_username : str
Proxy User name
proxy_port : str
Proxy port
proxy_password : str
Proxy password
connection_timeout_in_seconds : str
Connection timeout
socket_timeout_in_seconds : str
Socket timeout
proxy_schema : str
Proxy schema
host_environment : str
Target hosted environment
build_url(base_path, end_point_url, config=None)[source]

builds the end point url based on host environment.

base_path : str
base path for the selected service
end_point_url : str
url for the requested service end point
config : RestClientConfig
config object set by user
fetch_token(rest_client_config, credentials)[source]

Fetches a token either using service credentials or validates the token if its already provided in credentials

invoke_service(rest_client_config, api_url, headers, http_method, query_params=None, form_params=None, body_params=None, local_var_files=None, response_type=None, model_package=None)[source]

Method to invoke rest end points.

mindsphere_core.mindsphere_credentials module

class AppCredentials(app_name=None, app_version=None, key_store_client_id=None, key_store_client_secret=None, host_tenant=None, user_tenant=None, authorization=None)[source]

Bases: object

This class allows to configure app credentials.

app_name : str
Application name
app_version : str
Application version
key_store_client_id : str
Key store client Id
key_store_client_secret : str
Key store client Secret
host_tenant : str
Host Tenant
user_tenant : str
User tenant name
cached_token
class TenantCredentials(client_id=None, client_secret=None, tenant=None, sub_tenant=None, use_sub_tenant=None)[source]

Bases: object

This class allows to configure tenant credentials.

client_id : str
Client Id
client_secret : str
Client secret
tenant : str
Tenant name
sub_tenant : str
Sub tenant name
use_sub_tenant : bool
Boolean to indicate if subtenant will be used to get token
cached_token
class UserToken(authorization=None)[source]

Bases: object

This class allows to configure User token.

authorization : str
Authorization token

mindsphere_core.serialization_filter module

__deserialize(data, klass)[source]

Deserializes dict, list, str into an object.

Parameters:
  • data (object) – dict, list or str.
  • klass – class literal, or string of class name.
Returns:

object.

__deserialize_date(string)[source]

Deserializes string to date.

Parameters:string – str.
Returns:date.
__deserialize_datetime(string)[source]

Deserializes string to datetime.

The string should be in iso8601 datetime format.

Parameters:string – str.
Returns:datetime.
__deserialize_file(response)[source]

Deserializes body to file

Saves response body into a file in a temporary folder, using the filename from the Content-Disposition header if provided.

Parameters:response – RESTResponse.
Returns:file path.
__deserialize_model(data, klass)[source]

Deserializes list or dict to model.

Parameters:
  • data – dict, list.
  • klass – class literal.
Returns:

model object.

__deserialize_object(value)[source]

Return a original value.

Returns:object.
__deserialize_primitive(data, klass)[source]

Deserializes string to primitive type.

Parameters:
  • data – str.
  • klass – class literal.
Returns:

int, long, float, str, bool.

deserialize(response, response_type)[source]

Deserializes response into an object.

Parameters:
  • response – RESTResponse object to be deserialized.
  • response_type – class literal for deserialized object, or string of class name.
Returns:

deserialized object.

sanitize_for_serialization(obj)[source]

Builds a JSON POST object. If obj is None, return None. If obj is str, int, long, float, bool, return directly. If obj is datetime.datetime, datetime. date convert to string in iso8601 format. If obj is list, sanitize each element in the list. If obj is dict, return the dict. If obj is swagger model, return the properties dict.

Parameters:obj – The data to serialize.
Returns:The serialized form of data.
sanitize_headers(headers)[source]

Converts all custom header values to string. This is required because requests module only accept string type headers.

mindsphere_core.token_service module

class AppCredsRequestBody(app_name, app_version, host_tenant, user_tenant)[source]

Bases: object

_get_requested_token(rest_client_config, credentials)[source]
_get_token_with_app_creds(rest_client_config, credentials)[source]
_get_token_with_tenant_creds(rest_client_config, credentials)[source]
_get_token_with_user_token(credentials)[source]
_invoke_token_endpoint(rest_client_config, client_id, client_secret, tenant, sub_tenant=None)[source]

Method to fetch authorization token to preauthorize the service calls.

_is_app_creds_present()[source]
_is_tenant_creds_present()[source]
_populate_app_creds(credentials)[source]
_populate_tenant_creds(credentials)[source]
fetch_token(rest_client_config, credentials)[source]

Fetches a token either using service credentials or validates the token if its already provided in credentials

init_credentials(credentials)[source]

initializes the credentials after checking the env variables if its not set by user.

Module contents

mindsphere_core

The MindSphere SDK Java Core provides many core features like authorization , token handling , exception handling , api invoker , logging features etc. Mindsphere SDK Core is used as a dependency in auto-generated Mindsphere service SDKs to have all functionalities of SDK core.

Copyright (C), Siemens AG 2018 Licensed under the MindSphere Developer License, see LICENSE.md.

class RestClientConfig(proxy_host=None, proxy_port=None, proxy_username=None, proxy_password=None, connection_timeout_in_seconds=100, socket_timeout_in_seconds=100, proxy_schema='http', host_environment=None)[source]

Bases: object

This class allows to configure proxy , timeout and hosting environment.

proxy_host : str
Proxy host
proxy_username : str
Proxy User name
proxy_port : str
Proxy port
proxy_password : str
Proxy password
connection_timeout_in_seconds : str
Connection timeout
socket_timeout_in_seconds : str
Socket timeout
proxy_schema : str
Proxy schema
host_environment : str
Target hosted environment
class AppCredentials(app_name=None, app_version=None, key_store_client_id=None, key_store_client_secret=None, host_tenant=None, user_tenant=None, authorization=None)[source]

Bases: object

This class allows to configure app credentials.

app_name : str
Application name
app_version : str
Application version
key_store_client_id : str
Key store client Id
key_store_client_secret : str
Key store client Secret
host_tenant : str
Host Tenant
user_tenant : str
User tenant name
cached_token
class TenantCredentials(client_id=None, client_secret=None, tenant=None, sub_tenant=None, use_sub_tenant=None)[source]

Bases: object

This class allows to configure tenant credentials.

client_id : str
Client Id
client_secret : str
Client secret
tenant : str
Tenant name
sub_tenant : str
Sub tenant name
use_sub_tenant : bool
Boolean to indicate if subtenant will be used to get token
cached_token
class UserToken(authorization=None)[source]

Bases: object

This class allows to configure User token.

authorization : str
Authorization token