PaloAltoNetworks / panhandler

Panhandler is a tool to manage config snippets and Skillets for PAN-OS devices
Apache License 2.0
41 stars 19 forks source link

ability for python skillet to parse type=checkbox with cbx list #64

Closed scotchoaf closed 5 years ago

scotchoaf commented 5 years ago

The python skillet appears to only work with single value inputs as '--name value', name from the var section of the metadata file. Want to use a checkbox list model and var section parsing should be using each key/value pair in the list as '--key value' as an argument and ignore the name attribute.

cnc tasks.py likely should include: if type == 'checkbox' then: and parses the variables values differently than the text and other var types. Although not sure if the key (displayed value) is sent in as a value and value can be used as a variable key - no reversed?

https://github.com/PaloAltoNetworks/pan-cnc/blob/f3278ebbafe0ec312290568eab6173013b5a54f5/pan_cnc/tasks.py#L265

from def python3_execute_script:

    for k, v in args.items():
        if input_type == 'env':
            env[k] = v
        else:
            cmd_seq.append(f'--{k}={v}')
scotchoaf commented 5 years ago

Testing more the python parsing is now showing the value but only a single value, last in the list, so perhaps a checkbox list issue. This could be useful if the code filters based on checkbox=True for each item in the list and then creates the arg --name=value where the name is the var name.

Looks like in the python code you can use:

    parser.add_argument("--security_rules", action='append')

and this will create a list to send into python code with the values from the checked items in the list.

Use Case: I have a script to get all of the security rules from the firewall and would be able to feed this into a second .meta-cnc.yaml file var section to generate the checkbox list for second skillet that adds data (eg. zone, profile-group, tag...) to the set of rules.

nembery commented 5 years ago

@scotchoaf example python script to handle list type input args is here. let me know if this works for your use case: https://github.com/nembery/Skillets/tree/experimental/skillets_by_type/python/input_args

nembery commented 5 years ago

this was implemented using csv delimited env or cli args