Clean the code of Manager 99/50099/1
authorThomas Duval <thomas.duval@orange.com>
Fri, 5 Jan 2018 10:42:39 +0000 (11:42 +0100)
committerThomas Duval <thomas.duval@orange.com>
Fri, 5 Jan 2018 10:42:39 +0000 (11:42 +0100)
Change-Id: I636631929cfdf197a28debbfdf1df863b30445b3

16 files changed:
moon_manager/moon_manager/__init__.py
moon_manager/moon_manager/__main__.py
moon_manager/moon_manager/api/assignments.py
moon_manager/moon_manager/api/data.py
moon_manager/moon_manager/api/generic.py
moon_manager/moon_manager/api/meta_data.py
moon_manager/moon_manager/api/meta_rules.py
moon_manager/moon_manager/api/models.py
moon_manager/moon_manager/api/pdp.py
moon_manager/moon_manager/api/perimeter.py
moon_manager/moon_manager/api/policies.py
moon_manager/moon_manager/api/rules.py
moon_manager/moon_manager/http_server.py
moon_manager/moon_manager/server.py
moon_manager/setup.py
moon_manager/tests/unit_python/api/utilities.py

index 903c651..6f964a6 100644 (file)
@@ -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"
index 7d97f00..4fed8d1 100644 (file)
@@ -1,4 +1,4 @@
-from moon_manager.server import main
+from moon_manager.server import create_server
 
-server = main()
+server = create_server()
 server.run()
index c3ac45c..0b2cd20 100644 (file)
@@ -9,13 +9,13 @@ Assignments allow to connect data with elements of perimeter
 
 from flask import request
 from flask_restful import Resource
-from oslo_log import log as logging
+import logging
 from python_moonutilities.security_functions import check_auth
 from python_moondb.core import PolicyManager
 
-__version__ = "0.2.0"
+__version__ = "4.3.2"
 
-LOG = logging.getLogger("moon.manager.api." + __name__)
+logger = logging.getLogger("moon.manager.api." + __name__)
 
 
 class SubjectAssignments(Resource):
@@ -32,7 +32,8 @@ class SubjectAssignments(Resource):
     )
 
     @check_auth
-    def get(self, uuid=None, perimeter_id=None, category_id=None, data_id=None, user_id=None):
+    def get(self, uuid=None, perimeter_id=None, category_id=None,
+            data_id=None, user_id=None):
         """Retrieve all subject assignments or a specific one for a given policy
 
         :param uuid: uuid of the policy
@@ -50,21 +51,19 @@ class SubjectAssignments(Resource):
         }
         :internal_api: get_subject_assignments
         """
-        # return call(ctx={"id": uuid, "method": "get_subject_assignments", "perimeter_id": perimeter_id, "category_id": category_id, "user_id": user_id},
-        #             args={"data_id": data_id})
         try:
-            # if "perimeter_name" in ctx:
-            #     ctx["perimeter_id"] = self.__get_subject_id(ctx, ctx['perimeter_name'])
-            data = PolicyManager.get_subject_assignments(user_id=user_id, policy_id=uuid,
-                                                         subject_id=perimeter_id, category_id=category_id)
+            data = PolicyManager.get_subject_assignments(
+                user_id=user_id, policy_id=uuid,
+                subject_id=perimeter_id, category_id=category_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"subject_assignments": data}
 
     @check_auth
-    def post(self, uuid=None, perimeter_id=None, category_id=None, data_id=None, user_id=None):
+    def post(self, uuid=None, perimeter_id=None, category_id=None,
+             data_id=None, user_id=None):
         """Create a subject assignment.
 
         :param uuid: uuid of the policy
@@ -91,17 +90,19 @@ class SubjectAssignments(Resource):
             data_id = request.json.get("data_id")
             category_id = request.json.get("category_id")
             perimeter_id = request.json.get("id")
-            data = PolicyManager.add_subject_assignment(user_id=user_id, policy_id=uuid,
-                                                        subject_id=perimeter_id, category_id=category_id,
-                                                        data_id=data_id)
+            data = PolicyManager.add_subject_assignment(
+                user_id=user_id, policy_id=uuid,
+                subject_id=perimeter_id, category_id=category_id,
+                data_id=data_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"subject_assignments": data}
 
     @check_auth
-    def delete(self, uuid=None, perimeter_id=None, category_id=None, data_id=None, user_id=None):
+    def delete(self, uuid=None, perimeter_id=None, category_id=None,
+               data_id=None, user_id=None):
         """Delete a subject assignment for a given policy
 
         :param uuid: uuid of the policy
