Prevent default use of shell when running commands as postgres
so that our sudoers config can work as expected
This commit is contained in:
parent
c87ef42bad
commit
c8e24a55cf
|
@ -59,7 +59,7 @@ def sql(sql, database='', port=None):
|
||||||
cmd = 'psql {port} --tuples-only --no-align --command="{sql}" {database}'.format(
|
cmd = 'psql {port} --tuples-only --no-align --command="{sql}" {database}'.format(
|
||||||
port='--port={}'.format(port) if port else '',
|
port='--port={}'.format(port) if port else '',
|
||||||
sql=sql, database=database)
|
sql=sql, database=database)
|
||||||
return sudo(cmd, user='postgres')
|
return sudo(cmd, user='postgres', shell=False)
|
||||||
|
|
||||||
|
|
||||||
def script(path, database='', port=None, user=None, password=None):
|
def script(path, database='', port=None, user=None, password=None):
|
||||||
|
@ -75,7 +75,7 @@ def script(path, database='', port=None, user=None, password=None):
|
||||||
|
|
||||||
else: # run as postgres
|
else: # run as postgres
|
||||||
kw = dict(port=port, path=path, db=database)
|
kw = dict(port=port, path=path, db=database)
|
||||||
return sudo("psql {port} --file='{path}' {db}".format(**kw), user='postgres')
|
return sudo("psql {port} --file='{path}' {db}".format(**kw), user='postgres', shell=False)
|
||||||
|
|
||||||
|
|
||||||
def user_exists(name, port=None):
|
def user_exists(name, port=None):
|
||||||
|
@ -95,7 +95,7 @@ def create_user(name, password=None, port=None, checkfirst=True, createdb=False)
|
||||||
port='--port={}'.format(port) if port else '',
|
port='--port={}'.format(port) if port else '',
|
||||||
createdb='--{}createdb'.format('' if createdb else 'no-'),
|
createdb='--{}createdb'.format('' if createdb else 'no-'),
|
||||||
name=name)
|
name=name)
|
||||||
sudo(cmd, user='postgres')
|
sudo(cmd, user='postgres', shell=False)
|
||||||
if password:
|
if password:
|
||||||
set_user_password(name, password, port=port)
|
set_user_password(name, password, port=port)
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ def create_db(name, owner=None, port=None, checkfirst=True):
|
||||||
port='--port={}'.format(port) if port else '',
|
port='--port={}'.format(port) if port else '',
|
||||||
owner='--owner={}'.format(owner) if owner else '',
|
owner='--owner={}'.format(owner) if owner else '',
|
||||||
name=name)
|
name=name)
|
||||||
sudo(cmd, user='postgres')
|
sudo(cmd, user='postgres', shell=False)
|
||||||
|
|
||||||
|
|
||||||
def create_schema(name, dbname, owner='rattail', port=None):
|
def create_schema(name, dbname, owner='rattail', port=None):
|
||||||
|
@ -141,7 +141,7 @@ def drop_db(name, checkfirst=True):
|
||||||
Drop a PostgreSQL database.
|
Drop a PostgreSQL database.
|
||||||
"""
|
"""
|
||||||
if not checkfirst or db_exists(name):
|
if not checkfirst or db_exists(name):
|
||||||
sudo('dropdb {}'.format(name), user='postgres')
|
sudo('dropdb {}'.format(name), user='postgres', shell=False)
|
||||||
|
|
||||||
|
|
||||||
def download_db(name, destination=None, port=None, exclude_tables=None):
|
def download_db(name, destination=None, port=None, exclude_tables=None):
|
||||||
|
@ -156,7 +156,7 @@ def download_db(name, destination=None, port=None, exclude_tables=None):
|
||||||
name=name,
|
name=name,
|
||||||
port='--port={}'.format(port) if port else '',
|
port='--port={}'.format(port) if port else '',
|
||||||
exclude_tables='--exclude-table-data={}'.format(exclude_tables) if exclude_tables else '')
|
exclude_tables='--exclude-table-data={}'.format(exclude_tables) if exclude_tables else '')
|
||||||
sudo(cmd, user='postgres')
|
sudo(cmd, user='postgres', shell=False)
|
||||||
run('gzip --force {0}.sql'.format(name))
|
run('gzip --force {0}.sql'.format(name))
|
||||||
get('{0}.sql.gz'.format(name), destination)
|
get('{0}.sql.gz'.format(name), destination)
|
||||||
run('rm {0}.sql.gz'.format(name))
|
run('rm {0}.sql.gz'.format(name))
|
||||||
|
@ -193,5 +193,5 @@ def clone_db(name, owner, download, user='rattail', force=False, workdir=None):
|
||||||
|
|
||||||
# restore database on target server
|
# restore database on target server
|
||||||
run('gunzip --force {}.sql.gz'.format(name))
|
run('gunzip --force {}.sql.gz'.format(name))
|
||||||
sudo('psql --echo-errors --file={0}.sql {0}'.format(name), user='postgres')
|
sudo('psql --echo-errors --file={0}.sql {0}'.format(name), user='postgres', shell=False)
|
||||||
run('rm {}.sql'.format(name))
|
run('rm {}.sql'.format(name))
|
||||||
|
|
Loading…
Reference in a new issue