def __init__(self, credentials=None, protocol=None, payload_format=None, asset_endpoint=None):
        self._credentials = Validator.validate_param(credentials, 'credentials')
        self._payload_format = Validator.validate_param(payload_format, 'payload_format')
        self._asset_endpoint = Validator.validate_param(asset_endpoint, 'asset_endpoint')

        if protocol is None:
           protocol = AssetCommunicationProtocol.MQTT

        self._protocol = protocol
Ejemplo n.º 2
0
 def create_asset_client(self, asset_id):
     """
     Create new asset client that communicates with lumada via the gateway
     :param asset_id: ID of the asset to create
     :return: Asset Client
     """
     Validator.validate_param(asset_id, 'AssetId')
     self._registration_client.verify_asset(asset_id=asset_id)
     asset_client = AssetClient.from_gateway(asset_id=asset_id,
                                             gateway_id=self._gateway_id,
                                             client=self._lumada_client)
     return asset_client
 def __init__(self,
              credentials=None,
              protocol=None,
              payload_format=None,
              asset_endpoint=None,
              gateway_id=None,
              registration_endpoint=None):
     LumadaClientConfig.__init__(self, credentials, protocol,
                                 payload_format, asset_endpoint)
     self._gateway_id = Validator.validate_param(gateway_id, 'gateway_id')
     self._registration_endpoint = Validator.validate_param(
         registration_endpoint, 'registration_endpoint')
    def _publish_message(self, obj, name, message_type):
        Validator.validate_param(obj, 'object (to publish)')

        if not self._client.is_connected():
            self._client.connect()

        payload = JsonUtil.serialize_json(obj)

        message = LumadaMessage(message_type=message_type,
                                message_name=name,
                                asset_id=self._asset_id,
                                gateway_id=self._gateway_id,
                                payload=payload)

        self._client.publish(message)
Ejemplo n.º 5
0
    def __init__(self, username, password):
        """
        Initializes requests session with lumada
        :param username: user to authenticate to lumada
        :param password: password to authenticate to lumada
        """
        self.session = requests.session()

        Validator.validate_param(username, 'username')
        Validator.validate_param(password, 'password')

        self._username = username
        self._password = password

        self.encode_creds(username=username, password=password)
Ejemplo n.º 6
0
 def __init__(self, hostname=None, trust_certs=False, require_secure=True):
     """
     :param hostname: Hostname for the lumada endpoint
     :param trust_certs: (Optional) If set to True, will trust all certificates. Default is False
     """
     self._hostname = Validator.validate_param(hostname, 'hostname')
     self._trust_all_certs = trust_certs
     self._require_secure = require_secure
Ejemplo n.º 7
0
    def register_asset_behind_gateway(self, asset_name, gateway_id, tags):
        """
        Registers an asset behind a gateway
        :param asset_name: Name of asset to register
        :param gateway_id: ID of the gateway to register the client
        :param tags: tags/params to be encoded on the url
        :return: asset client
        """
        Validator.validate_param(asset_name, 'AssetName')
        Validator.validate_param(gateway_id, 'GatewayId')

        asset_id = self._registration_client.register_asset(
            asset_name=asset_name, gateway_id=gateway_id, properties=tags)
        asset_client = AssetClient.from_gateway(asset_id=asset_id,
                                                gateway_id=self._gateway_id,
                                                client=self._lumada_client)

        return asset_client
Ejemplo n.º 8
0
 def __init__(self,
              credentials=None,
              protocol=None,
              payload_format=None,
              asset_endpoint=None,
              asset_id=None):
     LumadaClientConfig.__init__(self, credentials, protocol,
                                 payload_format, asset_endpoint)
     self.__asset_id = Validator.validate_param(asset_id, 'asset_id')
Ejemplo n.º 9
0
 def __init__(self, gateway_client_config):
     self._lumada_client = LumadaClient(
         Validator.validate_config_provided(gateway_client_config,
                                            'AssetClientConfig'))
     self._gateway_id = gateway_client_config.get_credentials(
     ).get_entity_id()
     self._gateway_value = gateway_client_config.get_credentials(
     ).get_entity_value()
     self._registration_client = AssetRegistrationClient(
         gateway_id=self._gateway_id,
         gateway_value=self._gateway_value,
         asset_registration_endpoint=gateway_client_config.
         get_registration_endpoint())
    def _get_publish_url(self,
                         asset_id=None,
                         gateway_id=None,
                         message_type=None,
                         message_name=None,
                         path=None):
        """
        Private: Returns a publishing URL
        :param asset_id: ID of the asset to publish
        :param gateway_id: ID of the gateway to publish
        :param message_type: Type of message to publish
        :param message_name: Name of message to publish
        :return: URL to post to
        """
        self.message_type = Validator.validate_param(message_type,
                                                     'message_type')
        self.asset_id = Validator.validate_param(asset_id, 'asset_id')

        if path is None:
            path = '/v1/asset-connectivity'

        if gateway_id is not None:
            path += '/gateways/%s/assets/%s/%s' % (
                str(gateway_id), str(asset_id), str(message_type))
        else:
            path += '/assets/%s/%s' % (str(asset_id), str(message_type))

        if message_name is not None:
            path += '/%s' % (str(message_name))

        publish_url = self._http_util.get_endpoint_url(
            hostname=self._channel_config.get_hostname(),
            path=path,
            params=None)

        return publish_url
 def __init__(self, lumada_client_config=None):
     self._client_config = Validator.validate_config_provided(lumada_client_config, 'LumadaClientConfig')
     self._communication_channel = self._create_lumada_communication_channel(self._client_config)
 def publish_event(self, name=None, obj=None):
     Validator.validate_param(name, 'event_name')
     self._publish_message(obj, name, LumadaMessageType.EVENT.value)
 def from_gateway(cls, asset_id=None, gateway_id=None, client=None):
     cls._client = Validator.validate_param(client, "lumada_client")
     cls._asset_id = Validator.validate_param(asset_id, "asset_id")
     cls._gateway_id = Validator.validate_param(gateway_id, "gateway_id")
     return cls()
Ejemplo n.º 14
0
 def add_cred_type_to_username(username=None):
     _cred_type = "devicehash"
     user = Validator.validate_param(username, 'username')
     cred_and_user = _cred_type + '.' + user
     return cred_and_user
Ejemplo n.º 15
0
 def __init__(self, entity_id=None, entity_value=None):
     self._entity_id = Validator.validate_param(entity_id, 'entity_id')
     self._entity_value = Validator.validate_param(entity_value,
                                                   'entity_value')