Skip to content

NIST URLs

netutils.nist

Classes and functions used for building NIST URLs from the os platform values.

OsPlatform

Base class for dynamically generated vendor specific platform data classes.

Source code in netutils/nist.py
class OsPlatform(metaclass=abc.ABCMeta):
    """Base class for dynamically generated vendor specific platform data classes."""

    def asdict(self) -> t.Dict[str, t.Any]:
        """Returns dictionary representation of the class attributes."""
        return dataclasses.asdict(self)  # type: ignore

    @abc.abstractmethod
    def get_nist_urls(self) -> t.List[str]:
        """Returns list of NIST URLs for the platform."""

    def get(self, key: str) -> t.Any:
        """Return value of the attribute matching provided name or None if no attribute is found."""
        return getattr(self, key, None)

    def keys(self) -> t.KeysView[t.Any]:
        """Return attributes and their values as dict keys."""
        # Disabling pylint no-member due to BUG: https://github.com/pylint-dev/pylint/issues/7126
        return self.__annotations__.keys()  # pylint: disable=no-member

    def __getitem__(self, key: str) -> t.Any:
        """Allow retrieving attributes using subscript notation."""
        return getattr(self, key)

__getitem__(key)

Allow retrieving attributes using subscript notation.

Source code in netutils/nist.py
def __getitem__(self, key: str) -> t.Any:
    """Allow retrieving attributes using subscript notation."""
    return getattr(self, key)

asdict()

Returns dictionary representation of the class attributes.

Source code in netutils/nist.py
def asdict(self) -> t.Dict[str, t.Any]:
    """Returns dictionary representation of the class attributes."""
    return dataclasses.asdict(self)  # type: ignore

get(key)

Return value of the attribute matching provided name or None if no attribute is found.

Source code in netutils/nist.py
def get(self, key: str) -> t.Any:
    """Return value of the attribute matching provided name or None if no attribute is found."""
    return getattr(self, key, None)

get_nist_urls() abstractmethod

Returns list of NIST URLs for the platform.

Source code in netutils/nist.py
@abc.abstractmethod
def get_nist_urls(self) -> t.List[str]:
    """Returns list of NIST URLs for the platform."""

keys()

Return attributes and their values as dict keys.

Source code in netutils/nist.py
def keys(self) -> t.KeysView[t.Any]:
    """Return attributes and their values as dict keys."""
    # Disabling pylint no-member due to BUG: https://github.com/pylint-dev/pylint/issues/7126
    return self.__annotations__.keys()  # pylint: disable=no-member

get_nist_urls(network_driver, version)

Generate list of possible NIST URLs for the Network Driver, and Version.

Parameters:

Name Type Description Default
network_driver str

Value of device network_driver (Ex: cisco_ios, arista_eos)

required
version str

OS Software Platform Version

required

Returns:

Type Description
List[str]

t.List[str]: NIST URLs to search for possible CVE matches

Examples:

>>> from netutils.nist import get_nist_urls
>>> get_nist_urls('cisco_ios', '15.3')
['https://services.nvd.nist.gov/rest/json/cves/2.0?cpeName=cpe:2.3:o:cisco:ios:15.3:*']
>>>
Source code in netutils/nist.py
def get_nist_urls(network_driver: str, version: str) -> t.List[str]:
    """Generate list of possible NIST URLs for the Network Driver, and Version.

    Args:
        network_driver (str): Value of device network_driver (Ex: cisco_ios, arista_eos)
        version (str): OS Software Platform Version

    Returns:
        t.List[str]: NIST URLs to search for possible CVE matches

    Examples:
        >>> from netutils.nist import get_nist_urls
        >>> get_nist_urls('cisco_ios', '15.3')
        ['https://services.nvd.nist.gov/rest/json/cves/2.0?cpeName=cpe:2.3:o:cisco:ios:15.3:*']
        >>>
    """
    # DICTIONARY FOR VENDOR/PLATFORM TO NETWORK_DRIVER; UPDATE AS NEEDED
    vendor_os: str = NIST_LIB_MAPPER_REVERSE.get(network_driver, "")
    if not vendor_os:
        raise ValueError(
            f"The network driver `{network_driver}` has no associated mapping, the supported drivers are {list(NIST_LIB_MAPPER_REVERSE.keys())}."
        )
    vendor, os_name = vendor_os.split(":")

    return get_nist_vendor_platform_urls(vendor, os_name, version)

get_nist_vendor_platform_urls(vendor, platform, version)

Generate list of possible NIST URLs for the Vendor, OS Platform, and Version.

Parameters:

Name Type Description Default
vendor str

OS Software Platform Vendor/Manufacturer

required
platform str

OS Software Platform Name

required
version str

OS Software Platform Version

required

Returns:

Type Description
List[str]

t.List[str]: NIST URLs to search for possible CVE matches

Examples:

>>> from netutils.nist import get_nist_vendor_platform_urls
>>> get_nist_vendor_platform_urls('cisco', 'ios', '15.3')
['https://services.nvd.nist.gov/rest/json/cves/2.0?cpeName=cpe:2.3:o:cisco:ios:15.3:*']
>>>
Source code in netutils/nist.py
def get_nist_vendor_platform_urls(vendor: str, platform: str, version: str) -> t.List[str]:
    """Generate list of possible NIST URLs for the Vendor, OS Platform, and Version.

    Args:
        vendor (str): OS Software Platform Vendor/Manufacturer
        platform (str): OS Software Platform Name
        version (str): OS Software Platform Version

    Returns:
        t.List[str]: NIST URLs to search for possible CVE matches

    Examples:
        >>> from netutils.nist import get_nist_vendor_platform_urls
        >>> get_nist_vendor_platform_urls('cisco', 'ios', '15.3')
        ['https://services.nvd.nist.gov/rest/json/cves/2.0?cpeName=cpe:2.3:o:cisco:ios:15.3:*']
        >>>
    """
    platform_data = _os_platform_object_builder(vendor, platform, version).__dict__

    if vendor.lower() == "juniper" and platform.lower() == "junos":
        return _get_nist_urls_juniper_junos(platform_data)
    return _get_nist_urls_default(platform_data)