11# -------------------------------------------------------------------------------
2- # Copyright (c) 2019-2023 Siemens
2+ # Copyright (c) 2019-2026 Siemens
33# Copyright (c) 2022 BMW CarIT GmbH
44# All Rights Reserved.
55# Authors: thomas.graf@siemens.com, gernot.hillier@siemens.com
@@ -34,6 +34,8 @@ def get_attachment_infos_by_hash(self, hashvalue: str) -> Optional[Dict[str, Any
3434
3535 API endpoint: GET /attachments?sha1=
3636 """
37+ if not hashvalue :
38+ raise SW360Error (message = "No hash value provided!" )
3739
3840 resp = self .api_get (
3941 self .url + "resource/api/attachments?sha1=" + hashvalue
@@ -47,6 +49,15 @@ def get_attachment_infos_for_resource(self, resource_type: str, resource_id: str
4749 specific get_attachment_infos_for_{release,component,project} functions.
4850 """
4951
52+ if not resource_id :
53+ raise SW360Error (message = "No resource id provided!" )
54+
55+ if not resource_type :
56+ raise SW360Error (message = "No resource type provided!" )
57+
58+ if resource_type not in ("releases" , "components" , "projects" ):
59+ raise SW360Error (message = "Invalid resource type!" )
60+
5061 resp = self .api_get (
5162 self .url + "resource/api/"
5263 + resource_type
@@ -65,6 +76,8 @@ def get_attachment_infos_for_release(self, release_id: str) -> List[Dict[str, An
6576
6677 :param release_id: id of the release from which to list attachments
6778 """
79+ if not release_id :
80+ raise SW360Error (message = "No release id provided!" )
6881
6982 resp = self .get_attachment_infos_for_resource ("releases" , release_id )
7083 return resp
@@ -74,6 +87,8 @@ def get_attachment_infos_for_component(self, component_id: str) -> List[Dict[str
7487
7588 :param component_id: id of the component from which to list attachments
7689 """
90+ if not component_id :
91+ raise SW360Error (message = "No component id provided!" )
7792
7893 resp = self .get_attachment_infos_for_resource ("components" , component_id )
7994 return resp
@@ -83,6 +98,8 @@ def get_attachment_infos_for_project(self, project_id: str) -> List[Dict[str, An
8398
8499 :param project_id: id of the project from which to list attachments
85100 """
101+ if not project_id :
102+ raise SW360Error (message = "No project id provided!" )
86103
87104 resp = self .get_attachment_infos_for_resource ("projects" , project_id )
88105 return resp
@@ -92,6 +109,9 @@ def get_attachment_by_url(self, url: str) -> Optional[Dict[str, Any]]:
92109
93110 :param url: the full url of the attachment to be requested
94111 """
112+ if not url :
113+ raise SW360Error (message = "No url provided!" )
114+
95115 resp = self .api_get (url )
96116 return resp
97117
@@ -102,6 +122,8 @@ def get_attachment(self, attachment_id: str) -> Optional[Dict[str, Any]]:
102122
103123 :param attachment_id: id of the attachment
104124 """
125+ if not attachment_id :
126+ raise SW360Error (message = "No attachment id provided!" )
105127
106128 resp = self .api_get (self .url + "resource/api/attachments/" + attachment_id )
107129 return resp
@@ -111,6 +133,8 @@ def download_release_attachment(self, filename: str, release_id: str, attachment
111133
112134 API endpoint: GET /attachments
113135 """
136+ if not release_id :
137+ raise SW360Error (message = "No release id provided!" )
114138
115139 self .download_resource_attachment (
116140 filename , "releases" , release_id , attachment_id
@@ -121,6 +145,8 @@ def download_project_attachment(self, filename: str, project_id: str, attachment
121145
122146 API endpoint: GET /attachments
123147 """
148+ if not project_id :
149+ raise SW360Error (message = "No project id provided!" )
124150
125151 self .download_resource_attachment (
126152 filename , "projects" , project_id , attachment_id
@@ -131,6 +157,8 @@ def download_component_attachment(self, filename: str, component_id: str, attach
131157
132158 API endpoint: GET /attachments
133159 """
160+ if not component_id :
161+ raise SW360Error (message = "No component id provided!" )
134162
135163 self .download_resource_attachment (
136164 filename , "components" , component_id , attachment_id
@@ -142,6 +170,8 @@ def download_resource_attachment(self, filename: str, resource_type: str, resour
142170
143171 API endpoint: GET /attachments
144172 """
173+ if not filename :
174+ raise SW360Error (message = "No filename provided!" )
145175
146176 if not resource_id :
147177 raise SW360Error (message = "No resource id provided!" )
@@ -165,6 +195,11 @@ def download_attachment(self, filename: str, download_url: str) -> None:
165195
166196 API endpoint: GET /attachments
167197 """
198+ if not filename :
199+ raise SW360Error (message = "No filename provided!" )
200+
201+ if not download_url :
202+ raise SW360Error (message = "No download url provided!" )
168203
169204 hdr = self .api_headers .copy ()
170205 hdr ["Accept" ] = "application/*"
@@ -238,6 +273,8 @@ def upload_release_attachment(self, release_id: str, upload_file: str, upload_ty
238273
239274 API endpoint: POST /attachments
240275 """
276+ if not release_id :
277+ raise SW360Error (message = "No release id provided!" )
241278
242279 self ._upload_resource_attachment (
243280 "releases" , release_id , upload_file ,
@@ -259,6 +296,8 @@ def upload_component_attachment(self, component_id: str, upload_file: str, uploa
259296
260297 API endpoint: POST /attachments
261298 """
299+ if not component_id :
300+ raise SW360Error (message = "No component id provided!" )
262301
263302 self ._upload_resource_attachment (
264303 "components" , component_id , upload_file ,
@@ -280,6 +319,8 @@ def upload_project_attachment(self, project_id: str, upload_file: str, upload_ty
280319
281320 API endpoint: POST /attachments
282321 """
322+ if not project_id :
323+ raise SW360Error (message = "No project id provided!" )
283324
284325 self ._upload_resource_attachment (
285326 "projects" , project_id , upload_file ,
0 commit comments