getsolaris/laravel-aws-secretsmanager
最新稳定版本:v1.0.0
Composer 安装命令:
composer require getsolaris/laravel-aws-secretsmanager
包简介
A Laravel package to retrieve key management from AWS Secrets Manager
README 文档
README
Communication via AWS Secrets Manager may incur unnecessary charges.
So we developed a package that simply caches.
Installation
You can install the package via composer:
composer require getsolaris/laravel-aws-secretsmanager
You can publish the config file with:
php artisan vendor:publish --provider="Getsolaris\LaravelAwsSecretsManager\AwsSecretsManagerServiceProvider" --tag="config"
Usage
You can choose cache driver and cache ttl
default cache driver is filesystem (storage/framework/cache/data)
# .env CACHE_DRIVER=redis CACHE_TTL=86400 # aws configuration AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=
Required permissions: secretsmanager:GetSecretValue
If the secret is encrypted using a customer-managed key instead of the AWS managed key aws/secretsmanager
Example
createSecret
<?php namespace App\Services; use Getsolaris\LaravelAwsSecretsManager\AwsSecretsManager; class FacebookApiService extends Service { protected AwsSecretsManager $client; public function __construct() { $this->client = new AwsSecretsManager(); } /** * @param string $secretId * @return array * @throws \Exception */ public function createFacebookSecret(): \Aws\Result { $appId = env('FACEBOOK_APP_ID', 'test_app_id_123'); $appSecret = env('FACEBOOK_APP_SECRET', 'test_app_secret_123'); $createSecret = new CreateSecretDto( Name: 'prod/facebook/secret', SecretString: [ 'app_id' => $appId, 'app_secret' => $appSecret, ], ); $createSecret = new CreateSecretDto([ 'Name' => 'prod/facebook/secret', 'SecretString' => [ 'app_id' => $appId, 'app_secret' => $appSecret, ], ]); return $this->client->createSecret($createSecret); } }
getSecret
<?php namespace App\Services; use Getsolaris\LaravelAwsSecretsManager\AwsSecretsManager; class FacebookApiService extends Service { protected AwsSecretsManager $client; public function __construct() { $this->client = new AwsSecretsManager(); } /** * @param string $secretId * @return array * @throws \Exception */ public function getFacebookSecret(): \Aws\Result { return $this->client->getSecret('prod/facebook/secret'); } }
getSecretValue
<?php namespace App\Services; use Getsolaris\LaravelAwsSecretsManager\AwsSecretsManager; class FacebookApiService extends Service { protected AwsSecretsManager $client; public function __construct() { $this->client = new AwsSecretsManager(); } /** * @param string $secretId * @return array * @throws \Exception */ public function getFacebookSecretValue(): array { return $this->client->getSecretValue('prod/facebook/secret'); } }
Resource
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-25