Fix dangerous default args. (#29839)

This commit is contained in:
Matt Clay 2017-09-12 00:11:13 -07:00 committed by GitHub
commit 68aeaa58a8
50 changed files with 253 additions and 87 deletions

View file

@ -76,7 +76,9 @@ def check_args(module, warnings):
module.params[key] = ARGS_DEFAULT_VALUE[key]
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = [] if flags is None else flags
cmd = 'show run-config commands '
cmd += ' '.join(flags)
cmd = cmd.strip()

View file

@ -66,7 +66,9 @@ def check_args(module, warnings):
module.params[key] = ARGS_DEFAULT_VALUE[key]
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = [] if flags is None else flags
cmd = 'show running-config '
cmd += ' '.join(flags)
cmd = cmd.strip()

View file

@ -117,7 +117,9 @@ def run_commands(module, commands, check_rc=True):
return responses
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = [] if flags is None else flags
passwords = module.params['passwords']
if passwords:
cmd = 'more system:running-config'

View file

@ -40,7 +40,9 @@ from ansible.module_utils.ec2 import camel_dict_to_snake_dict
class DirectConnectError(Exception):
def __init__(self, msg, last_traceback=None, response={}):
def __init__(self, msg, last_traceback=None, response=None):
response = {} if response is None else response
self.msg = msg
self.last_traceback = last_traceback
self.response = camel_dict_to_snake_dict(response)

View file

@ -473,7 +473,7 @@ class AzureRMModuleBase(object):
return None
def serialize_obj(self, obj, class_name, enum_modules=[]):
def serialize_obj(self, obj, class_name, enum_modules=None):
'''
Return a JSON representation of an Azure object.
@ -482,6 +482,8 @@ class AzureRMModuleBase(object):
:param enum_modules: List of module names to build enum dependencies from.
:return: serialized result
'''
enum_modules = [] if enum_modules is None else enum_modules
dependencies = dict()
if enum_modules:
for module_name in enum_modules:

View file

@ -2156,7 +2156,7 @@ class AnsibleModule(object):
# and we don't want to break modules unnecessarily
return None
def get_bin_path(self, arg, required=False, opt_dirs=[]):
def get_bin_path(self, arg, required=False, opt_dirs=None):
'''
find system executable in PATH.
Optional arguments:
@ -2164,6 +2164,8 @@ class AnsibleModule(object):
- opt_dirs: optional list of directories to search in addition to PATH
if found return full path; otherwise return None
'''
opt_dirs = [] if opt_dirs is None else opt_dirs
sbin_paths = ['/sbin', '/usr/sbin', '/usr/local/sbin']
paths = []
for d in opt_dirs:

View file

@ -120,9 +120,11 @@ class Cli:
return exec_command(self._module, command)
def get_config(self, flags=[]):
def get_config(self, flags=None):
"""Retrieves the current config from the device or cache
"""
flags = [] if flags is None else flags
cmd = 'display current-configuration '
cmd += ' '.join(flags)
cmd = cmd.strip()
@ -227,7 +229,9 @@ def to_command(module, commands):
return commands
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = [] if flags is None else flags
conn = get_connection(module)
return conn.get_config(flags)

View file

@ -68,7 +68,9 @@ def check_args(module, warnings):
'removed in a future version' % key)
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = [] if flags is None else flags
cmd = 'show running-config '
cmd += ' '.join(flags)
cmd = cmd.strip()

View file

@ -67,7 +67,9 @@ def check_args(module, warnings):
'removed in a future version' % key)
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = [] if flags is None else flags
cmd = 'show running-config '
cmd += ' '.join(flags)
cmd = cmd.strip()

View file

@ -68,7 +68,9 @@ def check_args(module, warnings):
'removed in a future version' % key)
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = [] if flags is None else flags
cmd = 'show running-config '
cmd += ' '.join(flags)
cmd = cmd.strip()

View file

@ -136,9 +136,11 @@ class Cli:
out = to_text(out, errors='surrogate_then_replace')
return out.endswith('#')
def get_config(self, flags=[]):
def get_config(self, flags=None):
"""Retrieves the current config from the device or cache
"""
flags = [] if flags is None else flags
cmd = 'show running-config '
cmd += ' '.join(flags)
cmd = cmd.strip()
@ -363,9 +365,11 @@ class Eapi:
return responses
def get_config(self, flags=[]):
def get_config(self, flags=None):
"""Retrieves the current config from the device or cache
"""
flags = [] if flags is None else flags
cmd = 'show running-config '
cmd += ' '.join(flags)
cmd = cmd.strip()
@ -457,7 +461,9 @@ def to_command(module, commands):
return transform(to_list(commands))
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = None if flags is None else flags
conn = get_connection(module)
return conn.get_config(flags)

View file

@ -295,7 +295,7 @@ def gcp_connect(module, provider, get_driver, user_agent_product, user_agent_ver
return gcp
def get_google_cloud_credentials(module, scopes=[]):
def get_google_cloud_credentials(module, scopes=None):
"""
Get credentials object for use with Google Cloud client.
@ -324,6 +324,8 @@ def get_google_cloud_credentials(module, scopes=[]):
params dict {'service_account_email': '...', 'credentials_file': '...', 'project_id': ...}
:rtype: ``tuple``
"""
scopes = [] if scopes is None else scopes
if not HAS_GOOGLE_AUTH:
module.fail_json(msg='Please install google-auth.')
@ -348,7 +350,7 @@ def get_google_cloud_credentials(module, scopes=[]):
return (None, None)
def get_google_api_auth(module, scopes=[], user_agent_product='ansible-python-api', user_agent_version='NA'):
def get_google_api_auth(module, scopes=None, user_agent_product='ansible-python-api', user_agent_version='NA'):
"""
Authentication for use with google-python-api-client.
@ -384,6 +386,8 @@ def get_google_api_auth(module, scopes=[], user_agent_product='ansible-python-ap
params dict {'service_account_email': '...', 'credentials_file': '...', 'project_id': ...}
:rtype: ``tuple``
"""
scopes = [] if scopes is None else scopes
if not HAS_GOOGLE_API_LIB:
module.fail_json(msg="Please install google-api-python-client library")
if not scopes:

View file

@ -77,7 +77,9 @@ def get_defaults_flag(module):
return ['full']
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = [] if flags is None else flags
cmd = 'show running-config '
cmd += ' '.join(flags)
cmd = cmd.strip()

View file

@ -61,7 +61,9 @@ def check_args(module, warnings):
warnings.append('argument %s has been deprecated and will be removed in a future version' % key)
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = [] if flags is None else flags
cmd = 'show running-config '
cmd += ' '.join(flags)
cmd = cmd.strip()

View file

@ -39,7 +39,11 @@ from ansible.module_utils._text import to_native
class ConfigProxy(object):
def __init__(self, actual, client, attribute_values_dict, readwrite_attrs, transforms={}, readonly_attrs=[], immutable_attrs=[], json_encodes=[]):
def __init__(self, actual, client, attribute_values_dict, readwrite_attrs, transforms=None, readonly_attrs=None, immutable_attrs=None, json_encodes=None):
transforms = {} if transforms is None else transforms
readonly_attrs = [] if readonly_attrs is None else readonly_attrs
immutable_attrs = [] if immutable_attrs is None else immutable_attrs
json_encodes = [] if json_encodes is None else json_encodes
# Actual config object from nitro sdk
self.actual = actual

View file

@ -91,7 +91,9 @@ class Entity(object):
* default - default value
"""
def __init__(self, module, attrs=None, args=[], keys=None, from_argspec=False):
def __init__(self, module, attrs=None, args=None, keys=None, from_argspec=False):
args = [] if args is None else args
self._attributes = attrs or {}
self._module = module

View file

@ -116,9 +116,11 @@ class Cli:
command = self._module.jsonify(command)
return exec_command(self._module, command)
def get_config(self, flags=[]):
def get_config(self, flags=None):
"""Retrieves the current config from the device or cache
"""
flags = [] if flags is None else []
cmd = 'show running-config '
cmd += ' '.join(flags)
cmd = cmd.strip()
@ -299,9 +301,11 @@ class Nxapi:
return result
def get_config(self, flags=[]):
def get_config(self, flags=None):
"""Retrieves the current config from the device or cache
"""
flags = [] if flags is None else flags
cmd = 'show running-config '
cmd += ' '.join(flags)
cmd = cmd.strip()
@ -385,7 +389,9 @@ def to_command(module, commands):
return commands
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = [] if flags is None else flags
conn = get_connection(module)
return conn.get_config(flags)

View file

@ -67,7 +67,7 @@ def transform_list_to_dict(list_):
return ret
def merge_list_by_key(original_list, updated_list, key, ignore_when_null=[]):
def merge_list_by_key(original_list, updated_list, key, ignore_when_null=None):
"""
Merge two lists by the key. It basically:
@ -84,6 +84,8 @@ def merge_list_by_key(original_list, updated_list, key, ignore_when_null=[]):
if its values are null.
:return: list: Lists merged.
"""
ignore_when_null = [] if ignore_when_null is None else ignore_when_null
if not original_list:
return updated_list

View file

@ -1,7 +1,9 @@
_DEVICE_CONFIGS = {}
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = [] if flags is None else flags
cmd = 'show running-config '
cmd += ' '.join(flags)
cmd = cmd.strip()

View file

@ -58,7 +58,9 @@ def check_args(module, warnings):
warnings.append('argument %s has been deprecated and will be removed in a future version' % key)
def get_config(module, flags=[]):
def get_config(module, flags=None):
flags = [] if flags is None else flags
cmd = 'admin display-config '
cmd += ' '.join(flags)
cmd = cmd.strip()

View file

@ -670,10 +670,12 @@ class SSLValidationHandler(urllib_request.BaseHandler):
to_add_path = None
return (tmp_path, to_add_path, paths_checked)
def validate_proxy_response(self, response, valid_codes=[200]):
def validate_proxy_response(self, response, valid_codes=None):
'''
make sure we get back a valid code from the proxy
'''
valid_codes = [200] if valid_codes is None else valid_codes
try:
(http_version, resp_code, msg) = re.match(r'(HTTP/\d\.\d) (\d\d\d) (.*)', response).groups()
if int(resp_code) not in valid_codes: