""" This file loads the configuration used for the dashboard manager. The config is stored in a JSON format on the filesystem, with the following schema: .. asjson:: brian_dashboard_manager.config.CONFIG_SCHEMA Some config specific to each organization is hardcoded. This includes which organizations to provision, and which dashboards not to provision for each organization: `excluded_nrens` is a list of strings to search for in interface descriptions to exclude for that organization. `excluded_dashboards` is a list of dashboard names to exclude. These only cover the static dashboards loaded from the file system. `excluded_folders` covers dynamically generated folders and dashboards. This property is a mapping of folder name to `True` or a list of dashboards. A value of `True` should result in that folder being excluded. If the value is a list, dashboard titles within the list should be excluded. .. asjson:: brian_dashboard_manager.config.DEFAULT_ORGANIZATIONS """ import json import jsonschema import tempfile STATE_PATH = tempfile.gettempdir() + '/briandashboardmanager-state.json' DEFAULT_ORGANIZATIONS = [ { "name": "GÉANT Staff", "excluded_nrens": [ "GEANT", "Microsoft" ], "excluded_dashboards": [], "excluded_folders": {} }, { "name": "NRENs", "excluded_nrens": [ "GEANT", "CUSTOMER GEANT", "GEANT-IT", "Microsoft" ], "excluded_dashboards": [ "GÉANT Office devices", "GÉANT VM", "Lab Devices", "EUMETSAT" ], "excluded_folders": { "Aggregates": ["CAE1"], "EUMETSAT Multicast": True, } }, { "name": "General Public", "excluded_nrens": [ "GEANT", "CARNET", "PSNC", "PIONIER", "CUSTOMER GEANT", "GEANT-IT", "Microsoft" ], "excluded_dashboards": [ "GÉANT Office devices", "GÉANT VM", "Lab Devices", "IAS", "IAS Peers", "EUMETSAT" ], "excluded_folders": { "Aggregates": ["CAE1", "GWS UPSTREAMS", "IAS PEERS"], "IAS CUSTOMER": True, "IAS PRIVATE": True, "IAS PUBLIC": True, "IAS UPSTREAM": True, "GWS PHY Upstream": True, "GWS Direct": True, "GWS Indirect": True, "EUMETSAT Multicast": True, "NREN Access BETA": True } }, { "name": "CAE1 - Europe", "excluded_nrens": [ "GEANT", "CUSTOMER GEANT", "GEANT-IT", "PSNC", "PIONIER", "Microsoft" ], "excluded_dashboards": [ "GÉANT Office devices", "GÉANT VM", "Lab Devices", "EUMETSAT" ], "excluded_folders": { "EUMETSAT Multicast": True } }, { "name": "CAE1 - Asia", "excluded_nrens": [ "GEANT", "CARNET", "PSNC", "PIONIER", "CUSTOMER GEANT", "GEANT-IT", "Microsoft" ], "excluded_dashboards": [ "GÉANT Office devices", "GÉANT VM", "Lab Devices", "IAS", "IAS Peers", "EUMETSAT" ], "excluded_folders": { "Aggregates": ["GWS UPSTREAMS", "IAS PEERS"], "IAS CUSTOMER": True, "IAS PRIVATE": True, "IAS PUBLIC": True, "IAS UPSTREAM": True, "GWS PHY Upstream": True, "EUMETSAT Multicast": True, "NREN Access BETA": True } } ] CONFIG_SCHEMA = { "$schema": "https://json-schema.org/draft-07/schema#", "definitions": { "influx-datasource": { "type": "object", "properties": { "name": {"type": "string"}, "username": {"type": "string"}, "password": {"type": "string"}, "type": {"type": "string"}, "url": {"type": "string"}, "database": {"type": "string"}, "basicAuth": {"type": "boolean"}, "access": {"type": "string"}, "isDefault": {"type": "boolean"}, "readOnly": {"type": "boolean"} }, "required": [ "name", "type", "url", "database", "basicAuth", "access", "isDefault", "readOnly" ] }, "organization": { "type": "object", "properties": { "name": {"type": "string"}, "excluded_nrens": { "type": "array", "items": {"type": "string"} }, }, "required": [ "name", "excluded_nrens", ] } }, "type": "object", "properties": { "admin_username": {"type": "string"}, "admin_password": {"type": "string"}, "hostname": {"type": "string"}, "listen_port": {"type": "integer"}, "inventory_provider": {"type": "string"}, "reporting_provider": {"type": "string"}, "datasources": { "type": "object", "properties": { "influxdb": {"$ref": "#/definitions/influx-datasource"} }, "additionalProperties": False }, "ignored_folders": { "type": "array", "items": {"type": "string"} } }, "required": [ "admin_username", "admin_password", "hostname", "inventory_provider", "reporting_provider", "datasources", "ignored_folders" ] } def defaults(): return { "admin_username": "admin", "admin_password": "admin", "hostname": "localhost:3000", "listen_port": 3001, "datasources": {}, "ignored_folders": [] } def load(f): """ loads, validates and returns configuration parameters :param f: file-like object that produces the config file :return: """ config = json.loads(f.read()) jsonschema.validate(config, CONFIG_SCHEMA) return config