def test_revoke_permissions(db_config, namespace, add_test_database_user, permission, invalid_permission_fn, valid_permission_fn): # simulate loading a different dictionary if namespace: models.load_dictionary(dictionary=None, package_namespace=namespace) dummy_user, dummy_pwd = add_test_database_user g = psqlgraph.PsqlGraphDriver( host=db_config["host"], user=dummy_user, password=dummy_pwd, database=db_config["database"], package_namespace=namespace, ) # grant user permissions run_admin_command( ["graph-grant", "--{}={}".format(permission, dummy_user)]) # verify user has permission valid_permission_fn(g) # revoke permission run_admin_command( ["graph-revoke", "--{}={}".format(permission, dummy_user)]) # verify user no longer has permission invalid_permission_fn(g)
def get_admin_driver(db_config, namespace=None): # assumes no password postgres user g = psqlgraph.PsqlGraphDriver(package_namespace=namespace, host=db_config["host"], user="******", password=None, database=db_config["database"]) return g
def db(graph_models): models, _ = graph_models db_driver = psqlgraph.PsqlGraphDriver(host="localhost", user="******", password="******", database="gexplorer") # precautionary drop_all(db_driver.engine) psqlgraph.create_all(db_driver.engine) add_project(db_driver, models) yield db_driver drop_all(db_driver.engine)
def connect_to_psql(self, host, user, password, database): self.psqlgraphDriver = psqlgraph.PsqlGraphDriver( host, user, password, database)
default='localhost', type=str, help='host of the postgres server') parser.add_argument('-u', '--user', default='test', type=str, help='user to connect to postgres as') parser.add_argument('-p', '--password', default=None, type=str, help='password for given user. If no ' 'password given, one will be prompted.') args = parser.parse_args() print(message.format(args.database, args.host, args.user)) if args.password is None: args.password = getpass.getpass() g = psqlgraph.PsqlGraphDriver(args.host, args.user, args.password, args.database) with g.session_scope() as s: rb = s.rollback if ipython: IPython.embed() else: code.InteractiveConsole(locals=globals()).interact()
def init_pg_graph(): return psqlgraph.PsqlGraphDriver(host=os.environ.get( "DB_HOST", "postgres.service.consul"), user=os.environ.get("DB_USER"), password=os.environ.get("DB_PWD"), database=os.environ.get("DB_NAME"))