Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a get_certificate filter for Cisco and other configurations that include special characters #116

Open
mundruid opened this issue May 24, 2022 · 4 comments

Comments

@mundruid
Copy link
Contributor

Environment

  • netutils version:

A get_certificates filter needs to be added for configurations that add special characters in their certificates, for example Cisco ios has a hidden tab character: https://napalm.readthedocs.io/en/latest/support/ios.html

Proposed Functionality

A filter get_certificate that takes as input a running configuration and extracts its certificates, similar to the following:

def get_certificate(
    configuration: str,
    platform: str,
) -> Optional[str]:
    """Extracts certificate from downloaded configuration with all the included special characters and intricacies of a cisco certificate.

    Args:
        configuration (str): Running configuration copied from device.
        platform (str): Device platform. Ex: ios, nxos etc.

        {{ config | get_certificate("ios")}}
        {{ "ios" | get_certificate }}

    Returns:
        str: Certificates.
    """
    # this function is Cisco specific, it can take a list of config commands or the name of a file
    # with cisco config, parse it and return a specific part based on a regex
    parse = CiscoConfParse(config=configuration, syntax=platform)
    crypto_trustpoint = parse.find_all_children("^crypto pki trustpoint")
    crypto_cert_chain = parse.find_all_children("^crypto pki certificate chain")
    if crypto_trustpoint or crypto_cert_chain:
        return "\n".join(["!"] + crypto_trustpoint + ["!"] + crypto_cert_chain + ["!"])

    return None

Use Case

This feature will be useful for config replacement and a simple diff of running and candidate configs that does not include special chars.

@itdependsnetworks
Copy link
Contributor

We try to avoid dependencies, any change we can do this without CiscoConfParse? Any dependency would be optional.

@jeffkala
Copy link
Collaborator

Docstring would also need an example section so the docs are auto generated properly.

@mundruid
Copy link
Contributor Author

We try to avoid dependencies, any change we can do this without CiscoConfParse? Any dependency would be optional.

I can implement something similar to CiscoConfParse from scratch. It would be specific to certificates. Would that be acceptable?

@itdependsnetworks
Copy link
Contributor

That would be great, that was kinda the point of #124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants