def _download_plugin()

in container-images/gerrit-init/tools/gerrit-initializer/initializer/tasks/download_plugins.py [0:0]


    def _download_plugin(self, plugin, target):
        LOG.info("Downloading %s plugin to %s", plugin["name"], target)
        try:
            response = requests.get(plugin["url"])
        except requests.exceptions.SSLError:
            response = requests.get(plugin["url"], verify=self.config.ca_cert_path)

        with open(target, "wb") as f:
            f.write(response.content)

        file_sha = self._get_file_sha(target)

        if file_sha != plugin["sha1"]:
            os.remove(target)
            raise InvalidPluginException(
                (
                    "SHA1 of downloaded file (%s) did not match expected SHA1 (%s). "
                    "Removed downloaded file (%s)"
                )
                % (file_sha, plugin["sha1"], target)
            )