diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/onapsdk/sdc/service.py | 17 | ||||
-rw-r--r-- | src/onapsdk/utils/configuration.py | 5 | ||||
-rw-r--r-- | src/onapsdk/utils/headers_creator.py | 2 | ||||
-rw-r--r-- | src/onapsdk/utils/tosca_file_handler.py | 4 |
4 files changed, 11 insertions, 17 deletions
diff --git a/src/onapsdk/sdc/service.py b/src/onapsdk/sdc/service.py index c866fa4..9bd92f0 100644 --- a/src/onapsdk/sdc/service.py +++ b/src/onapsdk/sdc/service.py @@ -31,8 +31,7 @@ from onapsdk.exceptions import (ParameterError, RequestError, ResourceNotFound, from onapsdk.sdc.category_management import ServiceCategory from onapsdk.sdc.properties import NestedInput, Property from onapsdk.sdc.sdc_resource import SdcResource -from onapsdk.utils.configuration import (components_needing_distribution, - tosca_path) +from onapsdk.utils.configuration import components_needing_distribution from onapsdk.utils.headers_creator import headers_sdc_creator, headers_sdc_artifact_upload from onapsdk.utils.jinja import jinja_env @@ -591,7 +590,7 @@ class Service(SdcResource): # pylint: disable=too-many-instance-attributes, too const.DISTRIBUTE, headers=headers) - def get_tosca(self) -> None: + def get_tosca(self, paths) -> None: """Get Service tosca files and save it.""" url = "{}/services/{}/toscaModel".format(self._base_url(), self.identifier) @@ -603,17 +602,17 @@ class Service(SdcResource): # pylint: disable=too-many-instance-attributes, too url, headers=headers) if result: - self._create_tosca_file(result) + self._create_tosca_file(paths, result) - def _create_tosca_file(self, result: Response) -> None: + def _create_tosca_file(self, paths, result: Response) -> None: """Create Service Tosca files from HTTP response.""" csar_filename = "service-{}-csar.csar".format(self.name) - makedirs(tosca_path(), exist_ok=True) - with open((tosca_path() + csar_filename), 'wb') as csar_file: + makedirs(paths, exist_ok=True) + with open((paths + csar_filename), 'wb') as csar_file: for chunk in result.iter_content(chunk_size=128): csar_file.write(chunk) try: - self._unzip_csar_file(tosca_path() + csar_filename, + self._unzip_csar_file(paths + csar_filename, self._write_csar_file) except BadZipFile as exc: self._logger.exception(exc) @@ -795,7 +794,7 @@ class Service(SdcResource): # pylint: disable=too-many-instance-attributes, too def _write_csar_file(service_template: str, template_file: TextIOWrapper) -> None: """Write service temple into a file.""" - with open(tosca_path() + service_template[12:], 'wb') as file: + with open(service_template[12:], 'wb') as file: file.write(template_file.read()) # _service_template is not used but function generation is generic diff --git a/src/onapsdk/utils/configuration.py b/src/onapsdk/utils/configuration.py index 89bee5a..487a472 100644 --- a/src/onapsdk/utils/configuration.py +++ b/src/onapsdk/utils/configuration.py @@ -15,11 +15,6 @@ from typing import List -def tosca_path() -> str: - """Return tosca file paths.""" - return '/tmp/tosca_files/' - - def components_needing_distribution() -> List[str]: """Return the list of components needing distribution.""" return ["SO", "sdnc", "aai"] diff --git a/src/onapsdk/utils/headers_creator.py b/src/onapsdk/utils/headers_creator.py index adb0609..ae03a38 100644 --- a/src/onapsdk/utils/headers_creator.py +++ b/src/onapsdk/utils/headers_creator.py @@ -223,7 +223,7 @@ def headers_sdc_artifact_upload(base_header: Dict[str, str], data: str): headers["Accept"] = "application/json, text/plain, */*" headers["Accept-Encoding"] = "gzip, deflate, br" headers["Content-Type"] = "application/json; charset=UTF-8" - md5_content = hashlib.md5(data.encode('UTF-8')).hexdigest() + md5_content = hashlib.new('md5', data.encode('UTF-8'), usedforsecurity=False).hexdigest() content = base64.b64encode(md5_content.encode('ascii')).decode('UTF-8') headers["Content-MD5"] = content return headers diff --git a/src/onapsdk/utils/tosca_file_handler.py b/src/onapsdk/utils/tosca_file_handler.py index 921b868..1d1918b 100644 --- a/src/onapsdk/utils/tosca_file_handler.py +++ b/src/onapsdk/utils/tosca_file_handler.py @@ -14,7 +14,7 @@ # limitations under the License. import json import string -import random +import secrets from typing import Dict, List from onapsdk.exceptions import ValidationError @@ -103,4 +103,4 @@ def random_string_generator(size=6, str: a sequence of random characters """ - return ''.join(random.choice(chars) for _ in range(size)) + return ''.join(secrets.choice(chars) for _ in range(size)) |