def test_secrets(self, tmpdir): expected_secret = secure_config.secrets.EncryptedSecret("v3rys3cur3", "correct_db_password") print(expected_secret) test_config = os.path.join(self.module_path, 'application_secure.cfg') secret_file = os.path.join(self.module_path, 'secret_file.json') config_undecrypted = cf.get_config(test_config) assert config_undecrypted['metadb']["db_password"] == expected_secret.dumps() config_decrypted = cf.get_config(test_config, secrets_file=secret_file) assert config_decrypted['metadb']["db_password"].decrypt() == "correct_db_password"
def test_secrets(self, tmpdir): expected_secret = secure_config.secrets.EncryptedSecret( "v3rys3cur3", "correct_db_password") print(expected_secret) test_config = os.path.join(self.module_path, 'application_secure.cfg') secret_file = os.path.join(self.module_path, 'secret_file.json') config_undecrypted = cf.get_config(test_config) assert config_undecrypted['metadb'][ "db_password"] == expected_secret.dumps() config_decrypted = cf.get_config(test_config, secrets_file=secret_file) assert config_decrypted['metadb']["db_password"].decrypt( ) == "correct_db_password"
def parametrized_setup(request, tmpdir): from postgraas_server.management_resources import db cfg = tmpdir.join('config') with open(cfg.strpath, "w") as fp: json.dump(CONFIGS[request.param], fp) config = configuration.get_config(cfg.strpath) this_app = create_app(config) this_app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://" this_app.use_reloader = False this_app.config['TESTING'] = True ctx = this_app.app_context() ctx.push() db.create_all() username, db_name = str(uuid.uuid4()).replace('-', '_'), str(uuid.uuid4()).replace('-', '_') request.cls.app_client = this_app.test_client() request.cls.db_name = remove_digits(db_name) request.cls.username = remove_digits(username) request.cls.backend = request.param yield if request.param == 'docker': delete_all_test_postgraas_container() elif request.param == 'pg_cluster': try: delete_test_database_and_user(db_name, username, dict(config.items('backend'))) except Exception: pass db.drop_all() ctx.pop()
def parametrized_setup(request, tmpdir): from postgraas_server.management_resources import db cfg = tmpdir.join('config') with open(cfg.strpath, "w") as fp: json.dump(CONFIGS[request.param], fp) config = configuration.get_config(cfg.strpath) this_app = create_app(config) this_app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://" this_app.use_reloader = False this_app.config['TESTING'] = True ctx = this_app.app_context() ctx.push() db.create_all() username, db_name = str(uuid.uuid4()).replace('-', '_'), str( uuid.uuid4()).replace('-', '_') request.cls.app_client = this_app.test_client() request.cls.db_name = remove_digits(db_name) request.cls.username = remove_digits(username) request.cls.backend = request.param yield if request.param == 'docker': delete_all_test_postgraas_container() elif request.param == 'pg_cluster': try: delete_test_database_and_user(db_name, username, dict(config.items('backend'))) except Exception: pass db.drop_all() ctx.pop()
def setUp(self): self.module_path = os.path.abspath(os.path.dirname(__file__)) self.this_app = create_app( configuration.get_config(os.path.join(self.module_path, 'application.cfg')) ) self.this_app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://" self.this_app.use_reloader = False self.this_app.config['TESTING'] = True
def setUp(self): self.module_path = os.path.abspath(os.path.dirname(__file__)) self.this_app = create_app( configuration.get_config( os.path.join(self.module_path, 'application.cfg'))) self.this_app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://" self.this_app.use_reloader = False self.this_app.config['TESTING'] = True
def setUp(self): self.module_path = os.path.abspath(os.path.dirname(__file__)) self.this_app = create_app(configuration.get_config(os.path.join(self.module_path, 'postgraas_server.cfg'))) #self.this_app.debug = True self.this_app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://" self.this_app.use_reloader = False self.this_app.config['TESTING'] = True self.app = self.this_app.test_client() self.delete_all_test_postgraas_container() from postgraas_server.management_resources import db with self.this_app.app_context(): db.drop_all() db.create_all()
def main(): from postgraas_server import postgraas_api config = get_config() db_credentials = { "db_name": config['metadb']['db_name'], "db_username": get_user(config), "db_pwd": get_password(config), "host": config['metadb']['host'], "port": config['metadb']['port'] } wait_for_postgres(db_credentials['db_name'], db_credentials['db_username'], db_credentials['db_pwd'], db_credentials['host'], db_credentials['port']) print("initializing db") init_db(postgraas_api.app)
def create_db_container(): config = get_config() db_credentials = { "db_name": config.get('metadb', 'db_name'), "db_username": config.get('metadb', 'db_username'), "db_pwd": config.get('metadb', 'db_pwd'), "host": config.get('metadb', 'host'), "port": config.get('metadb', 'port') } try: db_credentials['container_id'] = pg.create_postgres_instance('postgraas_master_db', db_credentials) except ValueError as e: print "warning container already exists" postrgaas_db = pg.get_container_by_name('postgraas_master_db') db_credentials['container_id'] = postrgaas_db['Id'] return db_credentials
def main(): from postgraas_server import postgraas_api config = get_config() db_credentials = { "db_name": config['metadb']['db_name'], "db_username": get_user(config), "db_pwd": get_password(config), "host": config['metadb']['host'], "port": config['metadb']['port'] } wait_for_postgres( db_credentials['db_name'], db_credentials['db_username'], db_credentials['db_pwd'], db_credentials['host'], db_credentials['port'] ) print("initializing db") init_db(postgraas_api.app)
def docker_setup(request, tmpdir): from postgraas_server.management_resources import db cfg = tmpdir.join('config') with open(cfg.strpath, "w") as fp: json.dump(CONFIGS['docker'], fp) this_app = create_app(configuration.get_config(cfg.strpath)) this_app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://" this_app.use_reloader = False this_app.config['TESTING'] = True ctx = this_app.app_context() ctx.push() db.create_all() request.cls.app_client = this_app.test_client() yield delete_all_test_postgraas_container() db.drop_all() ctx.pop()
def create_db_container(): config = get_config() print(config) db_credentials = { "db_name": config['metadb']['db_name'], "db_username": get_user(config), "db_pwd": get_password(config), "host": config['metadb']['host'], "port": config['metadb']['port'] } if pg.check_container_exists('postgraas_master_db'): print("warning container already exists") postgraas_db = pg.get_container_by_name('postgraas_master_db') db_credentials['container_id'] = postgraas_db.id else: db_credentials['container_id'] = pg.create_postgres_instance( 'postgraas_master_db', db_credentials) return db_credentials
def create_db_container(): config = get_config() print(config) db_credentials = { "db_name": config['metadb']['db_name'], "db_username": get_user(config), "db_pwd": get_password(config), "host": config['metadb']['host'], "port": config['metadb']['port'] } if pg.check_container_exists('postgraas_master_db'): print("warning container already exists") postgraas_db = pg.get_container_by_name('postgraas_master_db') db_credentials['container_id'] = postgraas_db.id else: db_credentials['container_id'] = pg.create_postgres_instance( 'postgraas_master_db', db_credentials ) return db_credentials
def run_server(test, port): """ This script provides monitoring information about the postgraas server. """ logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)-12s %(levelname)-8s %(message)s") config = cfg.get_config() collector = CustomCollector(config) if test: click.echo("TEST MODE") for metric in collector.collect(): for sample in metric.samples: click.echo(sample) else: click.echo("Running web server at port {}".format(port)) REGISTRY.register(collector) app = Flask(__name__) app.register_blueprint(blueprint) app.run(host='0.0.0.0', port=port, threaded=True)
def run_server(test, port): """ This script provides monitoring information about the postgraas server. """ logging.basicConfig( level=logging.INFO, format="%(asctime)s %(name)-12s %(levelname)-8s %(message)s") config = cfg.get_config() collector = CustomCollector(config) if test: click.echo("TEST MODE") for metric in collector.collect(): for sample in metric.samples: click.echo(sample) else: click.echo("Running web server at port {}".format(port)) REGISTRY.register(collector) app = Flask(__name__) app.register_blueprint(blueprint) app.run(host='0.0.0.0', port=port, threaded=True)
import logging from postgraas_server.configuration import get_config from postgraas_server.create_app import create_app logger = logging.getLogger(__name__) app = create_app(get_config()) if __name__ == "__main__": app.run(debug=True, use_reloader=True)
def test_get_config(self): test_config = os.path.join(self.module_path, 'application.cfg') actual = cf.get_config(test_config) expected = 'postgraas' assert actual['metadb']['db_name'] == expected
def test_get_config(self): test_config = os.path.join(self.module_path, 'postgraas_server.cfg') actual = cf.get_config(test_config) expected = 'postgraas' self.assertEqual(actual.get('metadb', 'db_name'), expected)