@@ -116,11 +117,12 @@ class SubjectAssignments(Resource):
         :internal_api: delete_subject_assignment
         """
         try:
-            data = PolicyManager.delete_subject_assignment(user_id=user_id, policy_id=uuid,
-                                                           subject_id=perimeter_id, category_id=category_id,
-                                                           data_id=data_id)
+            data = PolicyManager.delete_subject_assignment(
+                user_id=user_id, policy_id=uuid,
+                subject_id=perimeter_id, category_id=category_id,
+                data_id=data_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
@@ -140,7 +142,8 @@ class ObjectAssignments(Resource):
     )
 
     @check_auth
-    def get(self, uuid=None, perimeter_id=None, category_id=None, data_id=None, user_id=None):
+    def get(self, uuid=None, perimeter_id=None, category_id=None,
+            data_id=None, user_id=None):
         """Retrieve all object assignment or a specific one for a given policy
 
         :param uuid: uuid of the policy
@@ -159,16 +162,18 @@ class ObjectAssignments(Resource):
         :internal_api: get_object_assignments
         """
         try:
-            data = PolicyManager.get_object_assignments(user_id=user_id, policy_id=uuid,
-                                                        object_id=perimeter_id, category_id=category_id)
+            data = PolicyManager.get_object_assignments(
+                user_id=user_id, policy_id=uuid,
+                object_id=perimeter_id, category_id=category_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"object_assignments": data}
 
     @check_auth
-    def post(self, uuid=None, perimeter_id=None, category_id=None, data_id=None, user_id=None):
+    def post(self, uuid=None, perimeter_id=None, category_id=None,
+             data_id=None, user_id=None):
         """Create an object assignment.
 
         :param uuid: uuid of the policy
@@ -195,17 +200,19 @@ class ObjectAssignments(Resource):
             data_id = request.json.get("data_id")
             category_id = request.json.get("category_id")
             perimeter_id = request.json.get("id")
-            data = PolicyManager.add_object_assignment(user_id=user_id, policy_id=uuid,
-                                                       object_id=perimeter_id, category_id=category_id,
-                                                       data_id=data_id)
+            data = PolicyManager.add_object_assignment(
+                user_id=user_id, policy_id=uuid,
+                object_id=perimeter_id, category_id=category_id,
+                data_id=data_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"object_assignments": data}
 
     @check_auth
-    def delete(self, uuid=None, perimeter_id=None, category_id=None, data_id=None, user_id=None):
+    def delete(self, uuid=None, perimeter_id=None, category_id=None,
+               data_id=None, user_id=None):
         """Delete a object assignment for a given policy
 
         :param uuid: uuid of the policy
@@ -220,11 +227,12 @@ class ObjectAssignments(Resource):
         :internal_api: delete_object_assignment
         """
         try:
-            data = PolicyManager.delete_object_assignment(user_id=user_id, policy_id=uuid,
-                                                          object_id=perimeter_id, category_id=category_id,
-                                                          data_id=data_id)
+            data = PolicyManager.delete_object_assignment(
+                user_id=user_id, policy_id=uuid,
+                object_id=perimeter_id, category_id=category_id,
+                data_id=data_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
@@ -244,7 +252,8 @@ class ActionAssignments(Resource):
     )
 
     @check_auth
-    def get(self, uuid=None, perimeter_id=None, category_id=None, data_id=None, user_id=None):
+    def get(self, uuid=None, perimeter_id=None, category_id=None,
+            data_id=None, user_id=None):
         """Retrieve all action assignment or a specific one for a given policy
 
         :param uuid: uuid of the policy
@@ -263,16 +272,18 @@ class ActionAssignments(Resource):
         :internal_api: get_action_assignments
         """
         try:
