定制 novay/bunny-secrets 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

novay/bunny-secrets

Composer 安装命令:

composer require novay/bunny-secrets

包简介

A Laravel filesystem driver and helper facade for Bunny.net Storage with optional Borneo Secrets Manager API key resolution.

README 文档

README

A small Laravel package for Bunny.net Storage with:

  • automatic bunnycdn filesystem driver registration;
  • a BunnySecret facade for upload, URL, exists, and delete helpers;
  • optional API key resolution from Borneo Secrets Manager;
  • safe fallback order for API keys to avoid circular filesystem boot errors.

Requirements

  • PHP ^8.1
  • Laravel ^10.0, ^11.0, ^12.0, or ^13.0
  • platformcommunity/flysystem-bunnycdn ^3.0

Installation

composer require novay/bunny-secrets
php artisan vendor:publish --tag=bunny-secrets-config
php artisan optimize:clear

Laravel package discovery will register the service provider automatically.

Environment

Recommended direct Bunny.net API key setup

Use this when you do not need Borneo Secrets Manager.

FILESYSTEM_DISK=local

BUNNYCDN_STORAGE_ZONE=your-storage-zone
BUNNYCDN_API_KEY=your-storage-zone-password-or-api-key
BUNNYCDN_REGION=sg
BUNNYCDN_PULL_ZONE=https://pull-zone.b-cdn.net
BUNNYCDN_CDN_URL=https://pull-zone.b-cdn.net

BORNEO_SECRET_ENABLED=false

Optional Borneo Secrets Manager setup

Turn this on only when the package should resolve the Bunny.net API key from your Borneo Secrets Manager API.

FILESYSTEM_DISK=local

BUNNYCDN_STORAGE_ZONE=your-storage-zone
BUNNYCDN_REGION=sg
BUNNYCDN_PULL_ZONE=https://pull-zone.b-cdn.net
BUNNYCDN_CDN_URL=https://pull-zone.b-cdn.net

BORNEO_SECRET_ENABLED=true
BORNEO_SECRET_URI=https://key.btekno.id
BORNEO_SECRET_API_KEY=your-borneo-secret-manager-api-key

BUNNY_SECRET_KEY=bunny-secrets-pass
BUNNY_SECRET_FILE=bunny_api_key.txt
BUNNY_SECRET_CACHE_FILE=true

Legacy env names are still supported:

SECRET_ENABLED=true
SECRET_URI=https://key.btekno.id
SECRET_KEY=your-borneo-secret-manager-api-key

API key resolution order:

  1. BUNNYCDN_API_KEY
  2. storage/app/{BUNNY_SECRET_FILE}
  3. Borneo Secrets Manager, only when BORNEO_SECRET_ENABLED=true

Recommendation: keep FILESYSTEM_DISK=local for Laravel and Livewire temporary uploads. Use the bunnycdn disk only when storing final files.

Usage

Upload with the facade

use Novay\BunnySecret\BunnySecret;

$filePath = BunnySecret::uploadCDN(
    file: $request->file('photo'),
    path: 'btekno/storage',
    filename: str()->slug('bride-' . $name) . '-' . uniqid(),
);

if ($filePath === false) {
    throw new RuntimeException('Failed to upload photo to Bunny.net Storage.');
}

$url = BunnySecret::showCDN($filePath);

Delete a file

BunnySecret::deleteCDN('/btekno/storage/photo.jpg');

Check file existence

if (BunnySecret::existsCDN('/btekno/storage/photo.jpg')) {
    // file exists
}

Use Laravel Storage

use Illuminate\Support\Facades\Storage;

Storage::disk('bunnycdn')->put('demo/index.html', '<h1>Hello Bunny</h1>');
$url = Storage::disk('bunnycdn')->url('demo/index.html');
Storage::disk('bunnycdn')->delete('demo/index.html');

Optional Borneo Secrets Manager API

The Borneo Secrets Manager feature remains available, but it is optional and disabled by default. When disabled, the package will not call the secret API during filesystem boot.

use Novay\BunnySecret\BunnySecret;

if (BunnySecret::hasSecretManager()) {
    $value = BunnySecret::getSecret('bunny-secrets-pass');
}

BunnySecret::storeSecret('another-key', 'secret-value');
BunnySecret::deleteSecret('another-key');

storeSecret() and deleteSecret() intentionally throw a clear exception when Borneo Secrets Manager is disabled or incomplete, because those are explicit write/delete actions. getSecret() returns null when the integration is disabled, not configured, or the secret cannot be resolved.

Configuration

The package publishes config/bunnycdn.php.

You do not need to manually add a bunnycdn disk to config/filesystems.php; the package registers it at runtime from config/bunnycdn.php. If you do define filesystems.disks.bunnycdn, your app-level values override the package defaults.

Failure behavior

This package avoids the previous circular failure where the service provider tried to read the API key through Laravel's default Storage disk before the custom bunnycdn driver existed.

Current behavior:

  • The bunnycdn driver is always registered during boot.
  • Borneo Secrets Manager is disabled by default and used only when BORNEO_SECRET_ENABLED=true.
  • Missing storage_zone or api_key throws a clear BunnySecretException when the disk is used.
  • Facade helpers such as uploadCDN() catch upload errors, log context, and return false for backward compatibility.

Useful commands after changing config

php artisan optimize:clear
php artisan package:discover
composer dump-autoload

License

This package is licensed under the MIT License.

novay/bunny-secrets 适用场景与选型建议

novay/bunny-secrets 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 73 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「filesystem」 「cdn」 「laravel」 「secrets」 「Flysystem」 「bunny」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 novay/bunny-secrets 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 novay/bunny-secrets 我们能提供哪些服务?
定制开发 / 二次开发

基于 novay/bunny-secrets 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 73
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-13