Exemplo n.º 1
0
    def _check_tarfile(self, app_name, app_tarfile):
        if app_name and app_tarfile:
            if not os.path.isfile(app_tarfile):
                raise wsme.exc.ClientSideError(
                    _("Application-upload rejected: application tar file {} does "
                      "not exist.".format(app_tarfile)))
            if (not app_tarfile.endswith('.tgz')
                    and not app_tarfile.endswith('.tar.gz')):
                raise wsme.exc.ClientSideError(
                    _("Application-upload rejected: {} has unrecognizable tar file "
                      "extension. Supported extensions are: .tgz and .tar.gz.".
                      format(app_tarfile)))

            with TempDirectory() as app_path:
                if not cutils.extract_tarfile(app_path, app_tarfile):
                    raise wsme.exc.ClientSideError(
                        _("Application-upload rejected: failed to extract tar file "
                          "{}.".format(os.path.basename(app_tarfile))))

                # If checksum file is included in the tarball, verify its contents.
                if not cutils.verify_checksum(app_path):
                    raise wsme.exc.ClientSideError(
                        _("Application-upload rejected: checksum validation failed."
                          ))

                mname, mfile = self._find_manifest_file(app_path)

                charts_dir = os.path.join(app_path, 'charts')
                if os.path.isdir(charts_dir):
                    tar_filelist = cutils.get_files_matching(app_path, '.tgz')
                    if len(os.listdir(charts_dir)) == 0:
                        raise wsme.exc.ClientSideError(
                            _("Application-upload rejected: tar file contains no "
                              "Helm charts."))
                    if not tar_filelist:
                        raise wsme.exc.ClientSideError(
                            _("Application-upload rejected: tar file contains no "
                              "Helm charts of expected file extension (.tgz).")
                        )
                    for p, f in tar_filelist:
                        if not cutils.extract_tarfile(p, os.path.join(p, f)):
                            raise wsme.exc.ClientSideError(
                                _("Application-upload rejected: failed to extract tar "
                                  "file {}.".format(os.path.basename(f))))
                LOG.info("Tar file of application %s verified." % app_name)
                return mname, mfile

        else:
            raise ValueError(
                _("Application-upload rejected: both application name and tar "
                  "file must be specified."))
Exemplo n.º 2
0
 def _extract_helm_charts(self, app_path, demote_user=False):
     charts_dir = os.path.join(app_path, 'charts')
     if os.path.isdir(charts_dir):
         tar_filelist = cutils.get_files_matching(app_path, '.tgz')
         if len(os.listdir(charts_dir)) == 0:
             raise exception.SysinvException(
                 _("tar file contains no Helm charts."))
         if not tar_filelist:
             raise exception.SysinvException(
                 _("tar file contains no Helm charts of "
                   "expected file extension (.tgz)."))
         for p, f in tar_filelist:
             if not cutils.extract_tarfile(p, os.path.join(p, f),
                                           demote_user):
                 raise exception.SysinvException(
                     _("failed to extract tar file {}.".format(
                         os.path.basename(f))))