-            data = PolicyManager.get_action_assignments(user_id=user_id, policy_id=uuid,
-                                                        action_id=perimeter_id, category_id=category_id)
+            data = PolicyManager.get_action_assignments(
+                user_id=user_id, policy_id=uuid,
+                action_id=perimeter_id, category_id=category_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"action_assignments": data}
 
     @check_auth
-    def post(self, uuid=None, perimeter_id=None, category_id=None, data_id=None, user_id=None):
+    def post(self, uuid=None, perimeter_id=None, category_id=None,
+             data_id=None, user_id=None):
         """Create an action assignment.
 
         :param uuid: uuid of the policy
@@ -299,17 +310,19 @@ class ActionAssignments(Resource):
             data_id = request.json.get("data_id")
             category_id = request.json.get("category_id")
             perimeter_id = request.json.get("id")
-            data = PolicyManager.add_action_assignment(user_id=user_id, policy_id=uuid,
-                                                       action_id=perimeter_id, category_id=category_id,
-                                                       data_id=data_id)
+            data = PolicyManager.add_action_assignment(
+                user_id=user_id, policy_id=uuid,
+                action_id=perimeter_id, category_id=category_id,
+                data_id=data_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"action_assignments": data}
 
     @check_auth
-    def delete(self, uuid=None, perimeter_id=None, category_id=None, data_id=None, user_id=None):
+    def delete(self, uuid=None, perimeter_id=None, category_id=None,
+               data_id=None, user_id=None):
         """Delete a action assignment for a given policy
 
         :param uuid: uuid of the policy
@@ -324,11 +337,12 @@ class ActionAssignments(Resource):
         :internal_api: delete_action_assignment
         """
         try:
-            data = PolicyManager.delete_action_assignment(user_id=user_id, policy_id=uuid,
-                                                          action_id=perimeter_id, category_id=category_id,
-                                                          data_id=data_id)
+            data = PolicyManager.delete_action_assignment(
+                user_id=user_id, policy_id=uuid,
+                action_id=perimeter_id, category_id=category_id,
+                data_id=data_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
index 61fe92b..b74ca38 100644 (file)
@@ -9,13 +9,13 @@ Data are elements used to create rules
 
 from flask import request
 from flask_restful import Resource
-from oslo_log import log as logging
+import logging
 from python_moonutilities.security_functions import check_auth
 from python_moondb.core import PolicyManager
 
-__version__ = "0.2.0"
+__version__ = "4.3.2"
 
-LOG = logging.getLogger("moon.manager.api." + __name__)
+logger = logging.getLogger("moon.manager.api." + __name__)
 
 
 class SubjectData(Resource):
@@ -58,7 +58,7 @@ class SubjectData(Resource):
                                                   category_id=category_id,
                                                   data_id=data_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"subject_data": data}
@@ -93,7 +93,7 @@ class SubjectData(Resource):
                                                   category_id=category_id,
                                                   value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"subject_data": data}
@@ -117,7 +117,7 @@ class SubjectData(Resource):
                                                      policy_id=uuid,
                                                      data_id=data_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
@@ -163,7 +163,7 @@ class ObjectData(Resource):
                                                  category_id=category_id,
                                                  data_id=data_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"object_data": data}
@@ -198,7 +198,7 @@ class ObjectData(Resource):
                                                  category_id=category_id,
                                                  value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"object_data": data}
@@ -222,7 +222,7 @@ class ObjectData(Resource):
                                                     policy_id=uuid,
                                                     data_id=data_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
@@ -268,7 +268,7 @@ class ActionData(Resource):
                                                  category_id=category_id,
                                                  data_id=data_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"action_data": data}
@@ -303,7 +303,7 @@ class ActionData(Resource):
                                                  category_id=category_id,
                                                  value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"action_data": data}
@@ -327,7 +327,7 @@ class ActionData(Resource):
                                                     policy_id=uuid,
                                                     data_id=data_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
index f46bfd3..c79520f 100644 (file)
@@ -7,13 +7,13 @@ Those API are helping API used to manage the Moon platform.
 """
 
 from flask_restful import Resource, request
