def main(): medallion_parser = _get_argparser() medallion_args = medallion_parser.parse_args() # Configuration checking sets up debug logging and does not run the app if medallion_args.conf_check: medallion_args.log_level = logging.DEBUG log.setLevel(medallion_args.log_level) configuration = medallion.config.load_config( medallion_args.CONFIG_PATH or medallion_args.conf_file, medallion_args.conf_dir if not medallion_args.no_conf_dir else None, ) set_config(APPLICATION_INSTANCE, "users", configuration) set_config(APPLICATION_INSTANCE, "taxii", configuration) set_config(APPLICATION_INSTANCE, "backend", configuration) APPLICATION_INSTANCE.medallion_backend = connect_to_backend( get_application_instance_config_values(APPLICATION_INSTANCE, "backend")) if (not APPLICATION_INSTANCE.blueprints): register_blueprints(APPLICATION_INSTANCE) if not medallion_args.conf_check: APPLICATION_INSTANCE.run( host=medallion_args.host, port=medallion_args.port, debug=medallion_args.debug_mode, )
def setUp(self): self.app = application_instance self.app_context = application_instance.app_context() self.app_context.push() self.app.testing = True register_blueprints(self.app) self.configuration = { "backend": { "module": "medallion.backends.mongodb_backend", "module_class": "MongoBackend", "uri": "mongodb://localhost:27017/", "default_page_size": 20 }, "users": { "admin": "Password0" }, "taxii": { "max_page_size": 20 } } self.client = application_instance.test_client() set_users_config(self.app, self.configuration["users"]) set_taxii_config(self.app, self.configuration["taxii"]) encoded_auth = 'Basic ' + base64.b64encode(b"admin:Password0").decode( "ascii") self.auth = {'Authorization': encoded_auth}
def setUp(self): self.app = application_instance self.app_context = application_instance.app_context() self.app_context.push() self.app.testing = True register_blueprints(self.app) if self.type == "mongo": reset_db(self.mongodb_config["backend"]["uri"]) self.configuration = self.mongodb_config elif self.type == "memory": self.configuration = self.memory_config elif self.type == "memory_no_config": self.configuration = self.no_config elif self.type == "no_taxii": self.configuration = self.config_no_taxii elif self.type == "no_auth": self.configuration = self.config_no_auth elif self.type == "no_backend": self.configuration = self.config_no_backend else: raise RuntimeError("Unknown backend!") set_config(self.app, "backend", self.configuration) set_config(self.app, "users", self.configuration) set_config(self.app, "taxii", self.configuration) self.client = application_instance.test_client() if self.type == "memory_no_config" or self.type == "no_auth": encoded_auth = "Basic " + \ base64.b64encode(b"user:pass").decode("ascii") else: encoded_auth = "Basic " + \ base64.b64encode(b"admin:Password0").decode("ascii") self.auth = {"Authorization": encoded_auth}
def setUp(self, start_threads=True): self.__name__ = self.type self.app = APPLICATION_INSTANCE self.app_context = APPLICATION_INSTANCE.app_context() self.app_context.push() self.app.testing = True if not self.app.blueprints: register_blueprints(self.app) if self.type == "mongo": self.configuration = self.mongodb_config elif self.type == "memory": self.configuration = self.memory_config elif self.type == "memory_no_config": self.configuration = self.no_config elif self.type == "no_taxii": self.configuration = self.config_no_taxii elif self.type == "no_auth": self.configuration = self.config_no_auth elif self.type == "no_backend": self.configuration = self.config_no_backend else: raise RuntimeError("Unknown backend!") set_config(self.app, "backend", self.configuration) set_config(self.app, "users", self.configuration) set_config(self.app, "taxii", self.configuration) if not start_threads: self.app.backend_config["run_cleanup_threads"] = False APPLICATION_INSTANCE.medallion_backend = connect_to_backend( get_application_instance_config_values(APPLICATION_INSTANCE, "backend"), clear_db=True) self.client = APPLICATION_INSTANCE.test_client() if self.type == "memory_no_config" or self.type == "no_auth": encoded_auth = "Basic " + \ base64.b64encode(b"user:pass").decode("ascii") elif self.type == "mongo": encoded_auth = "Basic " + \ base64.b64encode(b"root:example").decode("ascii") else: encoded_auth = "Basic " + \ base64.b64encode(b"admin:Password0").decode("ascii") self.headers = { "Accept": "application/taxii+json;version=2.1", "Authorization": encoded_auth } self.post_headers = { "Content-Type": "application/taxii+json;version=2.1", "Accept": "application/taxii+json;version=2.1", "Authorization": encoded_auth }
def main(): medallion_parser = _get_argparser() medallion_args = medallion_parser.parse_args() log.setLevel(medallion_args.log_level) with open(medallion_args.CONFIG_PATH, "r") as f: configuration = json.load(f) set_config(application_instance, configuration["users"]) init_backend(application_instance, configuration["backend"]) register_blueprints(application_instance) application_instance.run( host=medallion_args.host, port=medallion_args.port, debug=medallion_args.debug_mode )
def setUp(self): self.app = application_instance self.app_context = application_instance.app_context() self.app_context.push() self.app.testing = True register_blueprints(self.app) if self.type == "mongo": reset_db() self.configuration = self.mongodb_config else: self.memory_config['backend']['filename'] = self.DATA_FILE self.configuration = self.memory_config init_backend(self.app, self.configuration["backend"]) set_users_config(self.app, self.configuration["users"]) set_taxii_config(self.app, self.configuration["taxii"]) self.client = application_instance.test_client() encoded_auth = 'Basic ' + \ base64.b64encode(b"admin:Password0").decode("ascii") self.auth = {'Authorization': encoded_auth}
def setUp(self): self.app = application_instance self.app_context = application_instance.app_context() self.app_context.push() self.app.testing = True register_blueprints(self.app) self.configuration = { "backend": { "module": "medallion.backends.memory_backend", "module_class": "MemoryBackend", "filename": DATA_FILE }, "users": { "admin": "Password0" } } init_backend(self.app, self.configuration["backend"]) set_config(self.app, self.configuration["users"]) self.client = application_instance.test_client() encoded_auth = 'Basic ' + base64.b64encode(b"admin:Password0").decode("ascii") self.auth = {'Authorization': encoded_auth}
def main(): if len(sys.argv) < 2: raise ValueError("No config file specified") config_file_path = sys.argv[1] if os.path.isfile(config_file_path) and os.path.getsize(config_file_path) > 0: with open(config_file_path, 'r') as f: config = None try: config = json.load(f) except ValueError: raise ValueError("File {0} contains invalid JSON".format(config_file_path)) init(config) else: raise ValueError("File {0} is empty or not present".format(config_file_path)) application_instance = Flask(__name__) register_blueprints(application_instance) application_instance.run(debug=True)