Exemplo n.º 1
0
def migrate_user(old_username, new_username, password, superuser=False):
    if postgresql.is_primary():
        # We do this on any primary, as the master is
        # appointed later. It also works if we have
        # a weird setup with manual_replication and
        # multiple primaries.
        con = postgresql.connect()
        postgresql.ensure_user(con,
                               new_username,
                               password,
                               superuser=superuser)
        cur = con.cursor()
        hookenv.log("Granting old role {} to new role {}"
                    "".format(old_username, new_username))
        cur.execute(
            "GRANT %s TO %s",
            (
                postgresql.pgidentifier(old_username),
                postgresql.pgidentifier(new_username),
            ),
        )
        con.commit()
    else:
        hookenv.log("Primary must map role {!r} to {!r}"
                    "".format(old_username, new_username))
Exemplo n.º 2
0
def migrate_user(old_username, new_username, password, superuser=False):
    if postgresql.is_primary():
        # We do this on any primary, as the master is
        # appointed later. It also works if we have
        # a weird setup with manual_replication and
        # multiple primaries.
        con = postgresql.connect()
        postgresql.ensure_user(con, new_username, password,
                               superuser=superuser)
        cur = con.cursor()
        hookenv.log('Granting old role {} to new role {}'
                    ''.format(old_username, new_username))
        cur.execute('GRANT %s TO %s',
                    (postgresql.pgidentifier(old_username),
                        postgresql.pgidentifier(new_username)))
        con.commit()
    else:
        hookenv.log('Primary must map role {!r} to {!r}'
                    ''.format(old_username, new_username))
Exemplo n.º 3
0
 def test_pgidentifier(self):
     a = postgresql.pgidentifier("magic")
     self.assertEqual(a, postgresql.AsIs('"magic"'))
Exemplo n.º 4
0
 def test_pgidentifier(self):
     a = postgresql.pgidentifier('magic')
     self.assertEqual(a, postgresql.AsIs('"magic"'))