-from oslo_log import log as logging
+import logging
 import moon_manager.api
 from python_moonutilities.security_functions import check_auth
 
-__version__ = "0.1.0"
+__version__ = "4.3.2"
 
-LOG = logging.getLogger("moon.manager.api." + __name__)
+logger = logging.getLogger("moon.manager.api." + __name__)
 
 
 class Status(Resource):
@@ -120,7 +120,8 @@ class API(Resource):
             api_desc[api_name]["description"] = group_api_obj.__doc__
             if "__version__" in dir(group_api_obj):
                 api_desc[api_name]["version"] = group_api_obj.__version__
-            object_list = list(filter(lambda x: "__" not in x, dir(group_api_obj)))
+            object_list = list(filter(lambda x: "__" not in x,
+                                      dir(group_api_obj)))
             for obj in map(lambda x: eval("moon_manager.api.{}.{}".format(api_name, x)), object_list):
                 if "__urls__" in dir(obj):
                     api_desc[api_name][obj.__name__] = dict()
@@ -134,7 +135,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
index 9dc04cc..28aab44 100644 (file)
@@ -9,13 +9,13 @@ Meta Data are elements used to create Meta data (skeleton of security policies)
 
 from flask import request
 from flask_restful import Resource
-from oslo_log import log as logging
+import logging
 from python_moonutilities.security_functions import check_auth
 from python_moondb.core import ModelManager
 
-__version__ = "0.2.0"
+__version__ = "4.3.2"
 
-LOG = logging.getLogger("moon.manager.api." + __name__)
+logger = logging.getLogger("moon.manager.api." + __name__)
 
 
 class SubjectCategories(Resource):
@@ -47,7 +47,7 @@ class SubjectCategories(Resource):
             data = ModelManager.get_subject_categories(
                 user_id=user_id, category_id=category_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"subject_categories": data}
@@ -74,7 +74,7 @@ class SubjectCategories(Resource):
             data = ModelManager.add_subject_category(
                 user_id=user_id, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"subject_categories": data}
