Skip to content

Commit

Permalink
Add notification message for mobile application
Browse files Browse the repository at this point in the history
  • Loading branch information
winstonsmith1897 committed Aug 28, 2023
1 parent 28fd768 commit d7b6ebc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
5 changes: 0 additions & 5 deletions application_manager/app_dht.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ def pull_image(ws, image_name, topic_uuid, requestor_id, request_id):
topic_name = "SIFIS:application_manager_pull_image"
result = update_dht_list(ws, image_name)
if result != "Already Installed":
print("ciao")
client.images.pull(image_name)
# update_dht_list(ws, image_name)
print("pippo")
pulling_data = {
"requestor_id": requestor_id,
"request_id": request_id,
Expand Down Expand Up @@ -225,14 +223,11 @@ def remove_image(image_name, topic_uuid, request_id, requestor_id):
"operation": "remove image",
"result": "successfull",
}
print("prima di inviare immagine rimossa")
requests.post(
api_url + "topic_name/" + topic_name + "/topic_uuid/" + topic_uuid,
json=removing_info,
)
print("dopo di inviare immagine rimossa")
list_containers(topic_uuid, requestor_id, request_id, image_name)
print("dopo list")
client.images.remove(image_name, force=True)
return f"Image {image_name} removed successfully!"
except docker.errors.ImageNotFound as e:
Expand Down
52 changes: 32 additions & 20 deletions application_manager/catch_topic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

import app_dht
import requests
import security_by_contract
import websocket

Expand All @@ -10,35 +11,45 @@
permit_installation = False


def UCS_request(ws, topic_name, topic_uuid):
def UCS_request(ws, topic_name, topic_uuid, request_id, requestor_id):
global REGISTERED, session_id
try:
image_name = topic_name["image_name"]
print("[!] Recovering App LABELS\n")
_, app_id = security_by_contract.get_labels(image_name)
session_id = app_id
print("[!] APP_ID: " + str(session_id))
return
if session_id == "None":
notify_mobile_application(
image_name, topic_uuid, request_id, requestor_id
)
else:
print("[!] APP_ID: " + str(session_id))
return
except Exception as e:
print(e)


"""
def handle_pull_image(ws, topic_name, topic_uuid):
global REGISTERED, session_id
print("Permit Installation")
print(permit_installation)
try:
image_name = topic_name["image_name"]
requestor_id = topic_name["requestor_id"]
request_id = topic_name["request_id"]
result = app_dht.pull_image(
ws, image_name, topic_uuid, requestor_id, request_id
)
print(result)
except Exception as e:
print(e)
"""
def notify_mobile_application(
image_name, topic_uuid, request_id, requestor_id
):
topic_name = "SIFIS:notification_message"
print("[!] " + notification)
notification = (
"The "
+ image_name
+ " cannot be installed, the operation is NOT permitted by Usage Control"
)
address = "http://sifis-device4.iit.cnr.it:3000/"
notification_data = {
"requestor_id": requestor_id,
"request_id": request_id,
"message": notification,
}
requests.post(
address + "topic_name/" + topic_name + "/topic_uuid/" + topic_uuid,
json=notification_data,
)
return


def handle_pull_image():
Expand Down Expand Up @@ -161,6 +172,7 @@ def on_message(ws, message):
json_message = json_message["Volatile"]
json_value = json_message["value"]
purpose = json_value["command"]["value"]["message"]["purpose"]

if purpose == "TRY_RESPONSE":
print("[!] Permit Installation")
handle_pull_image()
Expand Down Expand Up @@ -212,7 +224,7 @@ def handle_message(ws, topic_uuid, topic_value, request_id, requestor_id):
operation = topic_value["operation"]
if operation == "pull_image":
print("[!] Forwarding UCS Request")
UCS_request(ws, topic_value, topic_uuid)
UCS_request(ws, topic_value, topic_uuid, request_id, requestor_id)
print("[!] Pulling Image Request")
params = {
"ws": ws,
Expand Down

0 comments on commit d7b6ebc

Please sign in to comment.