mend-reporting-tool 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mend-reporting-tool might be problematic. Click here for more details.

@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.4
2
+ Name: mend-reporting-tool
3
+ Version: 0.1.0
4
+ Summary: This is script to generate reports through Mend API v3.0
5
+ Maintainer-email: Alexander Chelyshev <alexchelyshev@gmail.com>
6
+ Requires-Python: >=3.12
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: requests>=2.33.1
9
+
10
+ # Mend Report Generation tool
11
+ This is script to generate reports through [Mend API v3.0](https://api-docs.mend.io/platform/3.0).
12
+
13
+ ### How To Use
14
+ ```shell
15
+ $ mend-reporting-tool -h
16
+ usage: mend-reporting-tool [-h] -mendAPI MENDAPI -orgUUID ORGUUID -userEmail USEREMAIL -userKey USERKEY -projectUUID PROJECTUUID
17
+ [-reportType REPORTTYPE] [-format FORMAT] [-unzip UNZIP]
18
+
19
+ This is script to generate reports through Mend API v3.0.
20
+
21
+ options:
22
+ -h, --help show this help message and exit
23
+ -mendAPI MENDAPI Mend API v3.0 server hostname without https://, like `api-saas.whitesourcesoftware.com`
24
+ -orgUUID ORGUUID Organization UUID
25
+ -userEmail USEREMAIL User Email
26
+ -userKey USERKEY User Key
27
+ -projectUUID PROJECTUUID
28
+ List of Project UUIDs separeted by ','
29
+ -reportType REPORTTYPE
30
+ Report Type, for example: `vulnerabilities`, `sbom`, `spdx`, `spdx_2_3`, `cycloneDX`, `cycloneDX_1_5`,
31
+ `cycloneDX_1_6`. The `vulnerabilities` report type generates vulnerability report. The `sbom` report type generates
32
+ `spdx` format. Optional, default: `sbom`
33
+ -format FORMAT Report Format, acceptable formats for `vulnerabilities` reportType: `json`, `excel`; for `sbom` reportType: `json`,
34
+ `yaml`. Optional, default: `json`
35
+ -unzip UNZIP Extract report to the 'mend-reports' folder. Variants: yes, no. Optional, default: `no`
36
+
37
+ ### Example:
38
+ mend-reporting-tool -mendAPI $MEND_API -orgUUID $MEND_ORGANIZATION_UUID -userEmail $MEND_EMAIL -userKey $MEND_USER_KEY -projectUUID $PROJECT_UUID -reportType sbom -format yaml -unzip yes
39
+
40
+ ### Processing Project UUID: <Project_UUID>
41
+ >>> The report saved to 'report-<Project_UUID>.zip' successfully.
42
+ >>> The report 'report-<Project_UUID>.zip' extracted to 'mend-reports' folder.
43
+ >>> Deleted: report-<Project_UUID>.zip
44
+ >>> Report is ready in `mend-reports` folder.
45
+ ...
46
+
47
+ # Content of `mend-reports` folder:
48
+ $ ls -l mend-reports/
49
+ -rw-r--r-- 1 alex alex 1033049 Apr 20 23:50 '<Project_Name>-project-SPDX-reportyaml'
50
+ ```
51
+
52
+ ### How To Install locally from source code
53
+ ```shell
54
+ python3 -m venv .venv
55
+ source .venv/bin/activate
56
+ pip install -e .
57
+ ```
58
+
@@ -0,0 +1,49 @@
1
+ # Mend Report Generation tool
2
+ This is script to generate reports through [Mend API v3.0](https://api-docs.mend.io/platform/3.0).
3
+
4
+ ### How To Use
5
+ ```shell
6
+ $ mend-reporting-tool -h
7
+ usage: mend-reporting-tool [-h] -mendAPI MENDAPI -orgUUID ORGUUID -userEmail USEREMAIL -userKey USERKEY -projectUUID PROJECTUUID
8
+ [-reportType REPORTTYPE] [-format FORMAT] [-unzip UNZIP]
9
+
10
+ This is script to generate reports through Mend API v3.0.
11
+
12
+ options:
13
+ -h, --help show this help message and exit
14
+ -mendAPI MENDAPI Mend API v3.0 server hostname without https://, like `api-saas.whitesourcesoftware.com`
15
+ -orgUUID ORGUUID Organization UUID
16
+ -userEmail USEREMAIL User Email
17
+ -userKey USERKEY User Key
18
+ -projectUUID PROJECTUUID
19
+ List of Project UUIDs separeted by ','
20
+ -reportType REPORTTYPE
21
+ Report Type, for example: `vulnerabilities`, `sbom`, `spdx`, `spdx_2_3`, `cycloneDX`, `cycloneDX_1_5`,
22
+ `cycloneDX_1_6`. The `vulnerabilities` report type generates vulnerability report. The `sbom` report type generates
23
+ `spdx` format. Optional, default: `sbom`
24
+ -format FORMAT Report Format, acceptable formats for `vulnerabilities` reportType: `json`, `excel`; for `sbom` reportType: `json`,
25
+ `yaml`. Optional, default: `json`
26
+ -unzip UNZIP Extract report to the 'mend-reports' folder. Variants: yes, no. Optional, default: `no`
27
+
28
+ ### Example:
29
+ mend-reporting-tool -mendAPI $MEND_API -orgUUID $MEND_ORGANIZATION_UUID -userEmail $MEND_EMAIL -userKey $MEND_USER_KEY -projectUUID $PROJECT_UUID -reportType sbom -format yaml -unzip yes
30
+
31
+ ### Processing Project UUID: <Project_UUID>
32
+ >>> The report saved to 'report-<Project_UUID>.zip' successfully.
33
+ >>> The report 'report-<Project_UUID>.zip' extracted to 'mend-reports' folder.
34
+ >>> Deleted: report-<Project_UUID>.zip
35
+ >>> Report is ready in `mend-reports` folder.
36
+ ...
37
+
38
+ # Content of `mend-reports` folder:
39
+ $ ls -l mend-reports/
40
+ -rw-r--r-- 1 alex alex 1033049 Apr 20 23:50 '<Project_Name>-project-SPDX-reportyaml'
41
+ ```
42
+
43
+ ### How To Install locally from source code
44
+ ```shell
45
+ python3 -m venv .venv
46
+ source .venv/bin/activate
47
+ pip install -e .
48
+ ```
49
+
@@ -0,0 +1,14 @@
1
+ [project]
2
+ name = "mend-reporting-tool"
3
+ version = "0.1.0"
4
+ description = "This is script to generate reports through Mend API v3.0"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ maintainers = [
8
+ {name = "Alexander Chelyshev", email = "alexchelyshev@gmail.com"}
9
+ ]
10
+ dependencies = [
11
+ "requests>=2.33.1",
12
+ ]
13
+ [project.scripts]
14
+ mend-reporting-tool = "mend_reporting_tool.main:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ if __name__ == "__main__":
2
+ from .main import main
3
+ main()
@@ -0,0 +1,179 @@
1
+ from time import sleep
2
+
3
+ import requests
4
+ import argparse
5
+ import zipfile
6
+ import os
7
+ import sys
8
+
9
+
10
+ def getRefreshToken(baseURL, email, userKey):
11
+ url = "https://"+baseURL+"/api/v3.0/login"
12
+
13
+ payload = {
14
+ "email": email,
15
+ "userKey": userKey
16
+ }
17
+
18
+ headers = {
19
+ "Content-Type": "application/json"
20
+ }
21
+
22
+ response = requests.post(url, json=payload, headers=headers)
23
+
24
+ data = response.json()
25
+ return data["response"]["refreshToken"]
26
+
27
+ def getAccessToken(baseURL, refreshToken):
28
+ url = "https://"+baseURL+"/api/v3.0/login/accessToken"
29
+
30
+ payload = {}
31
+
32
+ headers = {
33
+ "Content-Type": "application/json",
34
+ "wss-refresh-token": refreshToken
35
+ }
36
+
37
+ response = requests.post(url, json=payload, headers=headers)
38
+
39
+ data = response.json()
40
+ return data["response"]["jwtToken"]
41
+
42
+ def generateSBOM(baseURL, projectUUID, reportType, reportFormat, accessToken):
43
+ url = "https://"+baseURL+"/api/v3.0/projects/"+projectUUID+"/dependencies/reports/SBOM"
44
+
45
+ payload = {
46
+ "name": "SCA_report-"+reportType,
47
+ "format": reportFormat,
48
+ "sendEmailNotification": False,
49
+ "labelsUuidList": [],
50
+ "excludeInactiveProjects": True,
51
+ "reportType": reportType,
52
+ "maxDepthLevel": 1,
53
+ "includeVulnerabilities": True,
54
+ "isMlBomReport": True
55
+ }
56
+
57
+ authHeader = 'Bearer ' + accessToken
58
+ headers = {
59
+ "Content-Type": "application/json",
60
+ "Authorization": authHeader
61
+ }
62
+
63
+ response = requests.post(url, json=payload, headers=headers)
64
+
65
+ data = response.json()
66
+ return data["response"]["uuid"]
67
+
68
+ def checkReportStatus(baseURL, orgUuid, reportUUID, accessToken):
69
+ url = "https://"+baseURL+"/api/v3.0/orgs/"+orgUuid+"/reports/"+reportUUID
70
+
71
+ headers = {
72
+ "Content-Type": "application/json",
73
+ "Authorization": 'Bearer ' + accessToken
74
+ }
75
+
76
+ response = requests.get(url, headers=headers)
77
+
78
+ data = response.json()
79
+ return data["response"]["status"]
80
+
81
+ def downloadReport(baseURL, orgUuid, reportUUID, projectUUID, accessToken):
82
+ url = "https://"+baseURL+"/api/v3.0/orgs/"+orgUuid+"/reports/download/"+reportUUID
83
+
84
+ headers = {
85
+ "Authorization": 'Bearer ' + accessToken
86
+ }
87
+
88
+ filename = "report-"+projectUUID+".zip"
89
+
90
+ try:
91
+ # Stream the response to avoid loading it all into memory
92
+ with requests.get(url, stream=True, timeout=10, headers=headers) as response:
93
+ response.raise_for_status() # Raise an error for bad status codes
94
+
95
+ # Open file in binary write mode
96
+ with open(filename, 'wb') as file:
97
+ for chunk in response.iter_content(chunk_size=8192):
98
+ if chunk: # Filter out keep-alive chunks
99
+ file.write(chunk)
100
+
101
+ print(f">>> The report saved to '{filename}' successfully.")
102
+
103
+ except requests.exceptions.RequestException as e:
104
+ print(f">>> Error fetching URL: {e}")
105
+ except OSError as e:
106
+ print(f">>> File error: {e}")
107
+
108
+ def unzipReport(projectUUID):
109
+ pathZipReport = 'report-'+projectUUID+'.zip'
110
+ with zipfile.ZipFile(pathZipReport, 'r') as zip_ref:
111
+ zip_ref.extractall('mend-reports')
112
+ print(f">>> The report '{pathZipReport}' extracted to 'mend-reports' folder.")
113
+ if os.path.exists(pathZipReport):
114
+ os.remove(pathZipReport)
115
+ print(f">>> Deleted: {pathZipReport}")
116
+
117
+ def main():
118
+ # Create parser
119
+ parser = argparse.ArgumentParser(description="This is script to generate reports through Mend API v3.0.")
120
+
121
+ # Add arguments
122
+ parser.add_argument("-mendAPI",
123
+ help="Mend API v3.0 server hostname without https://, like `api-saas.whitesourcesoftware.com`",
124
+ required=True)
125
+ parser.add_argument("-orgUUID", help="Organization UUID", required=True)
126
+ parser.add_argument("-userEmail", help="User Email", required=True)
127
+ parser.add_argument("-userKey", help="User Key", required=True)
128
+ parser.add_argument("-projectUUID", help="List of Project UUIDs separeted by ','", required=True)
129
+ parser.add_argument("-reportType", default="sbom",
130
+ help="Report Type, for example: `vulnerabilities`, `sbom`, `spdx`, `spdx_2_3`, `cycloneDX`, `cycloneDX_1_5`, `cycloneDX_1_6`. The `vulnerabilities` report type generates vulnerability report. The `sbom` report type generates `spdx` format. Optional, default: `sbom`",
131
+ required=False)
132
+ parser.add_argument("-format", default="json",
133
+ help="Report Format, acceptable formats for `vulnerabilities` reportType: `json`, `excel`; for `sbom` reportType: `json`, `yaml`. Optional, default: `json`",
134
+ required=False)
135
+ parser.add_argument("-unzip", default="no",
136
+ help="Extract report to the 'mend-reports' folder. Variants: yes, no. Optional, default: `no`",
137
+ required=False)
138
+
139
+ # Parse arguments
140
+ args = parser.parse_args()
141
+
142
+ baseURL = args.mendAPI
143
+ orgUUID = args.orgUUID
144
+ userEmail = args.userEmail
145
+ userKey = args.userKey
146
+ projectUUID_list = args.projectUUID
147
+ reportType = args.reportType # The "vulnerabilities" report type generates vulnerability report. The "sbom" report type generates `spdx` format. The following report types do not work "spdx", "spdx_2_3", "cycloneDX", "cycloneDX_1_5", "cycloneDX_1_6"
148
+ reportFormat = args.format
149
+ extractReport = args.unzip
150
+ refreshToken = getRefreshToken(baseURL, userEmail, userKey)
151
+ accessToken = getAccessToken(baseURL, refreshToken)
152
+ # print (accessToken)
153
+ for item in projectUUID_list.split(","):
154
+ projectUUID = item.strip()
155
+ print(f"### Processing Project UUID: {projectUUID}")
156
+ reportUUID = generateSBOM(baseURL, projectUUID, reportType, reportFormat, accessToken)
157
+ reportStatus = ""
158
+ while reportStatus != "SUCCESS":
159
+ sleep(3)
160
+ reportStatus = checkReportStatus(baseURL, orgUUID, reportUUID, accessToken)
161
+ # print (reportStatus)
162
+ if reportStatus == "SUCCESS":
163
+ downloadReport(baseURL, orgUUID, reportUUID, projectUUID, accessToken)
164
+ if extractReport == "yes":
165
+ unzipReport(projectUUID)
166
+ print(">>> Report is ready in `mend-reports` folder.")
167
+ else:
168
+ print(">>> Report is ready in `./` folder.")
169
+ elif reportStatus == "IN_PROGRESS":
170
+ print(">>> Report generation in progress, please wait")
171
+ elif reportStatus == "FAILED":
172
+ print(">>> Report generation failed, please try again later")
173
+ sys.exit(1)
174
+ else:
175
+ print(">>> Report generation in progress, please wait")
176
+
177
+
178
+ if __name__ == "__main__":
179
+ main()
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.4
2
+ Name: mend-reporting-tool
3
+ Version: 0.1.0
4
+ Summary: This is script to generate reports through Mend API v3.0
5
+ Maintainer-email: Alexander Chelyshev <alexchelyshev@gmail.com>
6
+ Requires-Python: >=3.12
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: requests>=2.33.1
9
+
10
+ # Mend Report Generation tool
11
+ This is script to generate reports through [Mend API v3.0](https://api-docs.mend.io/platform/3.0).
12
+
13
+ ### How To Use
14
+ ```shell
15
+ $ mend-reporting-tool -h
16
+ usage: mend-reporting-tool [-h] -mendAPI MENDAPI -orgUUID ORGUUID -userEmail USEREMAIL -userKey USERKEY -projectUUID PROJECTUUID
17
+ [-reportType REPORTTYPE] [-format FORMAT] [-unzip UNZIP]
18
+
19
+ This is script to generate reports through Mend API v3.0.
20
+
21
+ options:
22
+ -h, --help show this help message and exit
23
+ -mendAPI MENDAPI Mend API v3.0 server hostname without https://, like `api-saas.whitesourcesoftware.com`
24
+ -orgUUID ORGUUID Organization UUID
25
+ -userEmail USEREMAIL User Email
26
+ -userKey USERKEY User Key
27
+ -projectUUID PROJECTUUID
28
+ List of Project UUIDs separeted by ','
29
+ -reportType REPORTTYPE
30
+ Report Type, for example: `vulnerabilities`, `sbom`, `spdx`, `spdx_2_3`, `cycloneDX`, `cycloneDX_1_5`,
31
+ `cycloneDX_1_6`. The `vulnerabilities` report type generates vulnerability report. The `sbom` report type generates
32
+ `spdx` format. Optional, default: `sbom`
33
+ -format FORMAT Report Format, acceptable formats for `vulnerabilities` reportType: `json`, `excel`; for `sbom` reportType: `json`,
34
+ `yaml`. Optional, default: `json`
35
+ -unzip UNZIP Extract report to the 'mend-reports' folder. Variants: yes, no. Optional, default: `no`
36
+
37
+ ### Example:
38
+ mend-reporting-tool -mendAPI $MEND_API -orgUUID $MEND_ORGANIZATION_UUID -userEmail $MEND_EMAIL -userKey $MEND_USER_KEY -projectUUID $PROJECT_UUID -reportType sbom -format yaml -unzip yes
39
+
40
+ ### Processing Project UUID: <Project_UUID>
41
+ >>> The report saved to 'report-<Project_UUID>.zip' successfully.
42
+ >>> The report 'report-<Project_UUID>.zip' extracted to 'mend-reports' folder.
43
+ >>> Deleted: report-<Project_UUID>.zip
44
+ >>> Report is ready in `mend-reports` folder.
45
+ ...
46
+
47
+ # Content of `mend-reports` folder:
48
+ $ ls -l mend-reports/
49
+ -rw-r--r-- 1 alex alex 1033049 Apr 20 23:50 '<Project_Name>-project-SPDX-reportyaml'
50
+ ```
51
+
52
+ ### How To Install locally from source code
53
+ ```shell
54
+ python3 -m venv .venv
55
+ source .venv/bin/activate
56
+ pip install -e .
57
+ ```
58
+
@@ -0,0 +1,11 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/mend_reporting_tool/__init__.py
4
+ src/mend_reporting_tool/__main__.py
5
+ src/mend_reporting_tool/main.py
6
+ src/mend_reporting_tool.egg-info/PKG-INFO
7
+ src/mend_reporting_tool.egg-info/SOURCES.txt
8
+ src/mend_reporting_tool.egg-info/dependency_links.txt
9
+ src/mend_reporting_tool.egg-info/entry_points.txt
10
+ src/mend_reporting_tool.egg-info/requires.txt
11
+ src/mend_reporting_tool.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mend-reporting-tool = mend_reporting_tool.main:main
@@ -0,0 +1 @@
1
+ mend_reporting_tool