laceworksdk.api.v2.vulnerabilities
Lacework Vulnerabilities API wrapper.
1# -*- coding: utf-8 -*- 2""" 3Lacework Vulnerabilities API wrapper. 4""" 5 6from laceworksdk.api.base_endpoint import BaseEndpoint 7from laceworksdk.api.search_endpoint import SearchEndpoint 8from laceworksdk.api.v1.vulnerability import VulnerabilityAPI 9 10 11class VulnerabilitiesAPI(VulnerabilityAPI): 12 """A class used to represent the Vulnerabilities API endpoint. 13 14 The Vulnerabilities API endpoint is simply a parent for different types of 15 vulnerabilities that can be queried. Due to namespace overlap with the v1 16 API, this class is a subclass of VulnerabilityAPI to expose those methods 17 and provide backwards compatibility. 18 19 Attributes 20 ---------- 21 containers: 22 A ContainerVulnerabilitiesAPI instance. 23 hosts: 24 A HostVulnerabilitiesAPI instance. 25 packages: 26 A SoftwarePackagesAPI instance. 27 """ 28 29 def __init__(self, session): 30 """ 31 Initializes the VulnerabilitiesAPI object. 32 33 :param session: An instance of the HttpSession class 34 35 :return VulnerabilitiesAPI object. 36 """ 37 38 super().__init__(session) 39 self._base_path = "Vulnerabilities" 40 41 self.containers = ContainerVulnerabilitiesAPI(session, self._base_path) 42 self.hosts = HostVulnerabilitiesAPI(session, self._base_path) 43 self.packages = SoftwarePackagesAPI(session, self._base_path) 44 45 46class ContainerVulnerabilitiesAPI(SearchEndpoint): 47 """A class used to represent the Container Vulnerabilities API endpoint. 48 49 Methods 50 ------- 51 search(json=None) 52 A method to search Container Vulnerabilities objects. 53 scan(registry, repository, tag, **request_params) 54 A method to issue a Container Vulnerability scan. 55 status(request_id) 56 A method to get the status of a Container Vulnerability scan. 57 """ 58 RESOURCE = "Containers" 59 60 def scan(self, 61 registry, 62 repository, 63 tag, 64 **request_params): 65 """ 66 A method to issue Container Vulnerability scans. 67 68 :param registry: A string representing the container registry to use. 69 :param repository: A string representing the container repository to use. 70 :param tag: A string representing the container tag to use. 71 :param request_params: Additional request parameters. 72 (provides support for parameters that may be added in the future) 73 74 :return response json 75 """ 76 77 json = self.build_dict_from_items( 78 **request_params, 79 registry=registry, 80 repository=repository, 81 tag=tag 82 ) 83 84 response = self._session.post(self.build_url(resource="Containers", action="scan"), json=json) 85 86 return response.json() 87 88 def status(self, 89 request_id): 90 """ 91 A method to get the status of a Container Vulnerability scan. 92 93 :param rquest_id: A string representing the request ID of the container scan. 94 95 :return response json 96 """ 97 98 if request_id is None or len(request_id) == 0: 99 raise ValueError("The value 'request_id' must be a valid container scan request ID.") 100 101 response = self._session.get(self.build_url(id=request_id, resource="Containers", action="scan")) 102 103 return response.json() 104 105 106class HostVulnerabilitiesAPI(SearchEndpoint): 107 """A class used to represent the Host Vulnerabilities API endpoint. 108 109 Methods 110 ------- 111 search(json=None) 112 A method to search Host Vulnerabilities objects. 113 """ 114 RESOURCE = "Hosts" 115 116 117class SoftwarePackagesAPI(BaseEndpoint): 118 """A class used to represent the Software Packages API endpoint. 119 120 Methods 121 ------- 122 scan(os_pkg_info_list, **request_params) 123 A method to initiate a Software Package vulnerability scan. 124 """ 125 126 def scan(self, 127 os_pkg_info_list, 128 **request_params): 129 """ 130 A method to initiate a software package vulnerability scan. 131 132 :param os_pkg_info_list: A list of packages to be scanned given the OS, OS Version, Package, and Package Version. 133 :obj 134 :param os: A string representing the name of the operating system. 135 :param osVer: A string representing the version of the operating system. 136 :param pkg: A string representing the name of the software package. 137 :param pkgVer: A string representing the verion of the software package. 138 :param request_params: Additional request parameters. 139 (provides support for parameters that may be added in the future) 140 141 :return: response json 142 """ 143 144 json = self.build_dict_from_items( 145 **request_params, 146 os_pkg_info_list=os_pkg_info_list 147 ) 148 149 response = self._session.post(self.build_url(resource="SoftwarePackages", action="scan"), json=json) 150 151 return response.json()
12class VulnerabilitiesAPI(VulnerabilityAPI): 13 """A class used to represent the Vulnerabilities API endpoint. 14 15 The Vulnerabilities API endpoint is simply a parent for different types of 16 vulnerabilities that can be queried. Due to namespace overlap with the v1 17 API, this class is a subclass of VulnerabilityAPI to expose those methods 18 and provide backwards compatibility. 19 20 Attributes 21 ---------- 22 containers: 23 A ContainerVulnerabilitiesAPI instance. 24 hosts: 25 A HostVulnerabilitiesAPI instance. 26 packages: 27 A SoftwarePackagesAPI instance. 28 """ 29 30 def __init__(self, session): 31 """ 32 Initializes the VulnerabilitiesAPI object. 33 34 :param session: An instance of the HttpSession class 35 36 :return VulnerabilitiesAPI object. 37 """ 38 39 super().__init__(session) 40 self._base_path = "Vulnerabilities" 41 42 self.containers = ContainerVulnerabilitiesAPI(session, self._base_path) 43 self.hosts = HostVulnerabilitiesAPI(session, self._base_path) 44 self.packages = SoftwarePackagesAPI(session, self._base_path)
A class used to represent the Vulnerabilities API endpoint.
The Vulnerabilities API endpoint is simply a parent for different types of vulnerabilities that can be queried. Due to namespace overlap with the v1 API, this class is a subclass of VulnerabilityAPI to expose those methods and provide backwards compatibility.
Attributes
containers: A ContainerVulnerabilitiesAPI instance. hosts: A HostVulnerabilitiesAPI instance. packages: A SoftwarePackagesAPI instance.
30 def __init__(self, session): 31 """ 32 Initializes the VulnerabilitiesAPI object. 33 34 :param session: An instance of the HttpSession class 35 36 :return VulnerabilitiesAPI object. 37 """ 38 39 super().__init__(session) 40 self._base_path = "Vulnerabilities" 41 42 self.containers = ContainerVulnerabilitiesAPI(session, self._base_path) 43 self.hosts = HostVulnerabilitiesAPI(session, self._base_path) 44 self.packages = SoftwarePackagesAPI(session, self._base_path)
Initializes the VulnerabilitiesAPI object.
Parameters
- session: An instance of the HttpSession class
:return VulnerabilitiesAPI object.
47class ContainerVulnerabilitiesAPI(SearchEndpoint): 48 """A class used to represent the Container Vulnerabilities API endpoint. 49 50 Methods 51 ------- 52 search(json=None) 53 A method to search Container Vulnerabilities objects. 54 scan(registry, repository, tag, **request_params) 55 A method to issue a Container Vulnerability scan. 56 status(request_id) 57 A method to get the status of a Container Vulnerability scan. 58 """ 59 RESOURCE = "Containers" 60 61 def scan(self, 62 registry, 63 repository, 64 tag, 65 **request_params): 66 """ 67 A method to issue Container Vulnerability scans. 68 69 :param registry: A string representing the container registry to use. 70 :param repository: A string representing the container repository to use. 71 :param tag: A string representing the container tag to use. 72 :param request_params: Additional request parameters. 73 (provides support for parameters that may be added in the future) 74 75 :return response json 76 """ 77 78 json = self.build_dict_from_items( 79 **request_params, 80 registry=registry, 81 repository=repository, 82 tag=tag 83 ) 84 85 response = self._session.post(self.build_url(resource="Containers", action="scan"), json=json) 86 87 return response.json() 88 89 def status(self, 90 request_id): 91 """ 92 A method to get the status of a Container Vulnerability scan. 93 94 :param rquest_id: A string representing the request ID of the container scan. 95 96 :return response json 97 """ 98 99 if request_id is None or len(request_id) == 0: 100 raise ValueError("The value 'request_id' must be a valid container scan request ID.") 101 102 response = self._session.get(self.build_url(id=request_id, resource="Containers", action="scan")) 103 104 return response.json()
A class used to represent the Container Vulnerabilities API endpoint.
Methods
search(json=None) A method to search Container Vulnerabilities objects. scan(registry, repository, tag, **request_params) A method to issue a Container Vulnerability scan. status(request_id) A method to get the status of a Container Vulnerability scan.
61 def scan(self, 62 registry, 63 repository, 64 tag, 65 **request_params): 66 """ 67 A method to issue Container Vulnerability scans. 68 69 :param registry: A string representing the container registry to use. 70 :param repository: A string representing the container repository to use. 71 :param tag: A string representing the container tag to use. 72 :param request_params: Additional request parameters. 73 (provides support for parameters that may be added in the future) 74 75 :return response json 76 """ 77 78 json = self.build_dict_from_items( 79 **request_params, 80 registry=registry, 81 repository=repository, 82 tag=tag 83 ) 84 85 response = self._session.post(self.build_url(resource="Containers", action="scan"), json=json) 86 87 return response.json()
A method to issue Container Vulnerability scans.
Parameters
- registry: A string representing the container registry to use.
- repository: A string representing the container repository to use.
- tag: A string representing the container tag to use.
- request_params: Additional request parameters. (provides support for parameters that may be added in the future)
:return response json
89 def status(self, 90 request_id): 91 """ 92 A method to get the status of a Container Vulnerability scan. 93 94 :param rquest_id: A string representing the request ID of the container scan. 95 96 :return response json 97 """ 98 99 if request_id is None or len(request_id) == 0: 100 raise ValueError("The value 'request_id' must be a valid container scan request ID.") 101 102 response = self._session.get(self.build_url(id=request_id, resource="Containers", action="scan")) 103 104 return response.json()
A method to get the status of a Container Vulnerability scan.
Parameters
- rquest_id: A string representing the request ID of the container scan.
:return response json
107class HostVulnerabilitiesAPI(SearchEndpoint): 108 """A class used to represent the Host Vulnerabilities API endpoint. 109 110 Methods 111 ------- 112 search(json=None) 113 A method to search Host Vulnerabilities objects. 114 """ 115 RESOURCE = "Hosts"
A class used to represent the Host Vulnerabilities API endpoint.
Methods
search(json=None) A method to search Host Vulnerabilities objects.
118class SoftwarePackagesAPI(BaseEndpoint): 119 """A class used to represent the Software Packages API endpoint. 120 121 Methods 122 ------- 123 scan(os_pkg_info_list, **request_params) 124 A method to initiate a Software Package vulnerability scan. 125 """ 126 127 def scan(self, 128 os_pkg_info_list, 129 **request_params): 130 """ 131 A method to initiate a software package vulnerability scan. 132 133 :param os_pkg_info_list: A list of packages to be scanned given the OS, OS Version, Package, and Package Version. 134 :obj 135 :param os: A string representing the name of the operating system. 136 :param osVer: A string representing the version of the operating system. 137 :param pkg: A string representing the name of the software package. 138 :param pkgVer: A string representing the verion of the software package. 139 :param request_params: Additional request parameters. 140 (provides support for parameters that may be added in the future) 141 142 :return: response json 143 """ 144 145 json = self.build_dict_from_items( 146 **request_params, 147 os_pkg_info_list=os_pkg_info_list 148 ) 149 150 response = self._session.post(self.build_url(resource="SoftwarePackages", action="scan"), json=json) 151 152 return response.json()
A class used to represent the Software Packages API endpoint.
Methods
scan(os_pkg_info_list, **request_params) A method to initiate a Software Package vulnerability scan.
127 def scan(self, 128 os_pkg_info_list, 129 **request_params): 130 """ 131 A method to initiate a software package vulnerability scan. 132 133 :param os_pkg_info_list: A list of packages to be scanned given the OS, OS Version, Package, and Package Version. 134 :obj 135 :param os: A string representing the name of the operating system. 136 :param osVer: A string representing the version of the operating system. 137 :param pkg: A string representing the name of the software package. 138 :param pkgVer: A string representing the verion of the software package. 139 :param request_params: Additional request parameters. 140 (provides support for parameters that may be added in the future) 141 142 :return: response json 143 """ 144 145 json = self.build_dict_from_items( 146 **request_params, 147 os_pkg_info_list=os_pkg_info_list 148 ) 149 150 response = self._session.post(self.build_url(resource="SoftwarePackages", action="scan"), json=json) 151 152 return response.json()
A method to initiate a software package vulnerability scan.
Parameters
- os_pkg_info_list: A list of packages to be scanned given the OS, OS Version, Package, and Package Version. :obj :param os: A string representing the name of the operating system. :param osVer: A string representing the version of the operating system. :param pkg: A string representing the name of the software package. :param pkgVer: A string representing the verion of the software package.
- request_params: Additional request parameters. (provides support for parameters that may be added in the future)
Returns
response json