Source code for laceworksdk.api.v2.vulnerability_exceptions

# -*- coding: utf-8 -*-
"""Lacework VulnerabilityExceptions API wrapper."""

from laceworksdk.api.crud_endpoint import CrudEndpoint


[docs] class VulnerabilityExceptionsAPI(CrudEndpoint): """A class used to represent the `Vulnerabilities Exceptions API endpoint <https://docs.lacework.net/api/v2/docs/#tag/VulnerabilityExceptions>`_ . Lacework provides the ability to create exceptions for certain vulnerable resources and criteria. For example, a \ certain CVE for a certain package or all packages can be excepted until a set expiry time. """ def __init__(self, session): """Initializes the VulnerabilityExceptionsAPI object. Args: session (HttpSession): An instance of the HttpSession class Returns: VulnerabilityExceptionsAPI: An instance of this class """ super().__init__(session, "VulnerabilityExceptions")
[docs] def create( self, exception_name, exception_reason, exception_type, props, vulnerability_criteria, resource_scope=None, expiry_time=None, state=True, **request_params, ): """A method to create a new vulnerability exception. Args: exception_name (str): The name of the exception. exception_reason (str): The exception reason. Valid values: "False Positive", "Accepted Risk", \ "Compensating Controls", "Fix Pending", "Other" exception_type (str): The exception type. Valid values: "Container", "Host" props (dict of str): The properties of the exception. Fields are:\ - description (str): The exception description - createdBy (str): The creator of the exception - updatedBy (str): The updator of the exception. vulnerability_criteria (dic): The criteria for excepted vulnerabilities. Fields are: - cve (list of str): The vulnerability (CVE) ID(s) that you want to constrain the exception to - package (list of dict): The package name(s) (for example, an operating system or language package). \ This can include a version number - severity (list of str): The severity levels of the vulnerability to constrain the exception to. \ Valid values: "Info", "Low", "Medium", "High", "Critical" - fixable (list of int): The fixability status (0 or 1) resource_scope (dict): The scope of resources for which to apply the exception. Fields for this dict change \ depending on the "exception type" field. See the `API docs <https://docs.lacework.net/api/v2/docs/#tag/VulnerabilityExceptions/paths/~1api~1v2~1VulnerabilityExceptions/post>`_ \ for field info. expiry_time (str): The expiration time for the exception. state (bool|int): Whether the exception is enabled. request_params (dict, optional): Use to pass any additional parameters the API Returns: dict: The newly created vulnerability exception """ return super().create( exception_name=exception_name, exception_reason=exception_reason, exception_type=exception_type, props=props, vulnerability_criteria=vulnerability_criteria, resource_scope=resource_scope, expiry_time=expiry_time, state=int(bool(state)), **request_params, )
[docs] def get(self, guid=None): """A method to get vulnerability exceptions. Using no args will get all vulnerability exceptions. Args: guid (str, optional): The GUID of the vulnerability exception to get. Returns: dict: The requested vulnerability exception(s) """ return super().get(id=guid)
[docs] def get_by_guid(self, guid): """A method to get vulnerability exceptions by GUID. Args: guid (str): The GUID of the vulnerability exception to get. Returns: dict: The requested vulnerability exception(s) """ return self.get(guid=guid)
[docs] def update( self, guid, exception_name=None, exception_reason=None, props=None, vulnerability_criteria=None, resource_scope=None, expiry_time=None, state=None, **request_params, ): """A method to update a VulnerabilityExceptions object. Args: guid: A string representing the object GUID. exception_name (str, optional): The name of the exception. exception_reason (str, optional): The exception reason. Valid values: "False Positive", "Accepted Risk", \ "Compensating Controls", "Fix Pending", "Other" props (dict of str): The properties of the exception. Fields are:\ - description (str, optional): The exception description - createdBy (str, optional): The creator of the exception - updatedBy (str, optional): The updator of the exception. vulnerability_criteria (dic): The criteria for excepted vulnerabilities. Fields are: - cve (list of str): The vulnerability (CVE) ID(s) that you want to constrain the exception to - package (list of dict): The package name(s) (for example, an operating system or language package). \ This can include a version number - severity (list of str): The severity levels of the vulnerability to constrain the exception to. \ Valid values: "Info", "Low", "Medium", "High", "Critical" - fixable (list of int): The fixability status (0 or 1) resource_scope (dict, optional): The scope of resources for which to apply the exception. Fields for this dict \ change depending on the "exception type" field. See the `API docs <https://docs.lacework.net/api/v2/docs/#tag/VulnerabilityExceptions/paths/~1api~1v2~1VulnerabilityExceptions~1%7BexceptionGuid%7D/patch>`_ \ for field info. expiry_time (str, optional): The expiration time for the exception. state (bool|int, optional): Whether the exception is enabled. request_params (dict, optional): Use to pass any additional parameters the API Returns: dict: The updated vulnerability exception """ if state is not None: state = int(bool(state)) return super().update( id=guid, exception_name=exception_name, exception_reason=exception_reason, props=props, vulnerability_criteria=vulnerability_criteria, resource_scope=resource_scope, expiry_time=expiry_time, state=state, **request_params, )
[docs] def delete(self, guid): """A method to delete a vulnerability exception. Args: guid (str): The GUID of the vulnerability exception to delete Returns: requests.models.Response: a Requests response object containing the response code """ return super().delete(id=guid)