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 api: scan status and scan now #16

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
* [SCANNING](#scanning)
+ [Scan Artifact](#scan-artifact)
+ [Scan Build](#scan-build)
+ [Scan Status](#scan-status)
+ [Scan Now](#scan-now)
<!-- tocstop -->

# Install
Expand Down Expand Up @@ -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())
```
57 changes: 57 additions & 0 deletions xray/scanning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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