From 6a69ed40b144ec53f82888cdb298de2ad852e83d Mon Sep 17 00:00:00 2001 From: Akashdeep Dhar Date: Jan 30 2021 06:44:37 +0000 Subject: Added a connection examination endpoint and used first tag as name Signed-off-by: Akashdeep Dhar --- diff --git a/dish/back.py b/dish/back.py index 91aed70..e78af91 100644 --- a/dish/back.py +++ b/dish/back.py @@ -116,7 +116,7 @@ class DockerImageInformation: for indx in imejlist: dispdict[indx.short_id] = { "id": indx.id, - "name": indx.name, + "name": indx.tags[0], } return dispdict diff --git a/falc.py b/falc.py index 9c519c4..453af3f 100644 --- a/falc.py +++ b/falc.py @@ -19,6 +19,7 @@ ########################################################################## """ +import json from secrets import choice import click @@ -51,6 +52,21 @@ class ConnectionManager: return retndata +class ConnectionExaminationEndpoint(object): + def __init__(self, passcode): + self.passcode = passcode + + def on_get(self, rqst, resp): + passcode = rqst.get_param("passcode") + if passcode == self.passcode: + retnjson = {"retnmesg": "allow"} + else: + retnjson = {"retnmesg": "deny"} + resp.body = json.dumps(retnjson, ensure_ascii=False) + resp.set_header("Access-Control-Allow-Origin", "*") + resp.status = falcon.HTTP_200 + + @click.command() @click.option("-p", "--portdata", "portdata", help="Set the port value [0-65536].", default="6969") @click.option("-u", "--unixsock", "unixsock", help="Set the UNIX socket for Docker.", default="unix://var/run/docker.sock") @@ -95,6 +111,7 @@ def mainfunc(portdata, netprotc, unixsock): dishimej = ImageInformationEndpoint(passcode, unixsock) dishntwk = NetworkInformationEndpoint(passcode, unixsock) dishvolm = VolumeInformationEndpoint(passcode, unixsock) + testconn = ConnectionExaminationEndpoint(passcode) main.add_route("/basestat", basestat) main.add_route("/basepsin", basepsin) main.add_route("/basetool", basetool) @@ -103,6 +120,7 @@ def mainfunc(portdata, netprotc, unixsock): main.add_route("/dishimej", dishimej) main.add_route("/dishntwk", dishntwk) main.add_route("/dishvolm", dishvolm) + main.add_route("/testconn", testconn) serving.run_simple(netpdata, int(portdata), main) except Exception as expt: click.echo(" * " + click.style("Error occurred : " + str(expt), fg="red"))