Ejemplo n.º 1
0
    def userPost(self, name: str, email: str, admin: bool,
                 getMethodsOnly: bool) -> dict:
        """
        Adds a new user, only accessible for admin users

        :param name: Name of the user account
        :param email: Email for the user account
        :param admin: If user account is a admin
        :param getMethodsOnly: If user account is read only
        :return: Newly created user account information

        If admin is set to false and getMethodsOnly is set to true then you create a read only or guest account
        """

        req = requests.post(
            url=self.server_address + f"/v2/user",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"},
            json={
                'name': name,
                'email': email,
                'admin': admin,
                'getMethodsOnly': getMethodsOnly
            },
            timeout=3)

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 2
0
    def login(self) -> str:
        """
        Gets the JWT token of the login endpoint

        :return: The JWT token of the login endpoint
        """

        try:
            req = requests.post(url=self.server_address + "/v2/login",
                                verify=False,
                                json={
                                    'user': self.username,
                                    'password': self.password
                                },
                                timeout=3)

            if req.status_code == 200:
                # Successfully logged in
                return req.json().get("JWT")
            else:
                check_status_code(req=req)

        except (TimeoutError, ConnectTimeoutError, MaxRetryError,
                RequestException):
            raise JWTError(
                status_code=401,
                message=
                "The wrong server IP address or login credentials were provided"
            )
Ejemplo n.º 3
0
    def userUUIDProfilePost(self, uuid: str, **kwargs) -> bool:
        """
        Updates user profile information

        :param uuid: Unique user ID
        :keyword name: Name of user account
        :keyword email: Email of user account
        :keyword oldPassword: Old password of user account
        :keyword newPassword: New password of user account
        :keyword acceptedEULA: If EULA has been accepted
        :return: Bool if user profile information has been updated or not
        """

        allowed = [
            'name', 'email', 'oldPassword', 'newPassword', 'acceptedEULA'
        ]
        body = {
            x: kwargs[x]
            for x in kwargs if x in allowed and kwargs[x] is not None
        }

        req = requests.post(
            url=self.server_address + f"/v2/user/{uuid}/profile",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"},
            json=body,
            timeout=3)

        if req.status_code == 200:
            return True
        else:
            check_status_code(req=req)