@@ -95,7 +95,7 @@ class SubjectCategories(Resource):
             data = ModelManager.delete_subject_category(
                 user_id=user_id, category_id=category_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
@@ -130,7 +130,7 @@ class ObjectCategories(Resource):
             data = ModelManager.get_object_categories(
                 user_id=user_id, category_id=category_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"object_categories": data}
@@ -157,7 +157,7 @@ class ObjectCategories(Resource):
             data = ModelManager.add_object_category(
                 user_id=user_id, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"object_categories": data}
@@ -178,7 +178,7 @@ class ObjectCategories(Resource):
             data = ModelManager.delete_object_category(
                 user_id=user_id, category_id=category_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
@@ -213,7 +213,7 @@ class ActionCategories(Resource):
             data = ModelManager.get_action_categories(
                 user_id=user_id, category_id=category_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"action_categories": data}
@@ -240,7 +240,7 @@ class ActionCategories(Resource):
             data = ModelManager.add_action_category(
                 user_id=user_id, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"action_categories": data}
@@ -261,7 +261,7 @@ class ActionCategories(Resource):
             data = ModelManager.delete_action_category(
                 user_id=user_id, category_id=category_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
index 21552dd..25ae5aa 100644 (file)
@@ -9,13 +9,13 @@ Meta rules are skeleton for security policies
 
 from flask import request
 from flask_restful import Resource
-from oslo_log import log as logging
+import logging
 from python_moonutilities.security_functions import check_auth
 from python_moondb.core import ModelManager
 
-__version__ = "0.1.0"
+__version__ = "4.3.2"
 
-LOG = logging.getLogger("moon.manager.api." + __name__)
+logger = logging.getLogger("moon.manager.api." + __name__)
 
 
 class MetaRules(Resource):
@@ -54,7 +54,7 @@ class MetaRules(Resource):
             data = ModelManager.get_meta_rules(
                 user_id=user_id, meta_rule_id=meta_rule_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"meta_rules": data}
@@ -89,7 +89,7 @@ class MetaRules(Resource):
             data = ModelManager.add_meta_rule(
                 user_id=user_id, meta_rule_id=None, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"meta_rules": data}
@@ -124,7 +124,7 @@ class MetaRules(Resource):
             data = ModelManager.set_meta_rule(
                 user_id=user_id, meta_rule_id=meta_rule_id, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"meta_rules": data}
@@ -159,7 +159,7 @@ class MetaRules(Resource):
             data = ModelManager.delete_meta_rule(
                 user_id=user_id, meta_rule_id=meta_rule_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
index 6286619..07b10d9 100644 (file)
@@ -8,13 +8,13 @@ Models aggregate multiple meta rules
 
 from flask import request
 from flask_restful import Resource
-from oslo_log import log as logging
+import logging
 from python_moonutilities.security_functions import check_auth
 from python_moondb.core import ModelManager
 
-__version__ = "0.1.0"
+__version__ = "4.3.2"
 
-LOG = logging.getLogger("moon.manager.api." + __name__)
+logger = logging.getLogger("moon.manager.api." + __name__)
 
 
 class Models(Resource):
@@ -47,7 +47,7 @@ class Models(Resource):
         try:
             data = ModelManager.get_models(user_id=user_id, model_id=uuid)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"models": data}
@@ -76,7 +76,7 @@ class Models(Resource):
             data = ModelManager.add_model(
                 user_id=user_id, model_id=uuid, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"models": data}
@@ -96,7 +96,7 @@ class Models(Resource):
         try:
             data = ModelManager.delete_model(user_id=user_id, model_id=uuid)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
@@ -120,7 +120,7 @@ class Models(Resource):
             data = ModelManager.update_model(
                 user_id=user_id, model_id=uuid, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"models": data}
index 9183c25..4dc2c31 100644 (file)
@@ -18,9 +18,9 @@ from python_moondb.core import PolicyManager
 from python_moondb.core import ModelManager
 from python_moonutilities import configuration
 
-__version__ = "0.1.0"
+__version__ = "4.3.2"
 
-LOG = logging.getLogger("moon.manager.api." + __name__)
+logger = logging.getLogger("moon.manager.api." + __name__)
 
 
 def delete_pod(uuid):
@@ -30,11 +30,9 @@ def delete_pod(uuid):
 def add_pod(uuid, data):
     if not data.get("keystone_project_id"):
         return
-    LOG.info("Add a new pod {}".format(data))
+    logger.info("Add a new pod {}".format(data))
     if "pdp_id" not in data:
         data["pdp_id"] = uuid
-    data['policies'] = PolicyManager.get_policies(user_id="admin")
-    data['models'] = ModelManager.get_models(user_id="admin")
     conf = configuration.get_configuration("components/orchestrator")
     hostname = conf["components/orchestrator"].get("hostname", "orchestrator")
     port = conf["components/orchestrator"].get("port", 80)
@@ -46,11 +44,11 @@ def add_pod(uuid, data):
                 json=data,
                 headers={"content-type": "application/json"})
         except requests.exceptions.ConnectionError:
-            LOG.warning("Orchestrator is not ready, standby...")
+            logger.warning("Orchestrator is not ready, standby...")
             time.sleep(1)
         else:
             break
-    LOG.info(req.text)
+    logger.info(req.text)
 
 
 class PDP(Resource):
@@ -84,7 +82,7 @@ class PDP(Resource):
         try:
             data = PDPManager.get_pdp(user_id=user_id, pdp_id=uuid)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"pdps": data}
@@ -118,11 +116,11 @@ class PDP(Resource):
             data = PDPManager.add_pdp(
                 user_id=user_id, pdp_id=None, value=request.json)
             uuid = list(data.keys())[0]
-            LOG.info("data={}".format(data))
-            LOG.info("uuid={}".format(uuid))
+            logger.debug("data={}".format(data))
+            logger.debug("uuid={}".format(uuid))
             add_pod(uuid=uuid, data=data[uuid])
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"pdps": data}
@@ -143,7 +141,7 @@ class PDP(Resource):
             data = PDPManager.delete_pdp(user_id=user_id, pdp_id=uuid)
             delete_pod(uuid)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
