def check(self, path: str) -> None:
     ext = os.path.splitext(path)[1]
     if ext not in [
             ".asc",
             ".jar",
             ".md5",
             ".module",
             ".pom",
             ".sha1",
             ".sha256",
             ".sha512",
             ".war",
             ".xml",
             ".zip",
     ]:
         raise BuildArtifactCheck.BuildArtifactInvalidError(
             path, f"{ext} is not a valid extension for a maven file")
     if os.path.splitext(path)[1] == ".jar":
         with ZipFile(path, "r") as zip:
             data = zip.read("META-INF/MANIFEST.MF").decode("UTF-8")
             properties = PropertiesFile(data)
             try:
                 versions: List[Any] = [None]
                 versions.extend(self.target.compatible_component_versions)
                 versions.extend(self.target.compatible_min_versions)
                 properties.check_value_in("Implementation-Version",
                                           versions)
             except PropertiesFile.CheckError as e:
                 raise BuildArtifactCheck.BuildArtifactInvalidError(
                     path, str(e))
             logging.info(
                 f'Checked {path} ({properties.get_value("Implementation-Version", "N/A")})'
             )
 def test_check_value_in_none_found(self) -> None:
     f = PropertiesFile()
     with self.assertRaises(PropertiesFile.UnexpectedKeyValuesError) as err:
         f.check_value_in("invalid", ["one", "two"])
     self.assertEqual(
         str(err.exception),
         "Expected to have invalid=any of ['one', 'two'], but none was found.",
     )
 def test_check_value_in_invalid(self) -> None:
     f = PropertiesFile({"key": "value"})
     with self.assertRaises(PropertiesFile.UnexpectedKeyValuesError) as err:
         f.check_value_in("key", ["one", "two"])
     self.assertEqual(
         str(err.exception),
         "Expected to have key=any of ['one', 'two'], but was 'value'.",
     )
Beispiel #4
0
 def check(self, path: str) -> None:
     if os.path.splitext(path)[1] != ".zip":
         raise BuildArtifactCheck.BuildArtifactInvalidError(path, "Not a zip file.")
     if not self.valid_path(path):
         raise BuildArtifactCheck.BuildArtifactInvalidError(path, f"Expected filename to include one of {self.target.compatible_component_versions}.")
     with ZipFile(path, "r") as zip:
         data = zip.read("plugin-descriptor.properties").decode("UTF-8")
         properties = PropertiesFile(data)
         try:
             properties.check_value_in("version", self.target.compatible_component_versions)
             properties.check_value_in("opensearch.version", self.target.compatible_versions)
         except PropertiesFile.CheckError as e:
             raise BuildArtifactCheck.BuildArtifactInvalidError(path, e.__str__())
         logging.info(f'Checked {path} ({properties.get_value("version", "N/A")})')
 def test_check_value_in(self) -> None:
     f = PropertiesFile({"key": "value"})
     f.check_value_in("key", ["value"])