diff --git a/README.md b/README.md index 4a1bc57..d9d4669 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ * [SCANNING](#scanning) + [Scan Artifact](#scan-artifact) + [Scan Build](#scan-build) + + [Scan Status](#scan-status) + + [Scan Now](#scan-now) # Install @@ -225,3 +227,33 @@ response = scanning.scan_build("build_name", "build_number") response = scanning.scan_build("build_name", "build_number", api_version='v2') print(response.json()) ``` + +### Scan Status +```python +from xray.common import PackageType +scanning = xray_rest_client.scanning +# get scan status for artifact +response = scanning.get_scan_status_for_artifact( + PackageType.NPM.value, + 'npm-local/static-module-3.0.4.tar.gz', + 'b0a887f6e5c16134b7d1280c2150d38811357642d56c622c6f7f6b239f668608' +) +print(response.json()) +# get scan status for build +scanning = xray_rest_client.scanning +response = scanning.get_scan_status_for_build("test-build", "1") +print(response.json()) +# get scan status for build with project +scanning = xray_rest_client.scanning +response = scanning.get_scan_status_for_build("test-build", "1", project="proj1") +print(response.json()) +``` + +### Scan Now +```python +from xray.common import PackageType +scanning = xray_rest_client.scanning +# scan now +response = scanning.scan_now("local-maven-repo/org/jenkins-ci/main/jenkins-war/2.289.1/jenkins-war-2.289.1.war") +print(response.json()) +``` \ No newline at end of file diff --git a/xray/scanning.py b/xray/scanning.py index ce0760f..52d56e1 100644 --- a/xray/scanning.py +++ b/xray/scanning.py @@ -55,3 +55,60 @@ def scan_build(self, build_name, build_number, api_version='v1'): json_data=json_data ) return response + + def get_scan_status_for_artifact(self, repository_pkg_type, path, sha256): + """ + Get scan status for artifact + :param repository_pkg_type: + :param path: + :param sha256: + :return: + """ + url = self.base_url + "/api/v1/scan/status/artifact" + json_data = { + "repository_pkg_type": repository_pkg_type, + "path": path, + "sha256": sha256, + } + response = self.rest_post( + url, + json_data=json_data + ) + return response + + def get_scan_status_for_build(self, name, version, project=None): + """ + Get scan status for build + :param name: + :param version: + :param project: + :return: + """ + url = self.base_url + "/api/v1/scan/status/build" + json_data = { + "name": name, + "version": version, + } + if project is not None: + json_data['project'] = project + response = self.rest_post( + url, + json_data=json_data + ) + return response + + def scan_now(self, path): + """ + Enables you to index resources on-demand, even those that were not marked for indexing + :param path: + :return: + """ + url = self.base_url + "/api/v2/index" + json_data = { + "repo_path": path + } + response = self.rest_post( + url, + json_data=json_data + ) + return response