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 bc5ca9c commit e33faf4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
22 changes: 17 additions & 5 deletions application_manager/catch_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
registration_id = 1
session_id = "None"
permit_installation = False
messages = []


def set_messages(message_id):
global messages
messages.append(message_id)


def UCS_request(ws, topic_name, topic_uuid, request_id, requestor_id):
Expand Down Expand Up @@ -203,18 +209,24 @@ def on_message(ws, message):
purpose = json_value["command"]["value"]["message"]["purpose"]

if purpose == "TRY_RESPONSE":
message_id = json_value["command"]["value"]["message"][
"message_id"
]
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:
print("[!] Permit Installation")
handle_pull_image()
notify_mobile_application(
message="Application can be installed"
)
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"
)

if (
json_value["command"]["value"]["topic_name"]
Expand Down
16 changes: 11 additions & 5 deletions application_manager/security_by_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uuid
from pathlib import Path

import catch_topic
import requests

REGISTERED = False
Expand Down Expand Up @@ -144,8 +145,14 @@ def get_labels(image_name):
path = "sifis-xacml/data/"
save_manifest_to_file(manifest_data, path + json_filename)
run_cargo_command(json_filename)
formatted_json, message_id = handle_xcml_request(image_name)
requests.post(websocket_uri + "pub", json=formatted_json)
source_path = "sifis-xacml/manifest_"
complete_path = source_path + image_name + "/"
files = os.listdir(complete_path)
for file in files:
file_path = complete_path + file
formatted_json, message_id = handle_xcml_request(file_path)
catch_topic.set_messages(message_id)
requests.post(websocket_uri + "pub", json=formatted_json)
return json_filename, message_id
except subprocess.CalledProcessError as e:
print("Error during script execution:", e)
Expand Down Expand Up @@ -174,9 +181,8 @@ def _extract_labels(image_name, script_file, sifis_prefix, version):
return manifest_data


def handle_xcml_request(image_name):
source_path = "sifis-xacml/manifest_"
file_path = source_path + image_name + "/request_1.xml"
def handle_xcml_request(file_path):
# file_path = source_path + image_name + "/request_1.xml"
base64_content = xml_to_base64(file_path)
organized_json = organize_json(base64_content)
print(json.dumps(organized_json, indent=2))
Expand Down

0 comments on commit e33faf4

Please sign in to comment.