mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Migrate away from pipes.quote (#56785)
* Migrate away from pipes.quote * Fix sanity
This commit is contained in:
parent
86354ff1fb
commit
3b9478ade0
6 changed files with 54 additions and 54 deletions
|
@ -101,13 +101,13 @@ EXAMPLES = r'''
|
|||
'''
|
||||
|
||||
import os
|
||||
import pipes
|
||||
import subprocess
|
||||
import traceback
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.database import mysql_quote_identifier
|
||||
from ansible.module_utils.mysql import mysql_connect, mysql_driver, mysql_driver_fail_msg
|
||||
from ansible.module_utils.six.moves import shlex_quote
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
|
@ -132,25 +132,25 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port,
|
|||
cmd = module.get_bin_path('mysqldump', True)
|
||||
# If defined, mysqldump demands --defaults-extra-file be the first option
|
||||
if config_file:
|
||||
cmd += " --defaults-extra-file=%s" % pipes.quote(config_file)
|
||||
cmd += " --defaults-extra-file=%s" % shlex_quote(config_file)
|
||||
if user is not None:
|
||||
cmd += " --user=%s" % pipes.quote(user)
|
||||
cmd += " --user=%s" % shlex_quote(user)
|
||||
if password is not None:
|
||||
cmd += " --password=%s" % pipes.quote(password)
|
||||
cmd += " --password=%s" % shlex_quote(password)
|
||||
if ssl_cert is not None:
|
||||
cmd += " --ssl-cert=%s" % pipes.quote(ssl_cert)
|
||||
cmd += " --ssl-cert=%s" % shlex_quote(ssl_cert)
|
||||
if ssl_key is not None:
|
||||
cmd += " --ssl-key=%s" % pipes.quote(ssl_key)
|
||||
cmd += " --ssl-key=%s" % shlex_quote(ssl_key)
|
||||
if ssl_ca is not None:
|
||||
cmd += " --ssl-ca=%s" % pipes.quote(ssl_ca)
|
||||
cmd += " --ssl-ca=%s" % shlex_quote(ssl_ca)
|
||||
if socket is not None:
|
||||
cmd += " --socket=%s" % pipes.quote(socket)
|
||||
cmd += " --socket=%s" % shlex_quote(socket)
|
||||
else:
|
||||
cmd += " --host=%s --port=%i" % (pipes.quote(host), port)
|
||||
cmd += " --host=%s --port=%i" % (shlex_quote(host), port)
|
||||
if all_databases:
|
||||
cmd += " --all-databases"
|
||||
else:
|
||||
cmd += " %s" % pipes.quote(db_name)
|
||||
cmd += " %s" % shlex_quote(db_name)
|
||||
if single_transaction:
|
||||
cmd += " --single-transaction=true"
|
||||
if quick:
|
||||
|
@ -168,9 +168,9 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port,
|
|||
path = module.get_bin_path('xz', True)
|
||||
|
||||
if path:
|
||||
cmd = '%s | %s > %s' % (cmd, path, pipes.quote(target))
|
||||
cmd = '%s | %s > %s' % (cmd, path, shlex_quote(target))
|
||||
else:
|
||||
cmd += " > %s" % pipes.quote(target)
|
||||
cmd += " > %s" % shlex_quote(target)
|
||||
|
||||
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
|
||||
return rc, stdout, stderr
|
||||
|
@ -183,25 +183,25 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
|
|||
cmd = [module.get_bin_path('mysql', True)]
|
||||
# --defaults-file must go first, or errors out
|
||||
if config_file:
|
||||
cmd.append("--defaults-extra-file=%s" % pipes.quote(config_file))
|
||||
cmd.append("--defaults-extra-file=%s" % shlex_quote(config_file))
|
||||
if user:
|
||||
cmd.append("--user=%s" % pipes.quote(user))
|
||||
cmd.append("--user=%s" % shlex_quote(user))
|
||||
if password:
|
||||
cmd.append("--password=%s" % pipes.quote(password))
|
||||
cmd.append("--password=%s" % shlex_quote(password))
|
||||
if ssl_cert is not None:
|
||||
cmd.append("--ssl-cert=%s" % pipes.quote(ssl_cert))
|
||||
cmd.append("--ssl-cert=%s" % shlex_quote(ssl_cert))
|
||||
if ssl_key is not None:
|
||||
cmd.append("--ssl-key=%s" % pipes.quote(ssl_key))
|
||||
cmd.append("--ssl-key=%s" % shlex_quote(ssl_key))
|
||||
if ssl_ca is not None:
|
||||
cmd.append("--ssl-ca=%s" % pipes.quote(ssl_ca))
|
||||
cmd.append("--ssl-ca=%s" % shlex_quote(ssl_ca))
|
||||
if socket is not None:
|
||||
cmd.append("--socket=%s" % pipes.quote(socket))
|
||||
cmd.append("--socket=%s" % shlex_quote(socket))
|
||||
else:
|
||||
cmd.append("--host=%s" % pipes.quote(host))
|
||||
cmd.append("--host=%s" % shlex_quote(host))
|
||||
cmd.append("--port=%i" % port)
|
||||
if not all_databases:
|
||||
cmd.append("-D")
|
||||
cmd.append(pipes.quote(db_name))
|
||||
cmd.append(shlex_quote(db_name))
|
||||
|
||||
comp_prog_path = None
|
||||
if os.path.splitext(target)[-1] == '.gz':
|
||||
|
@ -224,7 +224,7 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
|
|||
return p2.returncode, stdout2, stderr2
|
||||
else:
|
||||
cmd = ' '.join(cmd)
|
||||
cmd += " < %s" % pipes.quote(target)
|
||||
cmd += " < %s" % shlex_quote(target)
|
||||
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
|
||||
return rc, stdout, stderr
|
||||
|
||||
|
|
|
@ -159,7 +159,6 @@ EXAMPLES = r'''
|
|||
'''
|
||||
|
||||
import os
|
||||
import pipes
|
||||
import subprocess
|
||||
import traceback
|
||||
|
||||
|
@ -175,17 +174,18 @@ import ansible.module_utils.postgres as pgutils
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.database import SQLParseError, pg_quote_identifier
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils.six.moves import shlex_quote
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
class NotSupportedError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
# ===========================================
|
||||
# PostgreSQL module specific support methods.
|
||||
#
|
||||
|
||||
|
||||
def set_owner(cursor, db, owner):
|
||||
query = "ALTER DATABASE %s OWNER TO %s" % (
|
||||
pg_quote_identifier(db, 'database'),
|
||||
|
@ -348,9 +348,9 @@ def db_dump(module, target, target_opts="",
|
|||
# in a portable way.
|
||||
fifo = os.path.join(module.tmpdir, 'pg_fifo')
|
||||
os.mkfifo(fifo)
|
||||
cmd = '{1} <{3} > {2} & {0} >{3}'.format(cmd, comp_prog_path, pipes.quote(target), fifo)
|
||||
cmd = '{1} <{3} > {2} & {0} >{3}'.format(cmd, comp_prog_path, shlex_quote(target), fifo)
|
||||
else:
|
||||
cmd = '{0} > {1}'.format(cmd, pipes.quote(target))
|
||||
cmd = '{0} > {1}'.format(cmd, shlex_quote(target))
|
||||
|
||||
return do_with_password(module, cmd, password)
|
||||
|
||||
|
@ -402,7 +402,7 @@ def db_restore(module, target, target_opts="",
|
|||
else:
|
||||
return p2.returncode, '', stderr2, 'cmd: ****'
|
||||
else:
|
||||
cmd = '{0} < {1}'.format(cmd, pipes.quote(target))
|
||||
cmd = '{0} < {1}'.format(cmd, shlex_quote(target))
|
||||
|
||||
return do_with_password(module, cmd, password)
|
||||
|
||||
|
@ -419,9 +419,9 @@ def login_flags(db, host, port, user, db_prefix=True):
|
|||
flags = []
|
||||
if db:
|
||||
if db_prefix:
|
||||
flags.append(' --dbname={0}'.format(pipes.quote(db)))
|
||||
flags.append(' --dbname={0}'.format(shlex_quote(db)))
|
||||
else:
|
||||
flags.append(' {0}'.format(pipes.quote(db)))
|
||||
flags.append(' {0}'.format(shlex_quote(db)))
|
||||
if host:
|
||||
flags.append(' --host={0}'.format(host))
|
||||
if port:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue