diff --git a/magma/hackfest_squid_cnf/charms/squid/actions.yaml b/magma/hackfest_squid_cnf/charms/squid/actions.yaml index 687a92f472077e9331574ece57077fa2fd2b40c1..3e57d8e3987419e2857c90ffdef8a8a9bff4256f 100644 --- a/magma/hackfest_squid_cnf/charms/squid/actions.yaml +++ b/magma/hackfest_squid_cnf/charms/squid/actions.yaml @@ -1,13 +1,14 @@ addurl: - description: "Add squid config" + description: "Add allowed URL to squid config" params: url: description: "URL that will be allowed" type: string default: "" -start: - description: "Start squid service" -restart: - description: "Retart squid service" -stop: - description: "Stop squid service" +deleteurl: + description: "Delete allowed URL squid config" + params: + url: + description: "URL that will stop to be allowed" + type: string + default: "" diff --git a/magma/hackfest_squid_cnf/charms/squid/actions/restart b/magma/hackfest_squid_cnf/charms/squid/actions/restart deleted file mode 100755 index d6c3f2e332da657e91b00dff2a9d1eb0ac7a2cab..0000000000000000000000000000000000000000 --- a/magma/hackfest_squid_cnf/charms/squid/actions/restart +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -service squid restart diff --git a/magma/hackfest_squid_cnf/charms/squid/actions/start b/magma/hackfest_squid_cnf/charms/squid/actions/start deleted file mode 100755 index 1f62c7bda6c6728185ceaefcc61b7eb4beb7c892..0000000000000000000000000000000000000000 --- a/magma/hackfest_squid_cnf/charms/squid/actions/start +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -service squid start diff --git a/magma/hackfest_squid_cnf/charms/squid/actions/stop b/magma/hackfest_squid_cnf/charms/squid/actions/stop deleted file mode 100755 index 536232dda6aed199a676a9ac2ff7eb212d413d84..0000000000000000000000000000000000000000 --- a/magma/hackfest_squid_cnf/charms/squid/actions/stop +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -service squid stop diff --git a/magma/hackfest_squid_cnf/charms/squid/config.yaml b/magma/hackfest_squid_cnf/charms/squid/config.yaml index 7efafff5e232f3cf3e7b1e8d0decdb6cd6e3f224..65c33a86fdcdd7228c88268a6ae9a65f71efb8d3 100644 --- a/magma/hackfest_squid_cnf/charms/squid/config.yaml +++ b/magma/hackfest_squid_cnf/charms/squid/config.yaml @@ -2,7 +2,7 @@ options: image: type: string description: 'Docker image for squid' - default: 'sameersbn/squid:latest' + default: 'domfleischmann/squid-python' port: type: int description: 'Port' diff --git a/magma/hackfest_squid_cnf/charms/squid/src/charm.py b/magma/hackfest_squid_cnf/charms/squid/src/charm.py index 67383ee8f7b818495f4c6306d8614290d684478a..f15c42e4d3931c307b6c18e1b4f8c42337a62d5e 100755 --- a/magma/hackfest_squid_cnf/charms/squid/src/charm.py +++ b/magma/hackfest_squid_cnf/charms/squid/src/charm.py @@ -12,6 +12,7 @@ from ops.charm import CharmBase from ops.framework import StoredState from ops.main import main from ops.model import ActiveStatus, MaintenanceStatus +import subprocess class SquidK8SCharm(CharmBase): @@ -26,7 +27,7 @@ class SquidK8SCharm(CharmBase): self.framework.observe(self.on.install, self.on_install) self.framework.observe(self.on.start, self.on_start) self.framework.observe(self.on.config_changed, self.on_config_changed) -# self.framework.observe(self.on.addconfig_action, self) + self.framework.observe(self.on.deleteurl_action, self) # -- initialize states -- self.state.set_default(installed=False) self.state.set_default(configured=False) @@ -91,6 +92,29 @@ class SquidK8SCharm(CharmBase): self.state.started = True logging.info("Started") + def on_deleteurl_action(self, event): + """Handle the deleteurl action.""" + url = event.params["url"] + + line_to_delete = "acl allowedurls dstdomain .{}".format(url) + line_deleted = False + + with open("/etc/squid/squid.conf", "r") as f: + lines = f.readlines() + with open("/etc/squid/squid.conf", "w") as f: + for line in lines: + if line_to_delete not in line: + f.write(line) + else: + line_deleted = True + + if line_deleted: + event.set_results({"output": "URL deleted succesfully"}) + subprocess.check_output("kill -HUP `cat /var/run/squid.pid`", shell=True) + else: + event.fail("No URL was deleted") + + if __name__ == "__main__": from ops.main import main main(SquidK8SCharm) diff --git a/magma/hackfest_squid_cnf/squid_vnf.yaml b/magma/hackfest_squid_cnf/squid_vnf.yaml index e77ebb3f82da08e99ea30e357591917db37f4448..b15c49d1dd294720a43857f194ddeacd0235af02 100644 --- a/magma/hackfest_squid_cnf/squid_vnf.yaml +++ b/magma/hackfest_squid_cnf/squid_vnf.yaml @@ -11,22 +11,15 @@ vnfd-catalog: juju-bundle: bundle.yaml kdu-configuration: config-primitive: - - name: restart - parameter: - - name: application-name - data-type: STRING - default-value: squid - - name: start + - name: addurl parameter: - name: application-name data-type: STRING default-value: squid - - name: stop - parameter: - - name: application-name + - name: url data-type: STRING - default-value: squid - - name: addurl + default-value: "" + - name: deleteurl parameter: - name: application-name data-type: STRING