From 8b33c737355a47252b05ca5a8011cf9061fd0676 Mon Sep 17 00:00:00 2001 From: Ahmed Osman <ah_osman@yahoo.com> Date: Wed, 27 Sep 2023 23:06:55 +0200 Subject: [PATCH] Update file README.md --- demos/demo2/README.md | 60 +++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/demos/demo2/README.md b/demos/demo2/README.md index 08afa06..e6c5d9b 100644 --- a/demos/demo2/README.md +++ b/demos/demo2/README.md @@ -42,27 +42,59 @@ S3IBAsyncClient's sendUserMessage Method: Security-related data can be stored in the security submodel (refer to /model/security.py). It contains AccessControl, a SubmodelElementList of AccessRuleCollection. The latter is a SubmodelElementCollection, that contains a SubmodelElementList of AccessPermissonRule (a SubmodelElementCollection with the user the permission is being granted to, the permission type for example ALLOW, and the permisson for example READ) and the Target (a ReferenceElement that refers to the AAS-Element the rules apply to). ``` - rules = [security.AccessPermissionRule(forestmanager_hmi_id, - security.PermissionKind.ALLOW, - security.Permission.READ), - security.AccessPermissionRule(forestmanager_hmi_id, - security.PermissionKind.ALLOW, - security.Permission.WRITE)] - - rules_smc = security.AccessPermissionCollection( - target=model.ModelReference.from_referable(aas_dz_wald), - rules=rules - ) +rules = [security.AccessPermissionRule(forestmanager_hmi_id, + security.PermissionKind.ALLOW, + security.Permission.READ), + security.AccessPermissionRule(forestmanager_hmi_id, + security.PermissionKind.ALLOW, + security.Permission.WRITE)] + +rules_smc = security.AccessPermissionCollection( + target=model.ModelReference.from_referable(aas_dz_wald), + rules=rules +) - access_control = security.AccessControl(permissions=[rules_smc]) +access_control = security.AccessControl(permissions=[rules_smc]) - security_sm = security.Security("https://www.company.com/security") - security_sm.add_referable(access_control) +security_sm = security.Security("https://www.company.com/security") +security_sm.add_referable(access_control) ``` Since permission-granting decisions are made by the opa-server (if security enabled), this data must provided (in simpler format) to it and continiously updated (if changes occur). This is handled by the S3IBServer Component utilizing the security.py::get_dict_from_security_submodel method. +### Events + +Create server-side Events (S3IBServer expects events to be stored in a separate submodel with a fixed id). +In the following, any changes (received set-Requests) to Auftragsstatus cause an event message to be sent to topic123 (and all queues bound/subscribed to it): + +``` +events = model.Submodel( + id_="https://www.company.com/submodels/events", + id_short="Events" +) + +event = model.BasicEventElement( + id_short="Auftragsstatus_Updated", + observed=model.ModelReference.from_referable(arbeitsauftrag.get_referable(configs.AUFTRAGSSTATUS)), + direction=model.Direction.OUTPUT, + state=model.StateOfEvent.ON, + message_topic="topic123" +) + +events.add_referable(event) +``` + +On client-side events can be subscribed to and awaited using S3IBAsyncClient's awaitEvent method: + +``` +events_submodel_id = "https://www.company.com/submodels/events" +events_submodel_id_encoded = base64.urlsafe_b64encode(events_submodel_id.encode()).decode() +event: model.BasicEventElement = await client.getValue(dzwald_id, dzwald_endpoint, + f"/aas/submodels/{events_submodel_id_encoded} \ + /submodel/submodelElements/Auftragsstatus_Updated") +auftragsstatus_updated = await client.awaitEvent(event.message_topic) +``` -- GitLab