Bug 1862: Fixed required field in SOL006 IM to generate OSM repo index
[osm/osmclient.git] / osmclient / sol005 / osmrepo.py
index d731e30..85529de 100644 (file)
@@ -16,7 +16,6 @@
 OSM Repo API handling
 """
 import glob
 OSM Repo API handling
 """
 import glob
-import hashlib
 import logging
 from os import listdir, mkdir, getcwd, remove
 from os.path import isfile, isdir, join, abspath
 import logging
 from os import listdir, mkdir, getcwd, remove
 from os.path import isfile, isdir, join, abspath
@@ -29,6 +28,7 @@ from osm_im.validation import Validation as validation_im
 from osmclient.common.exceptions import ClientException
 from osmclient.common.package_tool import PackageTool
 from osmclient.sol005.repo import Repo
 from osmclient.common.exceptions import ClientException
 from osmclient.common.package_tool import PackageTool
 from osmclient.sol005.repo import Repo
+from osmclient.common import utils
 from packaging import version as versioning
 import requests
 import yaml
 from packaging import version as versioning
 import requests
 import yaml
@@ -226,19 +226,6 @@ class OSMRepo(Repo):
             + str(len(glob.glob(destination + "/nst/*/*/metadata.yaml")))
         )
 
             + str(len(glob.glob(destination + "/nst/*/*/metadata.yaml")))
         )
 
-    def md5(self, fname):
-        """
-        Checksum generator
-        :param fname: file path
-        :return: checksum string
-        """
-        self._logger.debug("")
-        hash_md5 = hashlib.md5()
-        with open(fname, "rb") as f:
-            for chunk in iter(lambda: f.read(4096), b""):
-                hash_md5.update(chunk)
-        return hash_md5.hexdigest()
-
     def fields_building(self, descriptor_dict, file, package_type):
         """
         From an artifact descriptor, obtain the fields required for indexing
     def fields_building(self, descriptor_dict, file, package_type):
         """
         From an artifact descriptor, obtain the fields required for indexing
@@ -321,8 +308,8 @@ class OSMRepo(Repo):
             msg = f"Unexpected descriptor format {descriptor_dict}"
             self._logger.error(msg)
             raise ValueError(msg)
             msg = f"Unexpected descriptor format {descriptor_dict}"
             self._logger.error(msg)
             raise ValueError(msg)
-
-        fields["name"] = aux_dict.get("name")
+        # Repo search is based on 'name' entry in index.yaml. It is mandatory then
+        fields["name"] = aux_dict.get("name", aux_dict["product-name"])
         fields["id"] = aux_dict.get("id")
         fields["description"] = aux_dict.get("description")
         fields["vendor"] = aux_dict.get("vendor")
         fields["id"] = aux_dict.get("id")
         fields["description"] = aux_dict.get("description")
         fields["vendor"] = aux_dict.get("vendor")
@@ -438,7 +425,7 @@ class OSMRepo(Repo):
                     path = pt.build(path)
                     self._logger.debug(f"Directory path {path}")
                     compressed = True
                     path = pt.build(path)
                     self._logger.debug(f"Directory path {path}")
                     compressed = True
-                fields["checksum"] = self.md5(path)
+                fields["checksum"] = utils.md5(path)
                 self.indexation(destination, path, package_type, fields)
 
         except Exception as e:
                 self.indexation(destination, path, package_type, fields)
 
         except Exception as e: