wyn/laravel-google-secret-manager

使用 Google Secrets Manager (GSM) 管理环境密钥。

v1.1.0 2024-07-21 20:04 UTC

This package is not auto-updated.

Last update: 2024-09-30 19:06:46 UTC


README

一个 Laravel 包,用于使用 Google Secrets Manager (GSM) 管理和集成环境密钥

安装

您可以通过 composer 安装此包

composer require wyn/laravel-google-secret-manager

发布配置

php artisan vendor:publish --provider="wyn\GoogleSecretManager\GoogleSecretManagerServiceProvider"

配置

设置 Google Cloud 项目

  • 确保您已经设置了 Google Cloud 项目。
  • 为您的项目启用 Secret Manager API。
  • 根据需要,在 Secret Manager 中创建密钥。

添加环境变量

将您的 Google Cloud 项目 ID 和密钥 ID 添加到您的 .env 文件中

GOOGLE_PROJECT_ID=your-google-cloud-project-id
GOOGLE_SECRET_ID=your-secret-id

Google 凭证

确保您的应用程序可以访问您的 Google Cloud 凭证。您可以将 GOOGLE_APPLICATION_CREDENTIALS 环境变量设置为指向您的服务帐户 JSON 密钥文件

GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/service-account-file.json

使用

将密钥注入到环境变量中

您可以使用 injectSecretToEnv 方法将密钥注入到环境变量中。

use Illuminate\Support\Facades\App;$secretManager = App::make('google.secret.manager');
// Inject the secret into environment variables
$secretManager->injectSecretToEnv(env('GOOGLE_PROJECT_ID'), env('GOOGLE_SECRET_ID'), 'YOUR_ENV_KEY');

将密钥注入到 Laravel 配置中

您可以使用 injectSecretToConfig 方法将密钥注入到 Laravel 配置设置中。

use Illuminate\Support\Facades\App;$secretManager = App::make('google.secret.manager');
// Inject the secret into Laravel configuration
$secretManager->injectSecretToConfig(env('GOOGLE_PROJECT_ID'), env('GOOGLE_SECRET_ID'), 'config.key');

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件