Ejemplo n.º 4
0
    def mqttMappingDelete(self, deleteAll: bool = False) -> dict:
        """
        Deletes all MQTT mappings from the service center

        :param deleteAll: Verifies deletion of all MQTT mappings is on purpose
        :return: Information on deleted MQTT mappings
        """

        req = requests.delete(url=self.server_address + f"/v2/mqttmapping?deleteAll={deleteAll}", verify=False,
                              headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 5
0
    def brokerBrokerIDGet(self, brokerID: str) -> dict:
        """
        Gets information about the requested MQTT broker

        :param brokerID: Unique MQTT broker ID
        :return: Detailed information about the requested MQTT broker
        """

        req = requests.get(url=self.server_address + f"/v2/broker/{brokerID}", verify=False,
                           headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 6
0
    def brokerBrokerIDDelete(self, brokerID: str) -> bool:
        """
        Deletes a single MQTT broker from the service center

        :param brokerID: Unique MQTT broker ID
        :return: Bool if the requested MQTT broker was deleted or not
        """

        req = requests.delete(url=self.server_address + f"/v2/broker/{brokerID}", verify=False,
                              headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return True
        else:
            check_status_code(req=req)
Ejemplo n.º 7
0
    def mqttMappingMappingIDGet(self, mappingID: str) -> dict:
        """
        Gets information about the requested MQTT mapping

        :param mappingID: Unique mapping ID
        :return: Detailed information about the requested MQTT mapping
        """

        req = requests.get(url=self.server_address + f"/v2/mqttmapping/{mappingID}",
                           verify=False, headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 8
0
    def systemBaseStationBsEuiGet(self, bsEui: str) -> dict:
        """
        Gets system status information for the requested base station

        :param bsEui: Unique bsEui of the requested base station
        :return: System status information for the requested base station
        """

        req = requests.get(url=self.server_address + f"/v2/system/basestation/{bsEui}", verify=False,
                           headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 9
0
    def pluginRegisterGet(self) -> dict:
        """
        Gets information about registered plugins

        :return: Information about registered plugins
        """

        req = requests.get(
            url=self.server_address + f"/v2/plugin/register",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 10
0
    def mqttMappingGet(self, returnCount: int = '', offset: int = '') -> dict:
        """
        Gets information about the requested MQTT mappings

        :param returnCount: The amount of MQTT mappings to be requested. -1 is ALL
        :param offset: The MQTT mappings count to start the MQTT mappings data request from
        :return: Detailed information about the requested MQTT mappings
        """

        req = requests.get(url=self.server_address + f"/v2/mqttmapping" + buildParameter(params=vars()), verify=False,
                           headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 11
0
    def systemGet(self) -> dict:
        """
        Gets system status information

        :return: Parser object of system status information
        """

        req = requests.get(
            url=self.server_address + f"/v2/system",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 12
0
    def systemEulaGet(self) -> str:
        """
        Gets the end user license agreement

        :return: The end user license agreement
        """

        req = requests.get(
            url=self.server_address + f"/v2/system/eula",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json().get("EULA")
        else:
            check_status_code(req=req)
Ejemplo n.º 13
0
    def userGet(self) -> dict:
        """
        Gets information on all registered users, only accessible for admin users

        :return: All registered users
        """

        req = requests.get(
            url=self.server_address + f"/v2/user",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 14
0
    def systemDatabaseDumpGet(self) -> dict:
        """
        Gets information about database dumpfiles and automatically deleted files

        :return: Information about database dumpfiles and automatically deleted files
        """

        req = requests.get(
            url=self.server_address + f"/v2/system/databasedump",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 15
0
    def authTicketGet(self) -> str:
        """
        Get ticket information from which you can request an upgrade to a websocket connection at /ws

        :return: Parser object of ticket information
        """

        req = requests.get(
            url=self.server_address + f"/v2/auth/ticket",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json().get("ticket")
        else:
            check_status_code(req=req)
Ejemplo n.º 16
0
    def userUUIDGet(self, uuid: str) -> dict:
        """
        Gets user information for the specified user, only accessible for admin users

        :param uuid: Unique user ID
        :return: User profile information
        """

        req = requests.get(
            url=self.server_address + f"/v2/user/{uuid}",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 17
0
    def azureFunctionIdGet(self, functionId: str) -> dict:
        """
        Gets information about the requested Azure function

        :param functionId: Unique Azure function ID
        :return: Detailed information about the requested Azure function
        """

        req = requests.get(
            url=self.server_address + f"/v2/azurefunction/{functionId}",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 18
0
    def azureFunctionIdDelete(self, functionId: str) -> bool:
        """
        Delete a single Azure function from the Service Center.

        :param functionId: Unique Azure function ID
        :return: Bool if Azure function has been successfully deleted or not
        """

        req = requests.delete(
            url=self.server_address + f"/v2/azurefunction/{functionId}",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return True
        else:
            check_status_code(req=req)
Ejemplo n.º 19
0
    def nodesEpEuiTxDataGet(self, epEui: str) -> dict:
        """
        Gets all downlink data quequed for the requested node

        :param epEui: Unique epEui of the node to request downlink data for
        :return: Information on the requested downlink data
        """

        req = requests.get(
            url=self.server_address + f"/v2/nodes/{epEui}/txdata",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 20
0
    def nodesEpEuiGet(self, epEui: str) -> NodeParser:
        """
        Gets information on a configured node with the matching epEui

        :param epEui: The unique epEui of the node to be requested
        :return: Information on the requested node
        """

        req = requests.get(
            url=self.server_address + f"/v2/nodes/{epEui}",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return NodeParser(req=req)
        else:
            check_status_code(req=req)
Ejemplo n.º 21
0
    def nodesEpEuiDelete(self, epEui: str) -> bool:
        """
        Deletes a single node from the service center

        :param epEui: The unique epEui of the node to be deleted
        :return: Bool if the requested node was deleted or not
        """

        req = requests.delete(
            url=self.server_address + f"/v2/nodes/{epEui}",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return True
        else:
            check_status_code(req=req)
Ejemplo n.º 22
0
    def sensorModelsSensorTypeGet(self, sensorType: str) -> ModelParser:
        """
        Gets information on a registered node model

        :param sensorType: Unique identifier of the node model to be requested
        :return: Parser object of configured node model
        """

        req = requests.get(
            url=self.server_address + f"/v2/sensormodels/{sensorType}",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return ModelParser(req=req)
        else:
            check_status_code(req=req)
Ejemplo n.º 23
0
    def messagesDelete(self, deleteAll: bool = False) -> dict:
        """
        Deletes all messages from the gateways

        :param deleteAll: Verifies deletion was on purpose
        :return: Deletion status information
        """

        req = requests.delete(
            url=self.server_address + f"/v2/messages?deleteAll={deleteAll}",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 24
0
    def pluginNameDelete(self, pluginName: str) -> bool:
        """
        Deletes and de-registers already accepted plugins

        :param pluginName: Name of the plugin to be deleted
        :return: Bool if plugin has been successfully deleted or not
        """

        req = requests.delete(
            url=self.server_address + f"/v2/plugin/{pluginName}",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return True
        else:
            check_status_code(req=req)
Ejemplo n.º 25
0
    def pluginNameMappingGet(self, pluginName: str) -> dict:
        """
        Gets information about all mappings to a plugin by name

        :param pluginName: Name of the plugin to get information on
        :return: Information about all mappings to a plugin by name
        """

        req = requests.get(
            url=self.server_address + f"/v2/plugin/{pluginName}/mapping",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 26
0
    def userUUIDDelete(self, uuid: str) -> bool:
        """
        Deletes the specified user, only accessible for admin users

        :param uuid: Unique user ID
        :return: Bool if user has been successfully deleted or not
        """

        req = requests.delete(
            url=self.server_address + f"/v2/user/{uuid}",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return True
        else:
            check_status_code(req=req)
Ejemplo n.º 27
0
    def systemBaseStationBsEuiDelete(self, bsEui: str) -> bool:
        """
        Deletes the requested base station from Mythings Central. This cancels the connection to the core. Normally,
        the core reconnects right after. This can be used to reset the bssci session with the core and the saved
        meta data.

        :param bsEui: Unique bsEui of the requested base station
        :return: Bool if the requested base station was deleted or not
        """

        req = requests.delete(url=self.server_address + f"/v2/system/basestation/{bsEui}", verify=False,
                              headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return True
        else:
            check_status_code(req=req)
Ejemplo n.º 28
0
    def azureMappingDelete(self, deleteAll: bool = False) -> dict:
        """
        Deletes all Azure mappings from the Service Center.

        :param deleteAll: Verifies deletion of all Azure mappings is on purpose
        :return: Number of Azure mappings deleted
        """

        req = requests.delete(
            url=self.server_address +
            f"/v2/azuremapping?deleteAll={deleteAll}",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 29
0
    def nodesEpEuiTxDataIdGet(self, epEui: str, messageId: str) -> dict:
        """
        Gets a specific downlink message for a specific node

        :param epEui: Unique epEui of the node to request a downlink message for
        :param messageId: Unique ID of the downlink message to request for a node
        :return: Message information of the requested message for a specific node
        """

        req = requests.get(
            url=self.server_address + f"/v2/nodes/{epEui}/txdata/{messageId}",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"})

        if req.status_code == 200:
            return req.json()
        else:
            check_status_code(req=req)
Ejemplo n.º 30
0
    def userUUIDResetPasswordPost(self, uuid: str) -> str:
        """
        Resets a users password to a randomly generated one, only accessible for admin users

        :param uuid: Unique user ID
        :return: New reset password for user
        """

        req = requests.post(
            url=self.server_address + f"/v2/user/{uuid}/resetpassword",
            verify=False,
            headers={"Authorization": f"Bearer {self.jwt_token}"},
            timeout=3)

        if req.status_code == 200:
            return req.json().get("password")
        else:
            check_status_code(req=req)