ansible-collections / ibm_zos_core

Red Hat Ansible Certified Content for IBM Z
75 stars 44 forks source link

[Enabler] [module_utils] Special character support #1424

Closed fernandofloresg closed 2 months ago

fernandofloresg commented 3 months ago

Is there an existing issue for this?

Special character support for data set names will be added from the BetterArgParser by changing the _data_set_type and _data_set_or_path_type return value, currently those just returns the data set name as string, but new behavior is to add a dictionary as a return value.

dict(original_name=str(contents), parsed_name=escaped_contents)

That way, the modules will have to retrieve the new escaped named and the original user provided name inside the dictionary like:

Module utils uses of BetterArgParser

- Backup.py - use of "data_set" type
- Copy.py - use of "data_set" type
- Encode.py - use of "data_set" and "data_set_or_path" type.

Job.py. Uses it but won't be affected bc does not use a data set type validation.

try:
        parser = better_arg_parser.BetterArgParser(arg_def)
        parsed_args = parser.parse_args(module.params)
    except ValueError as err:
        module.fail_json(msg="Parameter verification failed", stderr=str(err))

    # Use the escaped name as src.
    src = parsed_args.get("src").get("parsed_name")
    # Use the old-name for error messages.
    _src = parsed_args.get("src").get("original_name")

Escaping special characters could be done via a new function inside the BetterArgParser. These are some of the special characters:

Special character support

Ansible module

BetterArgParser

fernandofloresg commented 2 months ago

closed as duplicated