return response
def run(self):
- logger.info("self.context.pdp_set={}".format(self.context.pdp_set))
+ logger.debug("self.context.pdp_set={}".format(self.context.pdp_set))
result, message = self.__check_rules()
if result:
return self.__exec_instructions(result)
import os
import logging
from moon_authz.http_server import HTTPServer as Server
-from python_moonutilities import configuration
+from python_moonutilities import configuration, exceptions
logger = logging.getLogger("moon.authz.server")
meta_rule_id = os.getenv("META_RULE_ID")
keystone_project_id = os.getenv("KEYSTONE_PROJECT_ID")
logger.info("component_type={}".format(component_type))
- conf = configuration.get_configuration("plugins/{}".format(component_type))
- conf["plugins/{}".format(component_type)]['id'] = component_id
- hostname = conf["plugins/{}".format(component_type)].get('hostname',
- component_id)
- port = conf["plugins/{}".format(component_type)].get('port', tcp_port)
- bind = conf["plugins/{}".format(component_type)].get('bind', "0.0.0.0")
+ conf = configuration.get_plugins()
+ # conf = configuration.get_configuration("plugins/{}".format(component_type))
+ # conf["plugins/{}".format(component_type)]['id'] = component_id
+ if component_type not in conf:
+ raise exceptions.ConsulComponentNotFound("{} not found".format(
+ component_type))
+ hostname = conf[component_type].get('hostname', component_id)
+ port = conf[component_type].get('port', tcp_port)
+ bind = conf[component_type].get('bind', "0.0.0.0")
logger.info("Starting server with IP {} on port {} bind to {}".format(
hostname, port, bind))
def create_server():
configuration.init_logging()
try:
- conf = configuration.get_configuration("components/interface")
- hostname = conf["components/interface"].get("hostname", "interface")
- port = conf["components/interface"].get("port", 80)
- bind = conf["components/interface"].get("bind", "127.0.0.1")
+ conf = configuration.get_configuration("components/pipeline").get(
+ "components/pipeline", {}).get("interface", {})
+ hostname = conf.get("hostname", "pipeline")
+ port = conf.get("port", 80)
+ bind = conf.get("bind", "127.0.0.1")
except exceptions.ConsulComponentNotFound:
hostname = "interface"
bind = "127.0.0.1"
port = 80
- configuration.add_component(uuid="interface",
+ configuration.add_component(uuid="pipeline",
name=hostname,
port=port,
bind=bind)
logger.debug("_config={}".format(_config))
api_client = client.CoreV1Api(_config)
ext_client = client.ExtensionsV1beta1Api(_config)
- # TODO: get data from consul
data = [{
"name": hostname + "-" + get_random_name(),
"container": container,
return
plugins = configuration.get_plugins()
- conf = configuration.get_configuration("components/interface")
- i_hostname = conf["components/interface"].get("hostname", "interface")
- i_port = conf["components/interface"].get("port", 80)
- i_container = conf["components/interface"].get(
+ conf = configuration.get_configuration("components/pipeline")
+ # i_hostname = conf["components/pipeline"].get("interface").get("hostname", "interface")
+ i_port = conf["components/pipeline"].get("interface").get("port", 80)
+ i_container = conf["components/pipeline"].get("interface").get(
"container",
"wukongsun/moon_interface:v4.3")
data = [
{
- "name": i_hostname + "-" + get_random_name(),
+ "name": "pipeline-" + get_random_name(),
"container": i_container,
"port": i_port,
'pdp_id': pdp_id,
"slave",
"components/manager",
"components/orchestrator",
- "components/interface",
+ "components/pipeline",
"components/wrapper",
)
"""
from flask_restful import Resource, request
-from oslo_log import log as logging
+import logging
import moon_wrapper.api
from python_moonutilities.security_functions import check_auth
__version__ = "0.1.0"
-LOG = logging.getLogger("moon.manager.api." + __name__)
+logger = logging.getLogger("moon.manager.api." + __name__)
class Status(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
__version__ = "0.1.0"
-LOG = logging.getLogger("moon.wrapper.api." + __name__)
+logger = logging.getLogger("moon.wrapper.api." + __name__)
class OsloWrapper(Resource):
self.TIMEOUT = 5
def post(self):
- LOG.debug("POST {}".format(request.form))
+ logger.debug("POST {}".format(request.form))
response = flask.make_response("False")
if self.manage_data():
response = flask.make_response("True")
@staticmethod
def __get_project_id(target, credentials):
- LOG.info("__get_project_id {}".format(target))
+ logger.info("__get_project_id {}".format(target))
return target.get("project_id", "none")
def get_interface_url(self, project_id):
- LOG.info("project_id {}".format(project_id))
+ logger.debug("project_id {}".format(project_id))
for containers in self.CACHE.containers.values():
- LOG.info("containers {}".format(containers))
+ logger.info("containers {}".format(containers))
for container in containers:
if container.get("keystone_project_id") == project_id:
- if "interface" in container['name']:
+ if "pipeline" in container['name']:
return "http://{}:{}".format(
container['name'],
container['port'])
for containers in self.CACHE.containers.values():
for container in containers:
if container.get("keystone_project_id") == project_id:
- if "interface" in container['name']:
+ if "pipeline" in container['name']:
return "http://{}:{}".format(
container['name'],
container['port'])
_object = self.__get_object(target, credentials)
_action = rule
_project_id = self.__get_project_id(target, credentials)
- LOG.debug("POST with args project={} / "
+ logger.debug("POST with args project={} / "
"subject={} - object={} - action={}".format(
_project_id, _subject, _object, rule))
interface_url = self.get_interface_url(_project_id)
- LOG.debug("interface_url={}".format(interface_url))
+ logger.debug("interface_url={}".format(interface_url))
req = requests.get("{}/authz/{}/{}/{}/{}".format(
interface_url,
_project_id,
_object,
_action
))
- LOG.debug("Get interface {}".format(req.text))
+ logger.debug("Get interface {}".format(req.text))
if req.status_code == 200:
if req.json().get("result", False):
return True
config = get_configuration("logging")
logging.config.dictConfig(config['logging'])
+
def increment_port():
components_object = get_configuration("components/port_start")
- if 'port_start' in components_object:
- components_port_start = int(get_configuration("components/port_start")['port_start'])
+ if 'components/port_start' in components_object:
+ components_port_start = int(components_object['components/port_start'])
components_port_start += 1
else:
raise exceptions.ConsulComponentContentError("error={}".format(components_object))
raise exceptions.ConsulError
return components_port_start
+
def get_configuration(key):
url = "http://{}:{}/v1/kv/{}".format(CONSUL_HOST, CONSUL_PORT, key)
req = requests.get(url)
} for item in data
]
+
def add_component(name, uuid, port=None, bind="127.0.0.1", keystone_id="", extra=None, container=None):
data = {
"hostname": name,
logger.debug("data={}".format(data))
raise exceptions.ConsulError
logger.info("Add component {}".format(req.text))
- return configuration.get_configuration("components/"+uuid)
+ return get_configuration("components/"+uuid)
+
def get_plugins():
- url = "http://{}:{}/v1/kv/plugins?recurse=true".format(CONSUL_HOST, CONSUL_PORT)
- req = requests.get(url)
- if req.status_code != 200:
- logger.info("url={}".format(url))
- raise exceptions.ConsulError
- data = req.json()
- if len(data) == 1:
- data = data[0]
- if all(k in data for k in ("Key", "Value")):
- return {data["Key"].replace("plugins/", ""): json.loads(base64.b64decode(data["Value"]).decode("utf-8"))}
- raise exceptions.ConsulComponentContentError("error={}".format(data))
- else:
- for item in data:
- if not all(k in item for k in ("Key", "Value")):
- logger.warning("invalidate content {}".format(item))
- raise exceptions.ConsulComponentContentError("error={}".format(data))
- return {
- item["Key"].replace("plugins/", ""): json.loads(base64.b64decode(item["Value"]).decode("utf-8"))
- for item in data
- }
+ pipeline = get_configuration("components/pipeline")
+ logger.debug("pipeline={}".format(pipeline))
+ components = pipeline.get("components/pipeline")
+ components.pop('interface')
+ return components
+
def get_components():
url = "http://{}:{}/v1/kv/components?recurse=true".format(CONSUL_HOST, CONSUL_PORT)
# 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_log import log as logging
+import logging
from werkzeug.exceptions import HTTPException
logger = logging.getLogger("moon.utilities.exceptions")
kubectl delete -n moon -f tools/moon_kubernetes/templates/moon_orchestrator.yaml
for i in $(kubectl get deployments -n moon | grep wrapper | cut -d " " -f 1 | xargs); do
+ echo deleting $i
kubectl delete deployments/$i -n moon;
done
-for i in $(kubectl get deployments -n moon | grep interface | cut -d " " -f 1 | xargs); do
- kubectl delete deployments/$i -n moon;
-done
-for i in $(kubectl get deployments -n moon | grep authz | cut -d " " -f 1 | xargs); do
+for i in $(kubectl get deployments -n moon | grep pipeline | cut -d " " -f 1 | xargs); do
+ echo deleting $i
kubectl delete deployments/$i -n moon;
done
for i in $(kubectl get services -n moon | grep wrapper | cut -d " " -f 1 | xargs); do
+ echo deleting $i
kubectl delete services/$i -n moon;
done
-for i in $(kubectl get services -n moon | grep interface | cut -d " " -f 1 | xargs); do
- kubectl delete services/$i -n moon;
-done
-for i in $(kubectl get services -n moon | grep authz | cut -d " " -f 1 | xargs); do
+for i in $(kubectl get services -n moon | grep pipeline | cut -d " " -f 1 | xargs); do
+ echo deleting $i
kubectl delete services/$i -n moon;
done