getsolaris/laravel-aws-secretsmanager

This package is abandoned and no longer maintained. No replacement package was suggested.

A Laravel package to retrieve key management from AWS Secrets Manager

v1.0.0 2022-09-25 13:36 UTC

This package is auto-updated.

Last update: 2023-06-20 23:28:24 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.