baywa-re-lusy/file-storage

BayWa r.e. LUSY 文件存储工具

6.0.1 2022-12-04 09:03 UTC

This package is auto-updated.

Last update: 2024-09-29 17:11:10 UTC


README

CircleCI

安装

要安装文件存储工具,您需要在项目中安装 Composer

composer require baywa-re-lusy/file-storage

Azure Blob Storage

需要配置 Azure Blob Storage 以使用 AzureBlobAdapter。可以使用 terraform 创建。

# Create the Storage Account
resource "azurerm_storage_account" "blob_storage" {
  name                     = "storage-name"
  resource_group_name      = "resourge-group-name"
  location                 = "location"
  account_tier             = "Standard"
  account_replication_type = "GRS"
}

# Create a Blob Share inside the Storage Account
resource "azurerm_storage_container" "container" {
  name                  = "content"
  storage_account_name  = azurerm_storage_account.blob_storage.name
  container_access_type = "private"
}

# Generate Shared Access Signature
# the property "signed_version" can't be set (or must be an old one) and "tag" and "filter" must be set to false
# see https://github.com/hashicorp/terraform-provider-azurerm/issues/17558
data "azurerm_storage_account_sas" "sas" {
  connection_string = azurerm_storage_account.file_storage.primary_connection_string
  https_only        = true

  resource_types {
    service   = true
    container = true
    object    = true
  }

  services {
    blob  = true
    queue = false
    table = false
    file  = false
  }

  start  = "2022-05-17T00:00:00Z"
  expiry = "2024-05-17T00:00:00Z"

  permissions {
    read    = true
    write   = true
    delete  = true
    list    = true
    add     = false
    create  = true
    update  = false
    process = false
    tag     = false
    filter  = false
  }
}

output "azure_shared_access_signature" {
  value = data.azurerm_storage_account_sas.sas.sas
  sensitive = true
}

一旦基础设施更新,使用以下方法检索 SAS 连接字符串:

terraform output azure_shared_access_signature

使用方法

目前,此库支持 Azure Blob Storage。然而,它使用适配器模式以便轻松添加其他供应商。

Azure Blob

use BayWaReLusy\FileStorage\FileStorageService;
use BayWaReLusy\FileStorage\Adapter\AzureBlobAdapter;

$adapter            = new AzureBlobAdapter('<storage-account-name>', '<container name>', '<shared-access-signature>');
$fileStorageService = new FileStorageService($adapter);

本地存储

此库还包括一个用于测试目的的本地适配器。

您必须向适配器提供事先创建的远程目录路径(必须包含 'public' 文件夹)以及相应的写入权限以及 API 的 URL。

use BayWaReLusy\FileStorage\FileStorageService;
use BayWaReLusy\FileStorage\Adapter\LocalAdapter;

$adapter            = new LocalAdapter('/var/www/html/public/remote', 'https://my-api.api-url.com');
$fileStorageService = new FileStorageService($adapter);