def initialize(self, debug=False, subcommand='run'): self.log.setLevel(debug) self.get_settings_from_ini() self.settings['DOMAIN'] = register_models() self.settings['RESOURCE_METHODS'] = ['GET', 'POST', 'DELETE'] self.settings['ITEM_METHODS'] = ['GET', 'PATCH', 'PUT', 'DELETE'] self.settings['XML'] = False self.settings['X_DOMAINS'] = '*' self.settings['X_HEADERS'] = ( 'Authorization, If-Match,' ' X-HTTP-Method-Override, Content-Type' ) self.settings['PAGINATION_LIMIT'] = 200 self.settings['MONGO_HOST'] = 'localhost' self.settings['MONGO_PORT'] = 27017 # self.settings['MONGO_USERNAME'] = '******' # self.settings['MONGO_PASSWORD'] = '******' self.settings['MONGO_DBNAME'] = 'alignak-backend' self.app = Eve( settings=self.settings ) Bootstrap(self.app) self.app.register_blueprint(eve_docs, url_prefix='/docs') self.log.debug(pformat(self.app.settings)) self.app.debug = debug
def test_schema_version_uptodate(self): """ Test the `schema_version` default value has the same value than the highest schema_version attribute value in fields of the model :return: """ allmodels = register_models() for model_name in allmodels: print("Model: %s" % model_name) highest = 0 for field in allmodels[model_name]['schema']: print("- existing field: %s" % field) if field != 'schema_version': if allmodels[model_name]['schema'][field][ 'schema_version'] > highest: highest = allmodels[model_name]['schema'][field][ 'schema_version'] for field in allmodels[model_name]['schema_deleted']: print("- deleted field: %s" % field) if field != 'schema_version': if allmodels[model_name]['schema_deleted'][field][ 'schema_version'] > highest: highest = allmodels[model_name]['schema_deleted'][ field]['schema_version'] assert highest == allmodels[model_name]['schema'][ 'schema_version']['default']
def test_schema_version(self): """ Test each fields on all models have a schema_version field :return: None """ allmodels = register_models() for model_name in allmodels: print("Model: %s" % model_name) for field in allmodels[model_name]['schema']: print("- existing field: %s" % field) if field == 'schema_version': assert 'schema_version' not in allmodels[model_name][ 'schema'][field] else: assert 'schema_version' in allmodels[model_name]['schema'][ field] for field in allmodels[model_name]['schema_deleted']: print("- deleted field: %s" % field) if field == 'schema_version': assert 'schema_version' not in allmodels[model_name][ 'schema_deleted'][field] else: assert 'schema_version' in allmodels[model_name][ 'schema_deleted'][field]
# Default is ['$where', '$regex'] settings['MONGO_QUERY_BLACKLIST'] = ['$where'] # Flask specific options; default is to listen only on locahost ... settings['HOST'] = '127.0.0.1' settings['PORT'] = 5000 settings['SERVER_NAME'] = None settings['DEBUG'] = False # Read configuration file to update/completethe configuration get_settings(settings) print "Application settings: %s" % settings # Add model schema to the configuration settings['DOMAIN'] = register_models() app = Eve( settings=settings, validator=MyValidator, auth=MyTokenAuth ) # hooks app.on_pre_GET += pre_get app.on_insert_contact += pre_contact_post app.on_update_contact += pre_contact_patch # docs api Bootstrap(app) app.register_blueprint(eve_docs, url_prefix='/docs')
from alignak_backend.models import register_models from graphviz import Digraph dot = Digraph(format='png') # dot.node_attr.update(color='lightblue2', style='filled') # dot.graph_attr.update(nodesep='0.1') dot.graph_attr.update(size="140,140") # dot.edge_attr.update(weight='2.1') models = register_models() for name, schema in models.items(): color = '' if name == 'host': color = 'red' elif name == 'service': color = 'green' dot.node(name, color=color) for key, value in schema['schema'].items(): style = 'dashed' if 'required' in value and value['required']: style = 'solid' if not key.startswith("_"): if value['type'] == 'objectid': dot.edge(name, value['data_relation']['resource'], color=color, label=key, fontcolor=color, style=style) elif value['type'] == 'list' and 'schema' in value: if value['schema']['type'] == 'objectid': dot.edge(name, value['schema']['data_relation']['resource'], color=color, label=key, fontcolor=color, style=style) dot.render('model_schema', view=False)
from alignak_backend.models import register_models from graphviz import Digraph dot = Digraph(format='png',) #dot.node_attr.update(color='lightblue2', style='filled') #dot.graph_attr.update(nodesep='0.1') dot.graph_attr.update(size="140,140") #dot.edge_attr.update(weight='2.1') models = register_models() for name, schema in models.iteritems(): color = '' if name == 'host': color = 'red' elif name == 'service': color = 'green' dot.node(name, color=color) for key, value in schema['schema'].iteritems(): style = 'dashed' if 'required' in value and value['required']: style = 'solid' if not key.startswith("_"): if value['type'] == 'objectid': dot.edge(name, value['data_relation']['resource'], color=color, label=key, fontcolor=color, style=style) elif value['type'] == 'list' and 'schema' in value: if value['schema']['type'] == 'objectid': dot.edge(name, value['schema']['data_relation']['resource'], color=color, label=key, fontcolor=color, style=style) dot.render('model_schema', view=False)
if settings['SCHEDULER_GRAFANA_ACTIVE'] and settings[ 'GRAFANA_HOST'] is not None: jobs.append({ 'id': 'cron_grafana', 'func': 'alignak_backend.scheduler:cron_grafana', 'args': (), 'trigger': 'interval', 'seconds': 120 }) if len(jobs) > 0: settings['JOBS'] = jobs print("Application settings: %s" % settings) # Add model schema to the configuration settings['DOMAIN'] = register_models() base_path = os.path.dirname(os.path.abspath(alignak_backend.__file__)) app = Eve(settings=settings, validator=MyValidator, auth=MyTokenAuth, static_folder=base_path) # hooks pre-init app.on_pre_GET += pre_get app.on_insert_user += pre_user_post app.on_update_user += pre_user_patch app.on_update_host += pre_host_service_patch app.on_update_service += pre_host_service_patch app.on_delete_item_realm += pre_delete_realm app.on_deleted_item_realm += after_delete_realm