def pgcli(info, pgclirc): '''Start a pgcli session.''' from flask.globals import _app_ctx_stack app = _app_ctx_stack.top.app pgcli = PGCli(pgclirc_file=pgclirc) pgcli.connect_uri(app.config['SQLALCHEMY_DATABASE_URI']) pgcli.run_cli()
def test_application_name_db_uri(tmpdir): with mock.patch.object(PGExecute, '__init__') as mock_pgexecute: mock_pgexecute.return_value = None cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile"))) cli.connect_uri('postgres://[email protected]/?application_name=cow') mock_pgexecute.assert_called_with('bar', 'bar', '', 'baz.com', '', '', application_name='cow')
def test_port_db_uri(tmpdir): with mock.patch.object(PGCli, "connect") as mock_connect: cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile"))) cli.connect_uri("postgres://*****:*****@baz.com:2543/testdb") mock_connect.assert_called_with( database="testdb", host="baz.com", user="******", passwd="foo", port="2543" )
def test_quoted_db_uri(tmpdir): with mock.patch.object(PGCli, "connect") as mock_connect: cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile"))) cli.connect_uri("postgres://bar%5E:%[email protected]/testdb%5B") mock_connect.assert_called_with( database="testdb[", host="baz.com", user="******", passwd="]foo" )
def test_quoted_db_uri(tmpdir): with mock.patch.object(PGCli, 'connect') as mock_connect: cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile"))) cli.connect_uri('postgres://bar%5E:%[email protected]/testdb%5B') mock_connect.assert_called_with(database='testdb[', host='baz.com', user='******', passwd=']foo')
def test_application_name_db_uri(tmpdir): with mock.patch.object(PGExecute, "__init__") as mock_pgexecute: mock_pgexecute.return_value = None cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile"))) cli.connect_uri("postgres://[email protected]/?application_name=cow") mock_pgexecute.assert_called_with( "bar", "bar", "", "baz.com", "", "", application_name="cow" )
def shell(ctx): """Run database shell""" app = factory(ctx.obj['CONFIG']) with app.app_context(): pgcli = PGCli() database = str(app.extensions['sqlalchemy'].db.engine.url) pgcli.connect_uri(database) pgcli.logger.debug('Launch Params: \n\tdatabase: %r', database) pgcli.run_cli()
def test_port_db_uri(tmpdir): with mock.patch.object(PGCli, 'connect') as mock_connect: cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile"))) cli.connect_uri('postgres://*****:*****@baz.com:2543/testdb') mock_connect.assert_called_with(database='testdb', host='baz.com', user='******', passwd='foo', port='2543')
def sql_shell(): try: from pgcli.main import PGCli except ImportError: print('PGCli was not found, please install it with: pip install pgcli') sys.exit(1) conn_string = server.config.database.connection_string.strip("'") pgcli = PGCli() pgcli.connect_uri(conn_string) pgcli.run_cli()
def sql_shell(): conn_string = faraday.server.config.database.connection_string.strip("'") conn_string = urlparse(conn_string) parsed_conn_string = ("user={username} password={password} host={hostname} dbname={dbname}" .format(username=conn_string.username, password=conn_string.password, hostname=conn_string.hostname, dbname=conn_string.path[1:])) pgcli = PGCli() pgcli.connect_uri(parsed_conn_string) pgcli.run_cli()
def test_ssl_db_uri(tmpdir): with mock.patch.object(PGCli, 'connect') as mock_connect: cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile"))) cli.connect_uri( 'postgres://bar%5E:%[email protected]/testdb%5B?' 'sslmode=verify-full&sslcert=m%79.pem&sslkey=my-key.pem&sslrootcert=c%61.pem') mock_connect.assert_called_with(database='testdb[', host='baz.com', user='******', passwd=']foo', sslmode='verify-full', sslcert='my.pem', sslkey='my-key.pem', sslrootcert='ca.pem')
def test_ssl_db_uri(tmpdir): with mock.patch.object(PGCli, 'connect') as mock_connect: cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile"))) cli.connect_uri('postgres://bar%5E:%[email protected]/testdb%5B?' 'sslmode=verify-full&sslcert=m%79.pem&sslkey=' 'my-key.pem&sslrootcert=c%61.pem') mock_connect.assert_called_with(database='testdb[', host='baz.com', port=None, user='******', passwd=']foo', sslmode='verify-full', sslcert='my.pem', sslkey='my-key.pem', sslrootcert='ca.pem')
def sql_shell(): try: from pgcli.main import PGCli except ImportError: print('PGCli was not found, please install it with: pip install pgcli') sys.exit(1) conn_string = faraday.server.config.database.connection_string.strip("'") conn_string = urlparse(conn_string) parsed_conn_string = ("user={username} password={password} host={hostname} dbname={dbname}" .format(username=conn_string.username, password=conn_string.password, hostname=conn_string.hostname, dbname=conn_string.path[1:])) pgcli = PGCli() pgcli.connect_uri(parsed_conn_string) pgcli.run_cli()
def test_ssl_db_uri(tmpdir): with mock.patch.object(PGCli, "connect") as mock_connect: cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile"))) cli.connect_uri( "postgres://bar%5E:%[email protected]/testdb%5B?" "sslmode=verify-full&sslcert=m%79.pem&sslkey=my-key.pem&sslrootcert=c%61.pem" ) mock_connect.assert_called_with( database="testdb[", host="baz.com", user="******", passwd="]foo", sslmode="verify-full", sslcert="my.pem", sslkey="my-key.pem", sslrootcert="ca.pem", )