mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Added python_shell=True, quoted user input
This commit is contained in:
parent
aa023f25b8
commit
89d8faaeb1
1 changed files with 23 additions and 4 deletions
|
@ -3,6 +3,10 @@
|
|||
Manage and query NPM packages.
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
try:
|
||||
from shlex import quote as _cmd_quote # pylint: disable=E0611
|
||||
except ImportError:
|
||||
from pipes import quote as _cmd_quote
|
||||
|
||||
# Import python libs
|
||||
import json
|
||||
|
@ -44,7 +48,7 @@ def _check_valid_version(salt):
|
|||
'''
|
||||
# pylint: disable=no-member
|
||||
npm_version = distutils.version.LooseVersion(
|
||||
salt['cmd.run']('npm --version'))
|
||||
salt['cmd.run']('npm --version', python_shell=True))
|
||||
valid_version = distutils.version.LooseVersion('1.2')
|
||||
# pylint: enable=no-member
|
||||
if npm_version < valid_version:
|
||||
|
@ -105,6 +109,13 @@ def install(pkg=None,
|
|||
salt '*' npm.install coffee-script@1.0.1
|
||||
|
||||
'''
|
||||
# Protect against injection
|
||||
if pkg:
|
||||
pkg = _cmd_quote(pkg)
|
||||
if pkgs:
|
||||
pkgs = ' '.join([_cmd_quote(item) for item in pkgs.split()])
|
||||
if registry:
|
||||
registry = _cmd_quote(registry)
|
||||
|
||||
cmd = 'npm install --silent --json'
|
||||
|
||||
|
@ -118,6 +129,8 @@ def install(pkg=None,
|
|||
cmd += ' "{0}"'.format(pkg)
|
||||
elif pkgs:
|
||||
cmd += ' "{0}"'.format('" "'.join(pkgs))
|
||||
else:
|
||||
return 'No package name specified'
|
||||
|
||||
if env is None:
|
||||
env = {}
|
||||
|
@ -127,7 +140,7 @@ def install(pkg=None,
|
|||
if uid:
|
||||
env.update({'SUDO_UID': b'{0}'.format(uid), 'SUDO_USER': b''})
|
||||
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False, cwd=dir, runas=runas, env=env)
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=True, cwd=dir, runas=runas, env=env)
|
||||
|
||||
if result['retcode'] != 0:
|
||||
raise CommandExecutionError(result['stderr'])
|
||||
|
@ -190,6 +203,9 @@ def uninstall(pkg,
|
|||
salt '*' npm.uninstall coffee-script
|
||||
|
||||
'''
|
||||
# Protect against injection
|
||||
if pkg:
|
||||
pkg = _cmd_quote(pkg)
|
||||
|
||||
if env is None:
|
||||
env = {}
|
||||
|
@ -206,7 +222,7 @@ def uninstall(pkg,
|
|||
|
||||
cmd += ' "{0}"'.format(pkg)
|
||||
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=False, cwd=dir, runas=runas, env=env)
|
||||
result = __salt__['cmd.run_all'](cmd, python_shell=True, cwd=dir, runas=runas, env=env)
|
||||
|
||||
if result['retcode'] != 0:
|
||||
log.error(result['stderr'])
|
||||
|
@ -250,6 +266,9 @@ def list_(pkg=None,
|
|||
salt '*' npm.list
|
||||
|
||||
'''
|
||||
# Protect against injection
|
||||
if pkg:
|
||||
pkg = _cmd_quote(pkg)
|
||||
|
||||
if env is None:
|
||||
env = {}
|
||||
|
@ -272,7 +291,7 @@ def list_(pkg=None,
|
|||
cwd=dir,
|
||||
runas=runas,
|
||||
env=env,
|
||||
python_shell=False,
|
||||
python_shell=True,
|
||||
ignore_retcode=True)
|
||||
|
||||
# npm will return error code 1 for both no packages found and an actual
|
||||
|
|
Loading…
Add table
Reference in a new issue