aboutsummaryrefslogtreecommitdiffstats
path: root/app/api/app.py
diff options
context:
space:
mode:
authorYaron Yogev <yaronyogev@gmail.com>2017-07-27 09:02:54 +0300
committerYaron Yogev <yaronyogev@gmail.com>2017-07-27 14:56:25 +0300
commit7e83d0876ddb84a45e130eeba28bc40ef53c074b (patch)
tree47d76239ae7658d87c66abd142df92709427e7dd /app/api/app.py
parent378ecbd8947589b9cbb39013a0c2e2aa201e03bd (diff)
Calipso initial release for OPNFV
Change-Id: I7210c244b0c10fa80bfa8c77cb86c9d6ddf8bc88 Signed-off-by: Yaron Yogev <yaronyogev@gmail.com>
Diffstat (limited to 'app/api/app.py')
-rw-r--r--app/api/app.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/app/api/app.py b/app/api/app.py
new file mode 100644
index 0000000..5fa3da9
--- /dev/null
+++ b/app/api/app.py
@@ -0,0 +1,71 @@
+###############################################################################
+# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
+# and others #
+# #
+# All rights reserved. This program and the accompanying materials #
+# are made available under the terms of the Apache License, Version 2.0 #
+# which accompanies this distribution, and is available at #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+###############################################################################
+import importlib
+
+import falcon
+
+from api.auth.token import Token
+from api.backends.ldap_access import LDAPAccess
+from api.exceptions.exceptions import CalipsoApiException
+from api.middleware.authentication import AuthenticationMiddleware
+from utils.inventory_mgr import InventoryMgr
+from utils.logging.full_logger import FullLogger
+from utils.mongo_access import MongoAccess
+
+
+class App:
+
+ ROUTE_DECLARATIONS = {
+ "/inventory": "resource.inventory.Inventory",
+ "/links": "resource.links.Links",
+ "/messages": "resource.messages.Messages",
+ "/cliques": "resource.cliques.Cliques",
+ "/clique_types": "resource.clique_types.CliqueTypes",
+ "/clique_constraints": "resource.clique_constraints.CliqueConstraints",
+ "/scans": "resource.scans.Scans",
+ "/scheduled_scans": "resource.scheduled_scans.ScheduledScans",
+ "/constants": "resource.constants.Constants",
+ "/monitoring_config_templates":
+ "resource.monitoring_config_templates.MonitoringConfigTemplates",
+ "/aggregates": "resource.aggregates.Aggregates",
+ "/environment_configs":
+ "resource.environment_configs.EnvironmentConfigs",
+ "/auth/tokens": "auth.tokens.Tokens"
+ }
+
+ responders_path = "api.responders"
+
+ def __init__(self, mongo_config="", ldap_config="",
+ log_level="", inventory="", token_lifetime=86400):
+ MongoAccess.set_config_file(mongo_config)
+ self.inv = InventoryMgr()
+ self.inv.set_collections(inventory)
+ self.log = FullLogger()
+ self.log.set_loglevel(log_level)
+ self.ldap_access = LDAPAccess(ldap_config)
+ Token.set_token_lifetime(token_lifetime)
+ self.middleware = AuthenticationMiddleware()
+ self.app = falcon.API(middleware=[self.middleware])
+ self.app.add_error_handler(CalipsoApiException)
+ self.set_routes(self.app)
+
+ def get_app(self):
+ return self.app
+
+ def set_routes(self, app):
+ for url in self.ROUTE_DECLARATIONS.keys():
+ class_path = self.ROUTE_DECLARATIONS.get(url)
+ module = self.responders_path + "." + \
+ class_path[:class_path.rindex(".")]
+ class_name = class_path.split('.')[-1]
+ module = importlib.import_module(module)
+ class_ = getattr(module, class_name)
+ resource = class_()
+ app.add_route(url, resource)