Esempio n. 1
0
 def extract_archive(archive_path):
     try:
         tf = tarfile.open(archive_path)
         tf.extractall(path=const.INSTALL_CACHE)
     except IOError as e:
         raise general_exceptions.ArchiveExtractionError(
             "Could not extract {} archive to {}; {}".format(archive_path, const.INSTALL_CACHE, e))
     except Exception as e:
         raise general_exceptions.ArchiveExtractionError(
             "General error while attempting to extract {}} archive; {}".format(archive_path, e))
Esempio n. 2
0
def update_default_configurations():
    """
    Retrieves the latest skeleton configurations for setting up ElasticSearch, LogStash, Zeek, and Suricata
    """

    shutil.rmtree(const.INSTALL_CACHE, ignore_errors=True)
    makedirs(const.DEFAULT_CONFIGS, exist_ok=True)
    try:
        download_file(const.DEFAULT_CONFIGS_URL,
                      const.DEFAULT_CONFIGS_ARCHIVE_NAME,
                      stdout=True)
    except Exception as e:
        raise exceptions.DownloadError(
            "General error occurred while downloading archive: {}; {}".format(
                os.path.join(const.INSTALL_CACHE, 'default_configs.tar.gz'),
                e))
    shutil.rmtree(const.DEFAULT_CONFIGS, ignore_errors=True)
    time.sleep(1)
    try:
        extract_archive(
            os.path.join(const.INSTALL_CACHE, 'default_configs.tar.gz'),
            const.CONFIG_PATH)
    except IOError as e:
        raise exceptions.ArchiveExtractionError(
            "General error occurred while extracting archive: {}; {}".format(
                os.path.join(const.INSTALL_CACHE, 'default_configs.tar.gz'),
                e))
Esempio n. 3
0
 def extract_archive(archive_path: str) -> None:
     """
     Extract a tar.gz archive to disk
     Args:
         archive_path: The full path to the archive.
     Returns:
         None
     """
     try:
         tf = tarfile.open(archive_path)
         tf.extractall(path=const.INSTALL_CACHE)
     except IOError as e:
         raise exceptions.ArchiveExtractionError(
             f'Could not extract {archive_path} archive to {const.INSTALL_CACHE}; {e}')
     except Exception as e:
         raise exceptions.ArchiveExtractionError(
             f'General error while attempting to extract {archive_path} archive; {e}')
Esempio n. 4
0
    def extract_dynamite_sdk():
        """
        Extract DynamiteSDK to local install_cache
        """

        try:
            tf = tarfile.open(
                os.path.join(const.INSTALL_CACHE,
                             const.DYNAMITE_SDK_ARCHIVE_NAME))
            tf.extractall(path=const.INSTALL_CACHE)
        except IOError as e:
            raise general_exceptions.ArchiveExtractionError(
                "Could not extract DynamiteSDK archive to {}; {}".format(
                    const.INSTALL_CACHE, e))
        except Exception as e:
            raise general_exceptions.ArchiveExtractionError(
                "General error while attempting to extract DynamiteSDK archive; {}"
                .format(e))
Esempio n. 5
0
 def extract_configurations_package(
     archive_path: Optional[
         str] = f'{const.INSTALL_CACHE}/configurations.tar.gz'
 ) -> None:
     """Extract the relevant files from the dynamite `configurations` archive to the install_cache.
     Args:
         archive_path: The path to the archive
     Returns:
         None
     """
     try:
         shutil.rmtree(f'{const.INSTALL_CACHE}/configurations')
         shutil.rmtree(const.DEFAULT_CONFIGS)
     except FileNotFoundError:
         pass
     with tarfile.open(archive_path) as tar:
         members = tar.getmembers()
         if not members:
             raise exceptions.ArchiveExtractionError(
                 'Unable to find any members.')
         if not members[0].isdir():
             raise exceptions.ArchiveExtractionError(
                 'Root directory not found.')
         selected_members = [
             member for member in members
             if member.name.startswith(f'{members[0].name}/base')
             or member.name.startswith(f'{members[0].name}/delta')
         ]
         try:
             tar.extractall(members=selected_members,
                            path=const.INSTALL_CACHE)
         except IOError as e:
             raise exceptions.ArchiveExtractionError(
                 f'General extraction error: {e}')
         shutil.move(f'{const.INSTALL_CACHE}/{members[0].name}',
                     f'{const.INSTALL_CACHE}/configurations')