dbp/relay-blob-bundle

用于文件服务、持久化和管理的包


README

DbpRelayBlobBundle

GitHub | Packagist | 变更日志

该 blob 包提供了一种抽象不同共享存储系统的 API。您可以通过 API 无授权上传文件到配置的存储桶,并获取一个短期的临时链接。认证通过签名请求进行。文件附加到存储桶,而不是所有者。

存储桶可以是应用程序或应用程序空间。例如,您可以为一个应用程序配置两个具有不同目标组的存储桶。存储桶在配置文件中配置。

要求

您需要安装 DbpRelayBlobConnector 包以使此包工作。例如 DbpRelayBlobConnectorFilesystemBundle

包安装

您可以直接从 packagist.org 安装此包。

composer require dbp/relay-blob-bundle

集成到 Relay API 服务器

  • 将包添加到您的 config/bundles.php 文件中,在 DbpRelayCoreBundle 之前
...
Dbp\Relay\BlobBundle\DbpRelayBlobBundle::class => ['all' => true],
Dbp\Relay\CoreBundle\DbpRelayCoreBundle::class => ['all' => true],
];

如果您将 DBP API 服务器模板 作为您的 Symfony 应用程序的模板,则这应该已经为您生成。

  • 运行 composer install 以清除缓存

配置

该包具有多个配置值,您可以在应用程序中指定,无论是通过硬编码还是通过引用环境变量。

为此,在应用程序中创建 config/packages/dbp_relay_blob.yaml,内容如下

dbp_relay_blob:
  database_url: %env(resolve:DATABASE_URL)%'
  reporting_interval: "0 11 * * MON" # when notification cronjob should run
  cleanup_interval: "*/5 * * * *" # when cleanup cronjob should run
  file_integrity_checks: true # if file integrity checks should be performed periodically
  integrity_check_interval: "0 0 1 * *" # when integrity check cronjob should run
  bucket_size_check_interval: "0 2 * * 1" # when bucket size check cronjob should run
  quota_warning_interval: "0 7 * * *" # when bucket quota should be checked and if needed warning emails should be sent
  additional_auth: true # enable client credential flow
  buckets:
    test_bucket:
      service: 'Dbp\Relay\BlobConnectorFilesystemBundle\Service\FilesystemService' # The path to a dbp relay blob connector service
      internal_bucket_id: '019072b9-7736-7430-aabd-ad1bbeeebacf' # A given internal id for a bucket
      bucket_id: 'test-bucket' # friendly name of the bucket thats also used for the request
      key: '12345' # public key for signed request
      quota: 500 # Max quota in MB
      notify_when_quota_over: 70 # percent of quota when the bucket owner should be notified that the storage is running out
      report_when_expiry_in: 'P30D' # duration of how much in advance a bucket owner or user should be warned about the deletion of files
      bucket_owner: 'john@example.com' # Email who will be notified when quota is reached
      link_expire_time: 'P7D' # Max expire time of sharelinks in ISO 8601
      warn_quota: # Notification configuration how emails are sent when the quota is about to be reached
        dsn: '%env(TUGRAZ_MAILER_TRANSPORT_DSN)%'
        from: 'noreply@tugraz.at'
        to: 'john@example.com'
        subject: 'Blob Bucket Quota Warning'
        html_template: 'emails/warn-quota.html.twig'
      reporting: # Reporting configuration how emails are sent when files are about to expire
        dsn: '%env(TUGRAZ_MAILER_TRANSPORT_DSN)%'
        from: 'noreply@tugraz.at'
        to: 'john@example.com' # this email is a fallback, if no email field of a file is set
        subject: 'Blob file Deletion Report'
        html_template: 'emails/reporting.html.twig'
      integrity: # Integrity check configuration how emails are sent when file hash or metadata hash do not match with the saved file or metadata
        dsn: '%env(TUGRAZ_MAILER_TRANSPORT_DSN)%'
        from: 'noreply@tugraz.at'
        to: 'john@example.com'
        subject: 'Blob File Integrity Check Report'
        html_template: 'emails/integrity.html.twig'
      additional_types:
        - generic_id_card: '%kernel.project_dir%/config/packages/schemas/relay-blob-bundle/test-bucket/generic_id_card.json'

有关包配置的更多信息,请参阅 https://symfony.com.cn/doc/current/bundles/configuration.html

开发和测试

  • 安装依赖项: composer install
  • 运行测试: composer test
  • 运行 linters: composer run lint
  • 运行 cs-fixer: composer run cs-fix

包依赖项

如果您在包中安装包,别忘了在主应用程序中拉取依赖项。

# updates and installs dependencies of dbp/relay-blob-bundle
composer update dbp/relay-blob-bundle

脚本

数据库迁移

运行此脚本以迁移数据库。在安装包后以及每次更新后运行此脚本,以使数据库适应新的源代码。

php bin/console doctrine:migrations:migrate --em=dbp_relay_blob_bundle

错误代码

请参阅 API 文档

定时任务

清理定时任务

Blob 文件清理:此定时任务用于清理目的。它每小时启动一次,删除旧文件。

发送报告定时任务

Blob 文件发送报告:此定时任务将报告发送到指定的电子邮件地址或存储桶所有者。在这些报告中包含在配置中指定的时间段内将要删除的所有文件。电子邮件地址附加到这些文件或配置中有默认值。此定时任务每周一早上 9 点(UTC)启动。