How to use the sshpubkeys.exceptions.MissingMandatoryOptionValueError function in sshpubkeys

To help you get started, we’ve selected a few sshpubkeys examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ojarva / python-sshpubkeys / tests / invalid_options.py View on Github external
UnknownOptionNameError)

options = [
    ["includes_space", "no-user-rc ", InvalidOptionsError],
    ["includes_space_multiple", "no-user-rc, port-forwarding", InvalidOptionsError],
    ["includes_space_before_comma", "no-user-rc ,port-forwarding", InvalidOptionsError],
    ["empty_option_end", "no-user-rc,", InvalidOptionsError],
    ["empty_option_beginning", ",no-user-rc", InvalidOptionsError],
    ["empty_option_middle", "no-user-rc,,port-forwarding", InvalidOptionsError],
    ["unbalanced_quotes", 'from="asdf', InvalidOptionsError],
    ["invalid_characters_in_key_percent", 'from%', InvalidOptionNameError],
    ["invalid_characters_in_key_parenthesis", 'from)', InvalidOptionNameError],
    ["invalid_characters_in_key_space", 'fr om', InvalidOptionNameError],
    ["unknown_option_name", "random-option-name", UnknownOptionNameError],
    ["unbalanced_quotes_complex", 'from="asdf",no-user-rc"', InvalidOptionsError],
    ["parameter_missing", 'from,no-user-rc"', MissingMandatoryOptionValueError],
]
github ojarva / python-sshpubkeys / sshpubkeys / keys.py View on Github external
def parse_add_single_option(opt):
            """Parses and validates a single option, and adds it to parsed_options field."""
            if "=" in opt:
                opt_name, opt_value = opt.split("=", 1)
                opt_value = opt_value.replace('"', '')
            else:
                opt_name = opt
                opt_value = True
            if " " in opt_name or not self.OPTION_NAME_RE.match(opt_name):
                raise InvalidOptionNameError("%s is not valid option name." % opt_name)
            if self.strict_mode:
                for valid_opt_name, value_required in self.OPTIONS_SPEC:
                    if opt_name.lower() == valid_opt_name:
                        if value_required and opt_value is True:
                            raise MissingMandatoryOptionValueError("%s is missing mandatory value." % opt_name)
                        break
                else:
                    raise UnknownOptionNameError("%s is unrecognized option name." % opt_name)
            if opt_name not in parsed_options:
                parsed_options[opt_name] = []
            parsed_options[opt_name].append(opt_value)