getsolaris / laravel-aws-secretsmanager
A Laravel package to retrieve key management from AWS Secrets Manager
Requires
- php: ^8.0
- ext-json: *
- aws/aws-sdk-php: ^3.0
- illuminate/support: ^6.0 || ^7.0 || ^8.0 || ^9.0
- spatie/data-transfer-object: ^3.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2023-06-20 23:28:24 UTC
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.