Skip to content

Commit

Permalink
Handle multiple requests
Browse files Browse the repository at this point in the history
  • Loading branch information
winstonsmith1897 committed Oct 11, 2023
1 parent e33faf4 commit ce2c7b2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
51 changes: 40 additions & 11 deletions application_manager/catch_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@
session_id = "None"
permit_installation = False
messages = []
denied_messages = []
num_request = 0
permit_messages = []

request_message_mapping = []

def set_request_message_mapping(tuple):
global request_message_mapping
request_message_mapping.append(tuple)
return request_message_mapping

def set_num_request(num):
global num_request
num_request = num

def set_messages(message_id):
global messages
Expand Down Expand Up @@ -200,6 +213,9 @@ def on_message(ws, message):
global REGISTERED
global session_id
global permit_installation
global messages, denied_messages, permit_messages
global num_request
global request_message_mapping
json_message = json.loads(message)

try:
Expand All @@ -215,19 +231,32 @@ def on_message(ws, message):
evaluation = json_value["command"]["value"]["message"][
"evaluation"
]
if evaluation == "Deny":
print("The Operation has been denied from a UCS")
notify_mobile_application(message=None)
else:
try:
if message_id in messages:
messages.remove(message_id)
if len(messages) == 0:
print("[!] Permit Installation")
handle_pull_image()
notify_mobile_application(
message="Application can be installed"
)

except Exception as e:
print(e)
if evaluation == "Deny":
denied_messages.append(message_id)
else:
permit_messages.append(message_id)

num_responses = len(denied_messages) + len(permit_messages)
if num_responses == num_request:
if len(permit_messages) == num_request:
print("[!] Permit Installation")
handle_pull_image()
notify_mobile_application(
message="Application can be installed"
)
else:
notify_mobile_application(message="Application not compliant")
for deny_id in denied_messages:
for id, req in request_message_mapping:
if id == deny_id:
notify_mobile_application(message=f"The not compliant id message is the following: {str(id)}") #TODO: to substitute with request fields
permit_messages = []
denied_messages = []
if (
json_value["command"]["value"]["topic_name"]
== "application_manager_registration"
Expand Down
6 changes: 6 additions & 0 deletions application_manager/security_by_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def xml_to_base64(xml_file_path):
request64 = b.decode("utf-8")

return request64

except Exception as e:
return str(e)

Expand Down Expand Up @@ -148,6 +149,7 @@ def get_labels(image_name):
source_path = "sifis-xacml/manifest_"
complete_path = source_path + image_name + "/"
files = os.listdir(complete_path)
catch_topic.set_num_request(len(files))
for file in files:
file_path = complete_path + file
formatted_json, message_id = handle_xcml_request(file_path)
Expand Down Expand Up @@ -187,6 +189,10 @@ def handle_xcml_request(file_path):
organized_json = organize_json(base64_content)
print(json.dumps(organized_json, indent=2))
message_id = organized_json["command"]["value"]["message"]["message_id"]
request = Path(file_path).read_text()
tup = (message_id, request)
catch_topic.set_request_message_mapping(tup)

return organized_json, message_id


Expand Down

0 comments on commit ce2c7b2

Please sign in to comment.