@@ -170,11 +168,11 @@ class PDP(Resource):
                 _data["keystone_project_id"] = None
             data = PDPManager.update_pdp(
                 user_id=user_id, pdp_id=uuid, value=_data)
-            LOG.info("data={}".format(data))
-            LOG.info("uuid={}".format(uuid))
+            logger.debug("data={}".format(data))
+            logger.debug("uuid={}".format(uuid))
             add_pod(uuid=uuid, data=data[uuid])
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"pdps": data}
index 8196e62..d3948bc 100644 (file)
 
 from flask import request
 from flask_restful import Resource
-from oslo_log import log as logging
+import logging
 from python_moonutilities.security_functions import check_auth
 from python_moondb.core import PolicyManager
 
-__version__ = "0.2.0"
+__version__ = "4.3.2"
 
-LOG = logging.getLogger("moon.manager.api." + __name__)
+logger = logging.getLogger("moon.manager.api." + __name__)
 
 
 class Subjects(Resource):
@@ -59,7 +59,7 @@ class Subjects(Resource):
                 perimeter_id=perimeter_id
             )
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"subjects": data}
@@ -101,7 +101,7 @@ class Subjects(Resource):
                 user_id=user_id, policy_id=uuid,
                 perimeter_id=perimeter_id, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"subjects": data}
@@ -143,7 +143,7 @@ class Subjects(Resource):
                 user_id=user_id, policy_id=uuid,
                 perimeter_id=perimeter_id, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"subjects": data}
@@ -170,7 +170,7 @@ class Subjects(Resource):
             data = PolicyManager.delete_subject(
                 user_id=user_id, policy_id=uuid, perimeter_id=perimeter_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
@@ -213,7 +213,7 @@ class Objects(Resource):
                 perimeter_id=perimeter_id
             )
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"objects": data}
@@ -248,7 +248,7 @@ class Objects(Resource):
                 user_id=user_id, policy_id=uuid,
                 perimeter_id=perimeter_id, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"objects": data}
@@ -283,7 +283,7 @@ class Objects(Resource):
                 user_id=user_id, policy_id=uuid,
                 perimeter_id=perimeter_id, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"objects": data}
@@ -307,7 +307,7 @@ class Objects(Resource):
             data = PolicyManager.delete_object(
                 user_id=user_id, policy_id=uuid, perimeter_id=perimeter_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
@@ -347,7 +347,7 @@ class Actions(Resource):
             data = PolicyManager.get_actions(
                 user_id=user_id, policy_id=uuid, perimeter_id=perimeter_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"actions": data}
@@ -382,7 +382,7 @@ class Actions(Resource):
                 user_id=user_id, policy_id=uuid,
                 perimeter_id=perimeter_id, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"actions": data}
@@ -417,7 +417,7 @@ class Actions(Resource):
                 user_id=user_id, policy_id=uuid,
                 perimeter_id=perimeter_id, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"actions": data}
@@ -441,7 +441,7 @@ class Actions(Resource):
             data = PolicyManager.delete_action(
                 user_id=user_id, policy_id=uuid, perimeter_id=perimeter_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
index f34276b..0d7a52a 100644 (file)
@@ -9,13 +9,13 @@ Policies are instances of security models and implement security policies
 
 from flask import request
 from flask_restful import Resource
-from oslo_log import log as logging
+import logging
 from python_moonutilities.security_functions import check_auth
 from python_moondb.core import PolicyManager
 
-__version__ = "0.1.0"
+__version__ = "4.3.2"
 
-LOG = logging.getLogger("moon.manager.api." + __name__)
+logger = logging.getLogger("moon.manager.api." + __name__)
 
 
 class Policies(Resource):
@@ -49,7 +49,7 @@ class Policies(Resource):
         try:
             data = PolicyManager.get_policies(user_id=user_id, policy_id=uuid)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"policies": data}
@@ -80,7 +80,7 @@ class Policies(Resource):
             data = PolicyManager.add_policy(
                 user_id=user_id, policy_id=uuid, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"policies": data}
@@ -100,7 +100,7 @@ class Policies(Resource):
         try:
             data = PolicyManager.delete_policy(user_id=user_id, policy_id=uuid)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
@@ -125,7 +125,7 @@ class Policies(Resource):
             data = PolicyManager.update_policy(
                 user_id=user_id, policy_id=uuid, value=request.json)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"policies": data}
index b25365d..e6c46bf 100644 (file)
@@ -8,13 +8,13 @@ Rules (TODO)
 
 from flask import request
 from flask_restful import Resource
-from oslo_log import log as logging
+import logging
 from python_moonutilities.security_functions import check_auth
 from python_moondb.core import PolicyManager
 
-__version__ = "0.1.0"
+__version__ = "4.3.2"
 
-LOG = logging.getLogger("moon.manager.api." + __name__)
+logger = logging.getLogger("moon.manager.api." + __name__)
 
 
 class Rules(Resource):
@@ -52,7 +52,7 @@ class Rules(Resource):
                                            policy_id=uuid,
                                            rule_id=rule_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"rules": data}
@@ -114,7 +114,7 @@ class Rules(Resource):
                                           meta_rule_id=args['meta_rule_id'],
                                           value=args)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"rules": data}
@@ -133,7 +133,7 @@ class Rules(Resource):
             data = PolicyManager.delete_rule(
                 user_id=user_id, policy_id=uuid, rule_id=rule_id)
         except Exception as e:
-            LOG.error(e, exc_info=True)
+            logger.error(e, exc_info=True)
             return {"result": False,
                     "error": str(e)}, 500
         return {"result": True}
index 6aa2cd4..d67e112 100644 (file)
@@ -24,7 +24,7 @@ from python_moonutilities import configuration, exceptions
 from python_moondb.core import PDPManager
 
 
-LOG = logging.getLogger("moon.manager.http_server")
+logger = logging.getLogger("moon.manager.http_server")
 
 __API__ = (
     Status, Logs, API,
@@ -88,7 +88,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 = []
@@ -109,7 +110,8 @@ class HTTPServer(Server):
         super(HTTPServer, self).__init__(host=host, port=port, **kwargs)
         self.app = Flask(__name__)
         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)
@@ -143,10 +145,10 @@ class HTTPServer(Server):
             except sqlalchemy.exc.ProgrammingError:
                 time.sleep(1)
                 if first:
-                    LOG.warning("Waiting for the database...")
+                    logger.warning("Waiting for the database...")
                     first = False
             else:
-                LOG.warning("Database is up, resuming operations...")
+                logger.warning("Database is up, resuming operations...")
                 break
 
     def run(self):
index f4c0161..70ddaee 100644 (file)
@@ -3,17 +3,14 @@
 # license which can be found in the file 'LICENSE' in this package distribution
 # or at 'http://www.apache.org/licenses/LICENSE-2.0'.
 
-from oslo_config import cfg
-from oslo_log import log as logging
+import logging
 from python_moonutilities import configuration, exceptions
 from moon_manager.http_server import HTTPServer
 
-LOG = logging.getLogger("moon.manager.server")
-CONF = cfg.CONF
-DOMAIN = "moon_manager"
+logger = logging.getLogger("moon.manager.server")
 
 
-def main():
+def create_server():
     configuration.init_logging()
     try:
         conf = configuration.get_configuration("components/manager")
@@ -24,11 +21,19 @@ def main():
         hostname = "manager"
         bind = "127.0.0.1"
         port = 80
-        configuration.add_component(uuid="manager", name=hostname, port=port, bind=bind)
-    LOG.info("Starting server with IP {} on port {} bind to {}".format(hostname, port, bind))
+        configuration.add_component(uuid="manager",
+                                    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()
index bd8a70f..35c944c 100644 (file)
@@ -40,7 +40,7 @@ setup(
 
     entry_points={
         'console_scripts': [
-            'moon_manager = moon_manager.server:main',
+            'moon_manager = moon_manager.server:create_server',
         ],
     }
 
index 1c055da..a2b0689 100644 (file)
@@ -7,6 +7,6 @@ def get_json(data):
 
 def register_client():
     import moon_manager.server
-    server = moon_manager.server.main()
+    server = moon_manager.server.create_server()
     client = server.app.test_client()
     return client
\ No newline at end of file