Exemple #1
0
 def upload_pba_file(request_, is_linux=True):
     """
     Uploads PBA file to island's file system
     :param request_: Request object containing PBA file
     :param is_linux: Boolean indicating if this file is for windows or for linux
     :return: filename string
     """
     filename = secure_filename(request_.files['filepond'].filename)
     file_path = ABS_UPLOAD_PATH.joinpath(filename).absolute()
     request_.files['filepond'].save(str(file_path))
     ConfigService.set_config_value(
         (PBA_LINUX_FILENAME_PATH
          if is_linux else PBA_WINDOWS_FILENAME_PATH), filename)
     return filename
Exemple #2
0
    def delete(self, file_type):
        """
        Deletes file that has been deleted on the front end
        :param file_type: Type indicates which file was deleted, linux of windows
        :return: Empty response
        """
        filename_path = (PBA_LINUX_FILENAME_PATH if file_type == "PBAlinux"
                         else PBA_WINDOWS_FILENAME_PATH)
        filename = ConfigService.get_config_value(filename_path)
        if filename:
            PostBreachFilesService.remove_file(filename)
            ConfigService.set_config_value(filename_path, "")

        return {}
Exemple #3
0
    def upload_pba_file(file_storage: FileStorage, is_linux=True):
        """
        Uploads PBA file to island's file system
        :param request_: Request object containing PBA file
        :param is_linux: Boolean indicating if this file is for windows or for linux
        :return: filename string
        """
        filename = secure_filename(file_storage.filename)
        file_contents = file_storage.read()

        PostBreachFilesService.save_file(filename, file_contents)

        ConfigService.set_config_value(
            (PBA_LINUX_FILENAME_PATH
             if is_linux else PBA_WINDOWS_FILENAME_PATH), filename)

        return filename
Exemple #4
0
    def delete(self, file_type):
        """
        Deletes file that has been deleted on the front end
        :param file_type: Type indicates which file was deleted, linux of windows
        :return: Empty response
        """
        filename_path = PBA_LINUX_FILENAME_PATH if file_type == 'PBAlinux' else PBA_WINDOWS_FILENAME_PATH
        filename = ConfigService.get_config_value(filename_path)
        file_path = ABS_UPLOAD_PATH.joinpath(filename)
        try:
            if os.path.exists(file_path):
                os.remove(file_path)
            ConfigService.set_config_value(filename_path, '')
        except OSError as e:
            LOG.error(
                "Can't remove previously uploaded post breach files: %s" % e)

        return {}
Exemple #5
0
    def delete(self, file_type):
        """
        Deletes file that has been deleted on the front end
        :param file_type: Type indicates which file was deleted, linux of windows
        :return: Empty response
        """
        if self.is_pba_file_type_supported(file_type):
            return Response(status=HTTPStatus.UNPROCESSABLE_ENTITY,
                            mimetype="text/plain")

        filename_path = (PBA_LINUX_FILENAME_PATH if file_type == "PBAlinux"
                         else PBA_WINDOWS_FILENAME_PATH)
        filename = ConfigService.get_config_value(filename_path)
        if filename:
            PostBreachFilesService.remove_file(filename)
            ConfigService.set_config_value(filename_path, "")

        return {}
Exemple #6
0
def _set_aws_key(key_type: str, key_value: str):
    path_to_keys = AWS_KEYS_PATH
    encrypted_key = get_datastore_encryptor().encrypt(key_value)
    ConfigService.set_config_value(path_to_keys + [key_type], encrypted_key)