コード例 #1
0
 def test_create_user_with_no_connection_limit(self, _run_as_pg):
     from fabtools import postgres
     postgres.create_user('foo', 'bar', connection_limit=-1)
     expected = (
         'psql -c "CREATE USER foo NOSUPERUSER NOCREATEDB NOCREATEROLE '
         'INHERIT LOGIN CONNECTION LIMIT -1 UNENCRYPTED PASSWORD \'bar\';"')
     self.assertEqual(expected, _run_as_pg.call_args[0][0])
コード例 #2
0
 def test_create_user_with_no_options(self, _run_as_pg):
     from fabtools import postgres
     postgres.create_user('foo', 'bar')
     expected = (
         'psql -c "CREATE USER foo NOSUPERUSER NOCREATEDB NOCREATEROLE '
         'INHERIT LOGIN PASSWORD \'bar\';"')
     self.assertEqual(expected, _run_as_pg.call_args[0][0])
コード例 #3
0
ファイル: postgres.py プロジェクト: medecau/fabtools
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
        )
コード例 #4
0
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)
コード例 #5
0
 def test_create_user_with_no_connection_limit(self, _run_as_pg):
     from fabtools import postgres
     postgres.create_user('foo', 'bar', connection_limit=-1)
     expected = (
         'psql -c "CREATE USER foo NOSUPERUSER NOCREATEDB NOCREATEROLE '
         'INHERIT LOGIN CONNECTION LIMIT -1 UNENCRYPTED PASSWORD \'bar\';"')
     self.assertEqual(expected, _run_as_pg.call_args[0][0])
コード例 #6
0
 def test_create_user_with_no_options(self, _run_as_pg):
     from fabtools import postgres
     postgres.create_user('foo', 'bar')
     expected = (
         'psql -c "CREATE USER foo NOSUPERUSER NOCREATEDB NOCREATEROLE '
         'INHERIT LOGIN PASSWORD \'bar\';"')
     self.assertEqual(expected, _run_as_pg.call_args[0][0])
コード例 #7
0
def setup_postgres():
    """Initial postgres setup."""
    if not db.user_exists(env.database_user):
        if 'database_pw' not in env:
            prompt('PostgreSQL database password:'******'database_pw')
        create_user(env.database_user, password=env.database_pw, encrypted_password=True)
    if not database_exists(env.database_name):
        create_database(env.database_name, env.database_user)
コード例 #8
0
ファイル: test_postgres.py プロジェクト: zloy531/fabtools3
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')
コード例 #9
0
ファイル: test_postgres.py プロジェクト: harobed/fabtools
    def test_create_user_with_no_options(self, _run_as_pg):
        from fabtools import postgres

        postgres.create_user("foo", "bar")
        expected = (
            'psql -c "CREATE USER foo NOSUPERUSER NOCREATEDB NOCREATEROLE '
            "INHERIT LOGIN UNENCRYPTED PASSWORD 'bar';\""
        )
        self.assertEqual(expected, _run_as_pg.call_args[0][0])
コード例 #10
0
ファイル: test_postgres.py プロジェクト: DaveHewy/fabtools
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')
コード例 #11
0
 def test_create_user_with_custom_options(self, _run_as_pg):
     from fabtools import postgres
     postgres.create_user('foo', 'bar', superuser=True, createdb=True,
                          createrole=True, inherit=False, login=False,
                          connection_limit=20, encrypted_password=True)
     expected = (
         'psql -c "CREATE USER "\'"foo"\'" SUPERUSER CREATEDB CREATEROLE '
         'NOINHERIT NOLOGIN CONNECTION LIMIT 20 '
         'ENCRYPTED PASSWORD \'bar\';"')
     self.assertEqual(expected, _run_as_pg.call_args[0][0])
コード例 #12
0
 def test_create_user_with_custom_options(self, _run_as_pg):
     from fabtools import postgres
     postgres.create_user('foo', 'bar', superuser=True, createdb=True,
                          createrole=True, inherit=False, login=False,
                          connection_limit=20, encrypted_password=True)
     expected = (
         'psql -c "CREATE USER foo SUPERUSER CREATEDB CREATEROLE '
         'NOINHERIT NOLOGIN CONNECTION LIMIT 20 '
         'ENCRYPTED PASSWORD \'bar\';"')
     self.assertEqual(expected, _run_as_pg.call_args[0][0])
コード例 #13
0
    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')
コード例 #14
0
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"])
コード例 #15
0
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))
コード例 #16
0
ファイル: fabfile.py プロジェクト: webgeodatavore/projecta
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))
コード例 #17
0
ファイル: fabfile.py プロジェクト: kbeyazli/common-scripts
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
コード例 #18
0
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)
コード例 #19
0
def postgresql_user_create():
    if not postgres.user_exists(DATABASE_OWNER):
        postgres.create_user(DATABASE_OWNER, DATABASE_OWNER_PASSWORD)
コード例 #20
0
def setup_postgres_user():
    """Set up the postgresql instance."""
    create_user("wsgi", "")
コード例 #21
0
ファイル: fabfile.py プロジェクト: gitter-badger/projecta
def setup_postgres_user():
    """Set up the postgresql instance."""
    create_user('wsgi', '')
コード例 #22
0
ファイル: fabfile.py プロジェクト: webgeodatavore/projecta
def setup_postgres_user():
    """Set up the postgresql instance."""
    create_user('wsgi', '')