Skip to content

Support Laravel 11 and Use env() for dynamic configuration #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions .github/run-tests-L7.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
name: "Run Tests - L10"
name: "Run Tests - L11"

on: [push, pull_request]

jobs:
test:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
laravel: [8.*, 9.*, 10.*]
php: [8.1, 8.0, 7.4, 7.3]
laravel: [8.*, 9.*, 10.*, 11.*]
php: [8.3, 8.1, 8.0, 7.4, 7.3]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
Expand All @@ -19,19 +18,37 @@ jobs:
testbench: 7.*
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*
exclude:
- laravel: 8.*
php: 8.0
- laravel: 8.*
php: 8.1
- laravel: 8.*
php: 8.3
- laravel: 9.*
php: 7.3
- laravel: 9.*
php: 7.4
- laravel: 9.*
php: 8.3
- laravel: 10.*
php: 7.3
- laravel: 10.*
php: 7.4
- laravel: 10.*
php: 8.0
- laravel: 10.*
php: 8.3
- laravel: 11.*
php: 7.3
- laravel: 11.*
php: 7.4
- laravel: 11.*
php: 8.0
- laravel: 11.*
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

Expand All @@ -49,12 +66,24 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
extensions: mbstring, zip, curl, pcntl, pdo, sqlite, pdo_sqlite, iconv, xdebug, mysqlnd, bcmath, bz2, dba, enchant, gd, gmp, igbinary, imagick, imap, intl, ldap, memcache, mongodb, msgpack, mysqli, odbc, pdo_dblib, pdo_firebird, pdo_mysql, pdo_odbc, pdo_pgsql, pdo_sqlsrv, pgsql, pspell, redis, snmp, soap, sqlsrv, tidy, yaml, zmq, memcached, ds

coverage: none

- name: Debug PHP Setup
run: |
php -v
php -m

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "symfony/console:>=4.3.4" "mockery/mockery:^1.3.2" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

- name: Migrate PHPUnit Configuration
run: ./vendor/bin/phpunit --migrate-configuration || true

- name: Execute tests
run: vendor/bin/phpunit
run: |
vendor/bin/phpunit --no-coverage

31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,37 @@ AWS_SECRETS_TAG_VALUE=production

`AWS_SECRETS_TAG_NAME` and `AWS_SECRETS_TAG_VALUE` are used to pull down all the secrets that match the tag key/value.

### Other Environment-based Configuration

#### Enabled environments

Specify which environments should have AWS Secrets enabled:

`AWS_SECRETS_ENABLED_ENV=production,staging`

Default: `production`

#### Overwritable Variables Config

Specify which variables should be able to overwrite the config using the `AWS_SECRETS_VARIABLES_CONFIGS` key in the `.env` file. The format is a comma-separated list of `ENV_VARIABLE_NAME:CONFIG_KEY` pairs.

For example:

`VARIABLES_CONFIG_KEYS=APP_KEY:app.key,OTHER_KEY:app.other_key`

This setup allows `APP_KEY` to overwrite `app.key` in the config, and `OTHER_KEY` to overwrite `app.other_key`.

Default Behavior: If `AWS_SECRETS_VARIABLES_CONFIGS` is not set or is empty, no variables will be set for config overwriting.

#### Cache Settings

For example:
```
AWS_SECRETS_CACHE_ENABLED=true
AWS_SECRETS_CACHE_EXPIRY=60
AWS_SECRETS_CACHE_STORE=file
```

### Setting up AWS Secrets

1. Store New Secret.
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
}
],
"require": {
"php": "^7.1 || ^7.3 || ^7.4 || ^8.0 || ^8.1",
"php": "^7.1 || ^7.3 || ^7.4 || ^8.0 || ^8.1 || ^8.3",
"aws/aws-sdk-php": "^3.145 || ^3.219 || ^3.263",
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.8 || ^10.6"
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.8 || ^10.6 || ^11.0"
},
"require-dev": {
"orchestra/testbench": "^3.8 || ^5.0 || ^6.0 || ^7.4 || ^8.2",
"phpunit/phpunit": "^7.0||^8.4||^9.3.3"
"phpunit/phpunit": "^7.0 || ^8.4 || ^9.3.3 || ^11.0.1"
},
"autoload": {
"psr-4": {
Expand Down
25 changes: 16 additions & 9 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
|
*/

'enabled-environments' => [
'production',
],
'enabled-environments' => array_filter(explode(',', env('AWS_SECRETS_ENABLED_ENV', 'production'))),

/*
|--------------------------------------------------------------------------
Expand All @@ -48,10 +46,19 @@
| Some (not all) variables are set into the config, as such updating the env() will not overwrite
| the config cached values. The variables below will overwrite the config.
|
| Example:
| .env
| VARIABLES_CONFIG_KEYS=APP_KEY:app.key,OTHER_KEY:app.other_key
|
*/
'variables-config' => [
'APP_KEY' => 'app.key',
],

'variables-config' => collect(array_filter(explode(',', env('AWS_SECRETS_VARIABLES_CONFIGS', ''))))
->mapWithKeys(function ($pair) {
[$envKey, $configKey] = explode(':', $pair);

return [$envKey => $configKey];
})
->toArray(),

/*
|--------------------------------------------------------------------------
Expand All @@ -63,7 +70,7 @@
|
*/

'cache-enabled' => true, // boolean
'cache-enabled' => env('AWS_SECRETS_CACHE_ENABLED', true),

/*
|--------------------------------------------------------------------------
Expand All @@ -74,7 +81,7 @@
|
*/

'cache-expiry' => 30, // minutes
'cache-expiry' => env('AWS_SECRETS_CACHE_EXPIRY', 30),

/*
|--------------------------------------------------------------------------
Expand All @@ -86,7 +93,7 @@
|
*/

'cache-store' => 'file',
'cache-store' => env('AWS_SECRETS_CACHE_STORE', 'file'),

/*
|--------------------------------------------------------------------------
Expand Down
25 changes: 15 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
Expand All @@ -14,16 +16,19 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<junit outputFile="build/report.junit.xml"/>
<testdoxHtml outputFile="build/testdox.html"/>
<testdoxText outputFile="build/testdox.txt"/>
</logging>
</phpunit>
6 changes: 4 additions & 2 deletions src/LaravelAwsSecretsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class LaravelAwsSecretsManager
protected $cacheExpiry;
protected $cacheStore;
protected $debug;
protected $enabledEnvironments;
protected $listTag;
protected array $enabledEnvironments;
protected bool $keyRotation;
protected string $listTagName = '';
protected string $listTagValue = '';

public function __construct()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/ExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tapp\LaravelAwsSecretsManager\Tests;

use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;
use Tapp\LaravelAwsSecretsManager\LaravelAwsSecretsManagerServiceProvider;

class ExampleTest extends TestCase
Expand All @@ -12,7 +13,7 @@ protected function getPackageProviders($app)
return [LaravelAwsSecretsManagerServiceProvider::class];
}

/** @test */
#[Test]
public function true_is_true()
{
$this->assertTrue(true);
Expand Down
Loading