def test_create_and_drop_user(postgres_server): from fabtools.postgres import create_user, drop_user, user_exists create_user('alice', password='******') assert user_exists('alice') drop_user('alice') assert not user_exists('alice')
def user(name, password, superuser=False, createdb=False, createrole=False, inherit=True, login=True, connection_limit=None, encrypted_password=False): """ Require the existence of a PostgreSQL user. The password and options provided will only be applied when creating a new user (existing users will *not* be modified). :: from fabtools import require require.postgres.user('dbuser', password='******') require.postgres.user('dbuser2', password='******', createdb=True, create_role=True, connection_limit=20) """ if not user_exists(name): create_user(name, password, superuser, createdb, createrole, inherit, login, connection_limit, encrypted_password)
def setup_postgres(): require.postgres.server() # NOTE: fabtools.require.postgres.user did not allow me to create a user with no pw if not postgres.user_exists(SITE_USER): su('createuser -S -D -R -w %s' % SITE_USER, 'postgres') if not postgres.database_exists(SITE_USER): require.postgres.database(SITE_USER, SITE_USER, encoding='UTF8', locale='en_US.UTF-8')
def user( name, password, superuser=False, createdb=False, createrole=False, inherit=True, login=True, connection_limit=None, encrypted_password=False, ): """ Require the existence of a PostgreSQL user. The password and options provided will only be applied when creating a new user (existing users will *not* be modified). :: from fabtools import require require.postgres.user('dbuser', password='******') require.postgres.user('dbuser2', password='******', createdb=True, createrole=True, connection_limit=20) """ if not user_exists(name): create_user( name, password, superuser, createdb, createrole, inherit, login, connection_limit, encrypted_password )
def setup_database(): require.postgres.server() # NOTE: fabtools.require.postgres.user did not allow me to create a user with no pw prompt? if not postgres.user_exists(SITE_USER): su('createuser -S -D -R -w %s' % SITE_USER, 'postgres') if not postgres.database_exists(SITE_USER): require.postgres.database(SITE_USER, SITE_USER, encoding='UTF8', locale='en_US.UTF-8')
def setup_database(): user = SITE_SETTINGS["user"] require.postgres.server() # TODO: fabtools.require.postgres.user did not allow a user with no pw prompt? see if there is a better way if not postgres.user_exists(user): su("createuser -S -D -R -w %s" % user, "postgres") if not postgres.database_exists(user): require.postgres.database(user, user, encoding="UTF8", locale="en_US.UTF-8")
def test_require_user(postgres_server): from fabtools.postgres import user_exists, drop_user from fabtools.require.postgres import user user('bob', password='******') assert user_exists('bob') drop_user('bob')
def run(self): user = env['user'] if self.user: user = self.user if not funcs.user_exists(user): funcs.create_user(user, self.password) if not funcs.database_exists(self.database): funcs.create_database( self.database, user, locale='ja_JP.utf8')
def setup_database(): user = SITE_SETTINGS['user'] require.postgres.server() # TODO: fabtools.require.postgres.user did not allow a user with no pw prompt? see if there is a better way if not postgres.user_exists(user): su('createuser -S -D -R -w %s' % user, 'postgres') if not postgres.database_exists(user): require.postgres.database(user, user, encoding='UTF8', locale='en_US.UTF-8')
def server_prepare(): """ installing all necessary packages """ apt_packages = ('libpq-dev', 'python3-dev', 'libssl-dev', 'lib32ncurses5-dev', 'python3', 'postgresql', 'postgis',) sudo('apt-get install %s' % " ".join(apt_packages)) sudo('easy_install pip') """ db routines """ db_env = DB[env.environment] if not postgres.user_exists(db_env["user"]): postgres.create_user(db_env["user"], db_env["password"], createdb=True, createrole=True) if not postgres.database_exists(db_env['db']): postgres.create_database(db_env['db'], owner=db_env["user"])
def set_db_permissions(): """Set the db so user wsgi has all permissions. """ user = "******" dbname = "changelog" if not user_exists(user): create_user(user, password="******") if not database_exists(dbname): create_database(dbname, user) grant_sql = "GRANT ALL ON schema public to %s;" % user # assumption is env.repo_alias is also database name run('psql %s -c "%s"' % (dbname, grant_sql)) grant_sql = "GRANT ALL ON ALL TABLES IN schema public to %s;" % user # assumption is env.repo_alias is also database name run('psql %s -c "%s"' % (dbname, grant_sql)) grant_sql = "GRANT ALL ON ALL SEQUENCES IN schema public to %s;" % user run('psql %s -c "%s"' % (dbname, grant_sql))
def set_db_permissions(): """Set the db so user wsgi has all permissions. """ user = '******' dbname = 'changelog' if not user_exists(user): create_user(user, password='******') if not database_exists(dbname): create_database(dbname, user) grant_sql = 'GRANT ALL ON schema public to %s;' % user # assumption is env.repo_alias is also database name run('psql %s -c "%s"' % (dbname, grant_sql)) grant_sql = ( 'GRANT ALL ON ALL TABLES IN schema public to %s;' % user) # assumption is env.repo_alias is also database name run('psql %s -c "%s"' % (dbname, grant_sql)) grant_sql = ( 'GRANT ALL ON ALL SEQUENCES IN schema public to %s;' % user) run('psql %s -c "%s"' % (dbname, grant_sql))
def create_pgsql_user(username, password=None): if postgres.user_exists(username): raise KeyError("Username {} is taken".format(username)) if password is None: password = gen_pass(10) postgres.create_user(username, password=password, createdb=True) db_not_created = True db_name = "" while db_not_created: db_name = gen_pass(12) + "_DB" if not postgres.database_exists(db_name): postgres.create_database(db_name, owner=username) db_not_created = False print c.blue("Username="******"Password="******"DB Name =", bold=True),\ c.green(db_name, bold=True) return username, password, db_name
def configure_postgres_role(): if user_exists("postgres"): _run_as_pg( "psql -U postgres -c \"ALTER USER postgres WITH password '{0}'\"". format(env.postgresql_role_password))
def add_pg_user(): print(green("Adding Postgres user - " + settings.DB_USER)) #print(postgres.user_exists(DB_USER)) # doesn't check correctly if not postgres.user_exists(settings.DB_USER): postgres.create_user(settings.DB_USER, password=settings.DB_PASSWORD, encrypted_password=True)
def postgresql_user_create(): if not postgres.user_exists(DATABASE_OWNER): postgres.create_user(DATABASE_OWNER, DATABASE_OWNER_PASSWORD)
def configure_postgres_role(): if user_exists("postgres"): _run_as_pg("psql -U postgres -c \"ALTER USER postgres WITH password '{0}'\"".format(env.postgresql_role_password))