diff options
-rw-r--r-- | moon_interface/moon_interface/__init__.py | 2 | ||||
-rw-r--r-- | moon_interface/moon_interface/__main__.py | 4 | ||||
-rw-r--r-- | moon_interface/moon_interface/api/authz.py | 12 | ||||
-rw-r--r-- | moon_interface/moon_interface/api/generic.py | 45 | ||||
-rw-r--r-- | moon_interface/moon_interface/authz_requests.py | 15 | ||||
-rw-r--r-- | moon_interface/moon_interface/http_server.py | 19 | ||||
-rw-r--r-- | moon_interface/moon_interface/server.py | 20 | ||||
-rw-r--r-- | moon_interface/requirements.txt | 1 | ||||
-rw-r--r-- | moon_interface/setup.py | 2 | ||||
-rw-r--r-- | moon_interface/tests/unit_python/api/test_authz.py | 2 | ||||
-rw-r--r-- | moon_interface/tests/unit_python/conftest.py | 3 |
11 files changed, 50 insertions, 75 deletions
diff --git a/moon_interface/moon_interface/__init__.py b/moon_interface/moon_interface/__init__.py index 903c6518..6f964a63 100644 --- a/moon_interface/moon_interface/__init__.py +++ b/moon_interface/moon_interface/__init__.py @@ -3,4 +3,4 @@ # license which can be found in the file 'LICENSE' in this package distribution # or at 'http://www.apache.org/licenses/LICENSE-2.0'. -__version__ = "0.1.0" +__version__ = "4.3.2" diff --git a/moon_interface/moon_interface/__main__.py b/moon_interface/moon_interface/__main__.py index 517fdd60..9ad7bf2a 100644 --- a/moon_interface/moon_interface/__main__.py +++ b/moon_interface/moon_interface/__main__.py @@ -1,4 +1,4 @@ -from moon_interface.server import main +from moon_interface.server import create_server -server = main() +server = create_server() server.run() diff --git a/moon_interface/moon_interface/api/authz.py b/moon_interface/moon_interface/api/authz.py index a284ff3a..5739027d 100644 --- a/moon_interface/moon_interface/api/authz.py +++ b/moon_interface/moon_interface/api/authz.py @@ -10,15 +10,14 @@ from flask import request from flask_restful import Resource import logging import pickle -import requests import time from uuid import uuid4 from moon_interface.authz_requests import AuthzRequest -__version__ = "0.1.0" +__version__ = "4.3.1" -LOG = logging.getLogger("moon.interface.api.authz." + __name__) +logger = logging.getLogger("moon.interface.api.authz." + __name__) def pdp_in_cache(cache, uuid): @@ -72,6 +71,10 @@ def create_authz_request(cache, interface_name, manager_url, uuid, subject_name, return cache.authz_requests[req_id] +def delete_authz_request(cache, req_id): + cache.authz_requests.pop(req_id) + + class Authz(Resource): """ Endpoint for authz requests @@ -134,11 +137,14 @@ class Authz(Resource): cpt = 0 while True: if cpt > self.TIMEOUT*10: + delete_authz_request(self.CACHE, authz_request.request_id) return {"result": False, "message": "Authz request had timed out."}, 500 if authz_request.is_authz(): if authz_request.final_result == "Grant": + delete_authz_request(self.CACHE, authz_request.request_id) return {"result": True, "message": ""}, 200 + delete_authz_request(self.CACHE, authz_request.request_id) return {"result": False, "message": ""}, 401 cpt += 1 time.sleep(0.1) diff --git a/moon_interface/moon_interface/api/generic.py b/moon_interface/moon_interface/api/generic.py index 51de9214..dadac259 100644 --- a/moon_interface/moon_interface/api/generic.py +++ b/moon_interface/moon_interface/api/generic.py @@ -6,14 +6,14 @@ Those API are helping API used to manage the Moon platform. """ -from flask_restful import Resource, request +from flask_restful import Resource import logging import moon_interface.api from python_moonutilities.security_functions import check_auth -__version__ = "0.1.0" +__version__ = "4.3.1" -LOG = logging.getLogger("moon.interface.api." + __name__) +logger = logging.getLogger("moon.interface.api." + __name__) class Status(Resource): @@ -35,42 +35,7 @@ class Status(Resource): } } """ - raise NotImplemented - - -class Logs(Resource): - """ - Endpoint for logs requests - """ - - __urls__ = ("/logs", "/logs/", "/logs/<string:component_id>") - - def get(self, component_id=None): - """Get logs from the Moon platform - - :param component_id: the ID of the component your are looking for (optional) - :return: [ - "2015-04-15-13:45:20 - "2015-04-15-13:45:21 - "2015-04-15-13:45:22 - "2015-04-15-13:45:23 - ] - """ - filter_str = request.args.get('filter', '') - from_str = request.args.get('from', '') - to_str = request.args.get('to', '') - event_number = request.args.get('event_number', '') - try: - event_number = int(event_number) - except ValueError: - event_number = None - args = dict() - args["filter"] = filter_str - args["from"] = from_str - args["to"] = to_str - args["event_number"] = event_number - - raise NotImplemented + return {"result": True, "message": ""} class API(Resource): @@ -125,7 +90,7 @@ class API(Resource): if endpoint_id in api_desc[group_id]: return {group_id: {endpoint_id: api_desc[group_id][endpoint_id]}} elif len(endpoint_id) > 0: - LOG.error("Unknown endpoint_id {}".format(endpoint_id)) + logger.error("Unknown endpoint_id {}".format(endpoint_id)) return {"error": "Unknown endpoint_id {}".format(endpoint_id)} return {group_id: api_desc[group_id]} return api_desc diff --git a/moon_interface/moon_interface/authz_requests.py b/moon_interface/moon_interface/authz_requests.py index 3f99cb93..87e21152 100644 --- a/moon_interface/moon_interface/authz_requests.py +++ b/moon_interface/moon_interface/authz_requests.py @@ -7,11 +7,11 @@ import logging import itertools import pickle import requests -from python_moonutilities import configuration, exceptions -from python_moonutilities.security_functions import Context +from python_moonutilities import exceptions +from python_moonutilities.context import Context from python_moonutilities.cache import Cache -LOG = logging.getLogger("moon.interface.authz_requests") +logger = logging.getLogger("moon.interface.authz_requests") CACHE = Cache() @@ -51,7 +51,7 @@ class AuthzRequest: req.status_code )) except requests.exceptions.ConnectionError: - LOG.error("Cannot connect to {}".format( + logger.error("Cannot connect to {}".format( "http://{}:{}/authz".format( self.container_chaining[0]["hostip"], self.container_chaining[0]["port"] @@ -69,7 +69,7 @@ class AuthzRequest: req.status_code )) except requests.exceptions.ConnectionError: - LOG.error("Cannot connect to {}".format( + logger.error("Cannot connect to {}".format( "http://{}:{}/authz".format( self.container_chaining[0]["hostname"], self.container_chaining[0]["port"] @@ -152,8 +152,3 @@ class AuthzRequest: return True self.final_result = "Deny" return True - - # def notify(self, request_id, container_id, payload): - # LOG.info("notify {} {} {}".format(request_id, container_id, payload)) - # # TODO: send the notification and wait for the result - # # req = requests.get() diff --git a/moon_interface/moon_interface/http_server.py b/moon_interface/moon_interface/http_server.py index 72576f6c..57170985 100644 --- a/moon_interface/moon_interface/http_server.py +++ b/moon_interface/moon_interface/http_server.py @@ -4,19 +4,18 @@ # or at 'http://www.apache.org/licenses/LICENSE-2.0'. from flask import Flask, jsonify -from flask_cors import CORS, cross_origin from flask_restful import Resource, Api import logging from moon_interface import __version__ -from moon_interface.api.generic import Status, Logs, API +from moon_interface.api.generic import Status, API from moon_interface.api.authz import Authz from moon_interface.authz_requests import CACHE from python_moonutilities import configuration, exceptions -logger = logging.getLogger("moon.interface.http") +logger = logging.getLogger("moon.interface.http_server") __API__ = ( - Status, Logs, API + Status, API ) @@ -72,7 +71,8 @@ class Root(Resource): __methods = ("get", "post", "put", "delete", "options") def get(self): - tree = {"/": {"methods": ("get",), "description": "List all methods for that service."}} + tree = {"/": {"methods": ("get",), + "description": "List all methods for that service."}} for item in __API__: tree[item.__name__] = {"urls": item.__urls__} _methods = [] @@ -94,10 +94,9 @@ class HTTPServer(Server): self.app = Flask(__name__) self.port = port conf = configuration.get_configuration("components/manager") - self.manager_hostname = conf["components/manager"].get("hostname", "manager") + self.manager_hostname = conf["components/manager"].get("hostname", + "manager") self.manager_port = conf["components/manager"].get("port", 80) - #Todo : specify only few urls instead of * - CORS(self.app) self.api = Api(self.app) self.__set_route() self.__hook_errors() @@ -126,7 +125,9 @@ class HTTPServer(Server): resource_class_kwargs={ "cache": CACHE, "interface_name": self.host, - "manager_url": "http://{}:{}".format(self.manager_hostname, self.manager_port), + "manager_url": "http://{}:{}".format( + self.manager_hostname, + self.manager_port), } ) diff --git a/moon_interface/moon_interface/server.py b/moon_interface/moon_interface/server.py index 8b53d7f3..13955c3e 100644 --- a/moon_interface/moon_interface/server.py +++ b/moon_interface/moon_interface/server.py @@ -7,10 +7,10 @@ import logging from python_moonutilities import configuration, exceptions from moon_interface.http_server import HTTPServer -LOG = logging.getLogger("moon.interface.server") +logger = logging.getLogger("moon.interface.server") -def main(): +def create_server(): configuration.init_logging() try: conf = configuration.get_configuration("components/interface") @@ -21,11 +21,19 @@ def main(): hostname = "interface" bind = "127.0.0.1" port = 80 - configuration.add_component(uuid="interface", name=hostname, port=port, bind=bind) - LOG.info("Starting server with IP {} on port {} bind to {}".format(hostname, port, bind)) + configuration.add_component(uuid="interface", + name=hostname, + port=port, + bind=bind) + logger.info("Starting server with IP {} on port {} bind to {}".format( + hostname, port, bind)) return HTTPServer(host=bind, port=port) -if __name__ == '__main__': - server = main() +def run(): + server = create_server() server.run() + + +if __name__ == '__main__': + run() diff --git a/moon_interface/requirements.txt b/moon_interface/requirements.txt index 7aa2b6df..f22b38e7 100644 --- a/moon_interface/requirements.txt +++ b/moon_interface/requirements.txt @@ -1,4 +1,5 @@ flask flask_restful flask_cors +requests python_moonutilities
\ No newline at end of file diff --git a/moon_interface/setup.py b/moon_interface/setup.py index db15ff54..f358c598 100644 --- a/moon_interface/setup.py +++ b/moon_interface/setup.py @@ -40,7 +40,7 @@ setup( entry_points={ 'console_scripts': [ - 'moon_interface = moon_interface.server:main', + 'moon_interface = moon_interface.server:run', ], } diff --git a/moon_interface/tests/unit_python/api/test_authz.py b/moon_interface/tests/unit_python/api/test_authz.py index a63948f8..84605203 100644 --- a/moon_interface/tests/unit_python/api/test_authz.py +++ b/moon_interface/tests/unit_python/api/test_authz.py @@ -7,7 +7,7 @@ def get_json(data): def test_authz_true(context): import moon_interface.server - server = moon_interface.server.main() + server = moon_interface.server.create_server() client = server.app.test_client() req = client.get("/authz/{p_id}/{s_id}/{o_id}/{a_id}".format( p_id=context["project_id"], diff --git a/moon_interface/tests/unit_python/conftest.py b/moon_interface/tests/unit_python/conftest.py index 1f4e8cfa..35ee19d7 100644 --- a/moon_interface/tests/unit_python/conftest.py +++ b/moon_interface/tests/unit_python/conftest.py @@ -5,7 +5,6 @@ import pickle import pytest import requests_mock from uuid import uuid4 -from requests.packages.urllib3.response import HTTPResponse CONF = { "openstack": { @@ -205,7 +204,7 @@ def set_env_variables(): def get_pickled_context(): - from python_moonutilities.security_functions import Context + from python_moonutilities.context import Context from python_moonutilities.cache import Cache CACHE = Cache() CACHE.update() |