Skip to content

Commit

Permalink
Merge pull request #28 from aiial/release-3.1.1
Browse files Browse the repository at this point in the history
Release 3.1.1
  • Loading branch information
AdamMiltonBarker authored Sep 12, 2021
2 parents 371901a + 1d5f40c commit 7b86482
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 391 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

![HIAS MQTT IoT Agent](assets/images/project-banner.jpg)

[![CURRENT RELEASE](https://img.shields.io/badge/CURRENT%20RELEASE-3.1.0-blue.svg)](https://github.com/aiial/hias-mqtt-iot-agent/tree/release-3.1.0) [![UPCOMING RELEASE](https://img.shields.io/badge/DEV%20BRANCH-develop-blue.svg)](https://github.com/aiial/hias-mqtt-iot-agent/tree/develop) [![Contributions Welcome!](https://img.shields.io/badge/Contributions-Welcome-lightgrey.svg)](CONTRIBUTING.md) [![Issues](https://img.shields.io/badge/Issues-Welcome-lightgrey.svg)](issues)
[![CURRENT RELEASE](https://img.shields.io/badge/CURRENT%20RELEASE-3.1.1-blue.svg)](https://github.com/aiial/hias-mqtt-iot-agent/tree/release-3.1.1) [![UPCOMING RELEASE](https://img.shields.io/badge/DEV%20BRANCH-develop-blue.svg)](https://github.com/aiial/hias-mqtt-iot-agent/tree/develop) [![Contributions Welcome!](https://img.shields.io/badge/Contributions-Welcome-lightgrey.svg)](CONTRIBUTING.md) [![Issues](https://img.shields.io/badge/Issues-Welcome-lightgrey.svg)](issues)

[![PEP8](https://img.shields.io/badge/code%20style-pep8-orange.svg)](https://www.python.org/dev/peps/pep-0008/) [![Documentation Status](https://readthedocs.org/projects/hias-mqtt-iot-agent/badge/?version=latest)](https://hias-mqtt-iot-agent.readthedocs.io/en/latest/?badge=latest)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/4994/badge)](https://bestpractices.coreinfrastructure.org/projects/4994)
Expand Down
492 changes: 246 additions & 246 deletions agent.py

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions modules/AbstractAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,32 @@ def __init__(self):
self.hiashdi = None
self.mqtt = None

self.appTypes = ["Robotics", "Application", "Staff"]
self.ignoreTypes = ["Robotics", "HIASCDI", "HIASHDI", "HIASBCH", "Staff"]
self.app_types = ["Robotics", "Application", "Staff"]
self.ignore_types = ["Robotics", "HIASCDI", "HIASHDI", "HIASBCH", "Staff"]

self.helpers = helpers("Agent")
self.confs = self.helpers.confs
self.credentials = self.helpers.credentials

self.helpers.logger.info("Agent initialization complete.")

def hiascdiConn(self):
def hiascdi_connection(self):
"""Instantiates the HIASCDI Contextual Data Interface connection. """

self.hiascdi = hiascdi(self.helpers)

self.helpers.logger.info(
"HIASCDI Contextual Data Interface connection instantiated.")

def hiashdiConn(self):
def hiashdi_connection(self):
"""Instantiates the HIASCDI Historical Data Interface connection. """

self.hiashdi = hiashdi(self.helpers)

self.helpers.logger.info(
"HIASHDI Historical Data Interface connection instantiated.")

def mqttConn(self, credentials):
def mqtt_connection(self, credentials):
"""Initializes the HIAS MQTT connection. """

self.mqtt = mqtt(self.helpers, "Agent", credentials)
Expand All @@ -97,7 +97,7 @@ def mqttConn(self, credentials):
self.helpers.logger.info(
"HIAS iotJumpWay MQTT Broker connection created.")

def hiasbchConn(self):
def hiasbch_connection(self):
"""Initializes the HIASBCH connection. """

self.hiasbch = hiasbch(self.helpers)
Expand All @@ -109,23 +109,23 @@ def hiasbchConn(self):
self.helpers.logger.info(
"HIAS HIASBCH Blockchain connection created.")

def getRequiredAttributes(self, entityType, entity):
def get_attributes(self, entity_type, entity):
"""Gets entity attributes from HIASCDI.
Args:
entityType (str): The HIASCDI Entity type.
entity_type (str): The HIASCDI Entity type.
entity (str): The entity id.
Returns:
dict: Required entity attributes
"""

attrs = self.hiascdi.getRequiredAttributes(entityType, entity)
attrs = self.hiascdi.get_attributes(entity_type, entity)

rattrs = {}

if entityType in self.appTypes:
if entity_type in self.app_types:
rattrs["id"] = attrs["id"]
rattrs["type"] = attrs["type"]
rattrs["blockchain"] = attrs["authenticationBlockchainUser"]["value"]
Expand Down
4 changes: 2 additions & 2 deletions modules/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, ltype, log=True):

# Loads system configs
self.confs = {}
self.loadConfs()
self.load_confs()

# Sets system logging
self.logger = logging.getLogger(ltype)
Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(self, ltype, log=True):
if log is True:
self.logger.info("Helpers class initialization complete.")

def loadConfs(self):
def load_confs(self):
""" Load the configuration. """

with open(os.path.dirname(os.path.abspath(__file__)) + '/../configuration/credentials.json') as credentials:
Expand Down
34 changes: 1 addition & 33 deletions modules/hiasbch.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def start(self):
abi=json.dumps(self.credentials["hiasbch"]["contracts"]["iotJumpWay"]["abi"]))
self.helpers.logger.info("HIASBCH connections started")

def iotJumpWayAccessCheck(self, address):
def iotjumpway_access_check(self, address):
""" Checks sender is allowed access to the iotJumpWay Smart Contract """

self.helpers.logger.info("HIASBCH checking " + address)
Expand All @@ -78,35 +78,3 @@ def iotJumpWayAccessCheck(self, address):
else:
return True

def hash(self, data):
""" Hashes Command data for data integrity. """

hashString = ""

for value in data:
if value != "_id":
hashString += str(data[value])

hashed = bcrypt.hashpw(hashString.encode(), bcrypt.gensalt())

return hashed

def storeHash(self, id, hashed, at, inserter, identifier, to, typeof):
""" Stores data hash in the iotJumpWay smart contract """

try:
txh = self.iotContract.functions.registerHash(id, hashed, at, 0, identifier, self.w3.toChecksumAddress(to)).transact({
"from": self.w3.toChecksumAddress(self.credentials["hiasbch"]["un"]),
"gas": 1000000})
self.helpers.logger.info("HIASBCH Data Transaction OK!")
txr = self.w3.eth.waitForTransactionReceipt(txh)
if txr["status"] is 1:
self.helpers.logger.info("HIASBCH Data Hash OK!")
else:
self.helpers.logger.error("HIASBCH Data Hash KO!")
except:
e = sys.exc_info()
self.helpers.logger.error("HIASBCH Data Hash KO!")
self.helpers.logger.error(str(e))
self.helpers.logger.error(str(e))

36 changes: 18 additions & 18 deletions modules/hiascdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,66 +58,66 @@ def __init__(self, helpers):

self.helpers.logger.info("HIASCDI initialization complete.")

def getRequiredAttributes(self, entityType, entity):
def get_attributes(self, entity_type, entity):
""" Gets required attributes. """

if entityType in ["Robotics","Application","Staff"]:
if entity_type in ["Robotics","Application","Staff"]:
params = "&attrs=id,type,authenticationBlockchainUser.value,networkLocation.value"
else:
params = "&attrs=id,type,authenticationBlockchainUser.value,networkLocation.value,networkZone.value"

apiHost = "https://" + self.helpers.credentials["server"]["host"] + \
api_host = "https://" + self.helpers.credentials["server"]["host"] + \
self.helpers.credentials["hiascdi"]["endpoint"]
apiEndpoint = "/entities/" + entity + "?type=" + entityType + params
apiURL = apiHost + apiEndpoint
api_endpoint = "/entities/" + entity + "?type=" + entity_type + params
api_url = api_host + api_endpoint

response = requests.get(apiURL, headers=self.headers, auth=self.auth)
response = requests.get(api_url, headers=self.headers, auth=self.auth)

return json.loads(response.text)

def updateEntity(self, _id, typer, data):
def update_entity(self, _id, typer, data):
""" Updates an entity. """

apiUrl = "https://" + self.helpers.credentials["server"]["host"] + "/" + \
api_url = "https://" + self.helpers.credentials["server"]["host"] + "/" + \
self.helpers.credentials["hiascdi"]["endpoint"] + \
"/entities/" + _id + "/attrs?type=" + typer

response = requests.post(apiUrl, data=json.dumps(
response = requests.post(api_url, data=json.dumps(
data), headers=self.headers, auth=self.auth)
if response.status_code == 204:
return True
else:
return False

def getSensors(self, _id, typeof):
def get_sensors(self, _id, typeof):
""" Gets sensor list. """

apiUrl = "https://" + self.helpers.credentials["server"]["host"] + "/" + \
api_url = "https://" + self.helpers.credentials["server"]["host"] + "/" + \
self.helpers.credentials["hiascdi"]["endpoint"] + \
"/entities/" + _id + "?type=" + typeof + "&attrs=sensors"

response = requests.get(apiUrl, headers=self.headers, auth=self.auth)
response = requests.get(api_url, headers=self.headers, auth=self.auth)

return json.loads(response.text)

def getActuators(self, _id, typeof):
def get_actuators(self, _id, typeof):
""" Gets actuator list. """

apiUrl = "https://" + self.helpers.credentials["server"]["host"] + "/" + \
api_url = "https://" + self.helpers.credentials["server"]["host"] + "/" + \
self.helpers.credentials["hiascdi"]["endpoint"] + \
"/entities/" + _id + "?type=" + typeof + "&attrs=actuators"

response = requests.get(apiUrl, headers=self.headers, auth=self.auth)
response = requests.get(api_url, headers=self.headers, auth=self.auth)

return json.loads(response.text)

def getAiModels(self, _id, typeof):
def get_ai_models(self, _id, typeof):
""" Gets AI Agent models. """

apiUrl = "https://" + self.helpers.credentials["server"]["host"] + "/" + \
api_url = "https://" + self.helpers.credentials["server"]["host"] + "/" + \
self.helpers.credentials["hiascdi"]["endpoint"] + \
"/entities/" + _id + "?type=" + typeof + "&attrs=models"

response = requests.get(apiUrl, headers=self.headers, auth=self.auth)
response = requests.get(api_url, headers=self.headers, auth=self.auth)

return json.loads(response.text)
10 changes: 5 additions & 5 deletions modules/hiashdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ def __init__(self, helpers):

self.helpers.logger.info("HIASHDI initialization complete.")

def insertData(self, typeof, data):
def insert_data(self, typeof, data):
""" Inserts data into HIASHDI. """

apiHost = "https://" + self.helpers.credentials["server"]["host"] + "/" + \
api_host = "https://" + self.helpers.credentials["server"]["host"] + "/" + \
self.helpers.credentials["hiashdi"]["endpoint"]
apiEndpoint = "/data?type=" + typeof
apiURL = apiHost + apiEndpoint
api_endpoint = "/data?type=" + typeof
api_url = api_host + api_endpoint

response = requests.post(apiURL, data=json.dumps(
response = requests.post(api_url, data=json.dumps(
data), headers=self.headers, auth=self.auth)

if response.status_code == 201:
Expand Down
Loading

0 comments on commit 7b86482

Please sign in to comment.