Migrate away from pipes.quote (#56785)

* Migrate away from pipes.quote

* Fix sanity
This commit is contained in:
Martin Krizek 2019-05-24 21:48:42 +02:00 committed by Brian Coca
parent 86354ff1fb
commit 3b9478ade0
6 changed files with 54 additions and 54 deletions

View file

@ -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