Esempio n. 1
0
def test_string_suboptions_as_string(argument_spec, module_parameters,
                                     extra_params, expected):
    extra_opts = {
        'subopt_dict': {
            'type': 'dict',
            'options': {
                'dict_subopt1': {
                    'no_log': True
                },
                'dict_subopt2': {},
            },
        },
    }

    result = set(('under', 'makeshift'))
    result.update(expected)
    assert result == list_no_log_values(argument_spec(extra_opts),
                                        module_parameters(extra_params))
def test_list_no_log_values(params):
    argument_spec = {
        'secret': {
            'type': 'str',
            'no_log': True
        },
        'other_secret': {
            'type': 'str',
            'no_log': True
        },
        'state': {
            'type': 'str'
        },
        'value': {
            'type': 'int'
        },
    }
    result = set(('undercookwovennativity', 'cautious-slate-makeshift'))
    assert result == list_no_log_values(argument_spec, params)
Esempio n. 3
0
    def _handle_no_log_values(self, spec=None, param=None):
        if spec is None:
            spec = self.argument_spec
        if param is None:
            param = self.params

        try:
            self.no_log_values.update(list_no_log_values(spec, param))
        except TypeError as te:
            self.fail_json(
                msg=
                "Failure when processing no_log parameters. Module invocation will be hidden. "
                "%s" % to_native(te),
                invocation={'module_args': 'HIDDEN DUE TO FAILURE'})

        for message in list_deprecations(spec, param):
            self.deprecate(message['msg'],
                           version=message.get('version'),
                           date=message.get('date'),
                           collection_name=message.get('collection_name'))
Esempio n. 4
0
def test_list_no_log_values_sub_suboptions(argument_spec, module_parameters):
    extra_opts = {
        'sub_level_1': {
            'type': 'dict',
            'options': {
                'l1_1': {
                    'no_log': True
                },
                'l1_2': {},
                'l1_3': {
                    'type': 'dict',
                    'options': {
                        'l2_1': {
                            'no_log': True
                        },
                        'l2_2': {},
                    }
                }
            }
        }
    }

    extra_params = {
        'sub_level_1': {
            'l1_1': 'saucy',
            'l1_2': 'napped',
            'l1_3': {
                'l2_1': 'corporate',
                'l2_2': 'tinsmith',
            }
        }
    }

    expected = set(('under', 'makeshift', 'saucy', 'corporate'))
    assert expected == list_no_log_values(argument_spec(extra_opts),
                                          module_parameters(extra_params))
 def validate_config(self, spec, data, redact=False):
     validated_data = _validate_config(spec, data)
     if redact:
         self._module.no_log_values.update(
             list_no_log_values(spec, validated_data))
     return validated_data
Esempio n. 6
0
def test_list_no_log_values(argument_spec, module_parameters):
    expected = set(('under', 'makeshift'))
    assert expected == list_no_log_values(argument_spec(), module_parameters())
Esempio n. 7
0
    def validate(self, *args, **kwargs):
        """Validate module parameters against argument spec.

        :Example:

        validator = ArgumentSpecValidator(argument_spec, parameters)
        passeded = validator.validate()

        :param argument_spec: Specification of parameters, type, and valid values
        :type argument_spec: dict

        :param parameters: Parameters provided to the role
        :type parameters: dict

        :returns: True if no errors were encountered, False if any errors were encountered.
        :rtype: bool
        """

        self._no_log_values.update(set_fallbacks(self.argument_spec, self._validated_parameters))

        alias_warnings = []
        alias_deprecations = []
        try:
            alias_results, legal_inputs = handle_aliases(self.argument_spec, self._validated_parameters, alias_warnings, alias_deprecations)
        except (TypeError, ValueError) as e:
            alias_results = {}
            legal_inputs = None
            self._add_error(to_native(e))

        for option, alias in alias_warnings:
            warn('Both option %s and its alias %s are set.' % (option, alias))

        for deprecation in alias_deprecations:
            deprecate("Alias '%s' is deprecated. See the module docs for more information" % deprecation['name'],
                      version=deprecation.get('version'), date=deprecation.get('date'),
                      collection_name=deprecation.get('collection_name'))

        self._no_log_values.update(list_no_log_values(self.argument_spec, self._validated_parameters))

        if legal_inputs is None:
            legal_inputs = list(alias_results.keys()) + list(self.argument_spec.keys())
        self._unsupported_parameters.update(get_unsupported_parameters(self.argument_spec, self._validated_parameters, legal_inputs))

        self._no_log_values.update(set_defaults(self.argument_spec, self._validated_parameters, False))

        try:
            check_required_arguments(self.argument_spec, self._validated_parameters)
        except TypeError as e:
            self._add_error(to_native(e))

        validate_argument_types(self.argument_spec, self._validated_parameters, errors=self._error_messages)
        validate_argument_values(self.argument_spec, self._validated_parameters, errors=self._error_messages)

        self._no_log_values.update(set_defaults(self.argument_spec, self._validated_parameters))

        validate_sub_spec(self.argument_spec, self._validated_parameters,
                          errors=self._error_messages,
                          no_log_values=self._no_log_values,
                          unsupported_parameters=self._unsupported_parameters)

        if self._unsupported_parameters:
            self._add_error('Unsupported parameters: %s' % ', '.join(sorted(list(self._unsupported_parameters))))

        self._sanitize_error_messages()

        if self.error_messages:
            return False
        else:
            return True