# 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"
-from moon_manager.server import main
+from moon_manager.server import create_server
-server = main()
+server = create_server()
server.run()
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):
)
@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
}
: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
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
: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}
)
@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
: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
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
: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}
)
@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
: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
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
: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}
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):
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}
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}
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}
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}
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}
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}
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}
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}
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}
"""
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):
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()
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
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):
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}
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}
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}
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}
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}
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}
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}
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}
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}
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):
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}
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}
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}
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}
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):
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}
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}
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}
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}
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):
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)
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):
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}
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}
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}
_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}
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):
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}
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}
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}
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}
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}
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}
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}
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}
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}
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}
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}
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}
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):
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}
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}
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}
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}
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):
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}
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}
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}
from python_moondb.core import PDPManager
-LOG = logging.getLogger("moon.manager.http_server")
+logger = logging.getLogger("moon.manager.http_server")
__API__ = (
Status, Logs, API,
__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 = []
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)
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):
# 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")
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()
entry_points={
'console_scripts': [
- 'moon_manager = moon_manager.server:main',
+ 'moon_manager = moon_manager.server:create_server',
],
}
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