Skip to content

Commit c5a779a

Browse files
authored
Support Laravel 11 and Use env() for dynamic configuration (#29)
* Support Laravel 11 * Use env() in config file * Update README with environment based configuration
1 parent a84e621 commit c5a779a

File tree

8 files changed

+106
-76
lines changed

8 files changed

+106
-76
lines changed

.github/run-tests-L7.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.github/workflows/run-tests-l10.yml renamed to .github/workflows/run-tests-l11.yml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
name: "Run Tests - L10"
1+
name: "Run Tests - L11"
22

33
on: [push, pull_request]
44

55
jobs:
66
test:
7-
87
runs-on: ubuntu-latest
98
strategy:
109
fail-fast: false
1110
matrix:
12-
laravel: [8.*, 9.*, 10.*]
13-
php: [8.1, 8.0, 7.4, 7.3]
11+
laravel: [8.*, 9.*, 10.*, 11.*]
12+
php: [8.3, 8.1, 8.0, 7.4, 7.3]
1413
dependency-version: [prefer-lowest, prefer-stable]
1514
include:
1615
- laravel: 8.*
@@ -19,19 +18,37 @@ jobs:
1918
testbench: 7.*
2019
- laravel: 10.*
2120
testbench: 8.*
21+
- laravel: 11.*
22+
testbench: 9.*
2223
exclude:
24+
- laravel: 8.*
25+
php: 8.0
2326
- laravel: 8.*
2427
php: 8.1
28+
- laravel: 8.*
29+
php: 8.3
2530
- laravel: 9.*
2631
php: 7.3
2732
- laravel: 9.*
2833
php: 7.4
34+
- laravel: 9.*
35+
php: 8.3
2936
- laravel: 10.*
3037
php: 7.3
3138
- laravel: 10.*
3239
php: 7.4
3340
- laravel: 10.*
3441
php: 8.0
42+
- laravel: 10.*
43+
php: 8.3
44+
- laravel: 11.*
45+
php: 7.3
46+
- laravel: 11.*
47+
php: 7.4
48+
- laravel: 11.*
49+
php: 8.0
50+
- laravel: 11.*
51+
php: 8.1
3552

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

@@ -49,12 +66,24 @@ jobs:
4966
uses: shivammathur/setup-php@v2
5067
with:
5168
php-version: ${{ matrix.php }}
52-
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
69+
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
70+
5371
coverage: none
5472

73+
- name: Debug PHP Setup
74+
run: |
75+
php -v
76+
php -m
77+
5578
- name: Install dependencies
5679
run: |
5780
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "symfony/console:>=4.3.4" "mockery/mockery:^1.3.2" --no-interaction --no-update
5881
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
82+
83+
- name: Migrate PHPUnit Configuration
84+
run: ./vendor/bin/phpunit --migrate-configuration || true
85+
5986
- name: Execute tests
60-
run: vendor/bin/phpunit
87+
run: |
88+
vendor/bin/phpunit --no-coverage
89+

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,37 @@ AWS_SECRETS_TAG_VALUE=production
3232

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

35+
### Other Environment-based Configuration
36+
37+
#### Enabled environments
38+
39+
Specify which environments should have AWS Secrets enabled:
40+
41+
`AWS_SECRETS_ENABLED_ENV=production,staging`
42+
43+
Default: `production`
44+
45+
#### Overwritable Variables Config
46+
47+
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.
48+
49+
For example:
50+
51+
`VARIABLES_CONFIG_KEYS=APP_KEY:app.key,OTHER_KEY:app.other_key`
52+
53+
This setup allows `APP_KEY` to overwrite `app.key` in the config, and `OTHER_KEY` to overwrite `app.other_key`.
54+
55+
Default Behavior: If `AWS_SECRETS_VARIABLES_CONFIGS` is not set or is empty, no variables will be set for config overwriting.
56+
57+
#### Cache Settings
58+
59+
For example:
60+
```
61+
AWS_SECRETS_CACHE_ENABLED=true
62+
AWS_SECRETS_CACHE_EXPIRY=60
63+
AWS_SECRETS_CACHE_STORE=file
64+
```
65+
3566
### Setting up AWS Secrets
3667

3768
1. Store New Secret.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^7.1 || ^7.3 || ^7.4 || ^8.0 || ^8.1",
19+
"php": "^7.1 || ^7.3 || ^7.4 || ^8.0 || ^8.1 || ^8.3",
2020
"aws/aws-sdk-php": "^3.145 || ^3.219 || ^3.263",
21-
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.8 || ^10.6"
21+
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.8 || ^10.6 || ^11.0"
2222
},
2323
"require-dev": {
2424
"orchestra/testbench": "^3.8 || ^5.0 || ^6.0 || ^7.4 || ^8.2",
25-
"phpunit/phpunit": "^7.0||^8.4||^9.3.3"
25+
"phpunit/phpunit": "^7.0 || ^8.4 || ^9.3.3 || ^11.0.1"
2626
},
2727
"autoload": {
2828
"psr-4": {

config/config.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@
3636
|
3737
*/
3838

39-
'enabled-environments' => [
40-
'production',
41-
],
39+
'enabled-environments' => array_filter(explode(',', env('AWS_SECRETS_ENABLED_ENV', 'production'))),
4240

4341
/*
4442
|--------------------------------------------------------------------------
@@ -48,10 +46,19 @@
4846
| Some (not all) variables are set into the config, as such updating the env() will not overwrite
4947
| the config cached values. The variables below will overwrite the config.
5048
|
49+
| Example:
50+
| .env
51+
| VARIABLES_CONFIG_KEYS=APP_KEY:app.key,OTHER_KEY:app.other_key
52+
|
5153
*/
52-
'variables-config' => [
53-
'APP_KEY' => 'app.key',
54-
],
54+
55+
'variables-config' => collect(array_filter(explode(',', env('AWS_SECRETS_VARIABLES_CONFIGS', ''))))
56+
->mapWithKeys(function ($pair) {
57+
[$envKey, $configKey] = explode(':', $pair);
58+
59+
return [$envKey => $configKey];
60+
})
61+
->toArray(),
5562

5663
/*
5764
|--------------------------------------------------------------------------
@@ -63,7 +70,7 @@
6370
|
6471
*/
6572

66-
'cache-enabled' => true, // boolean
73+
'cache-enabled' => env('AWS_SECRETS_CACHE_ENABLED', true),
6774

6875
/*
6976
|--------------------------------------------------------------------------
@@ -74,7 +81,7 @@
7481
|
7582
*/
7683

77-
'cache-expiry' => 30, // minutes
84+
'cache-expiry' => env('AWS_SECRETS_CACHE_EXPIRY', 30),
7885

7986
/*
8087
|--------------------------------------------------------------------------
@@ -86,7 +93,7 @@
8693
|
8794
*/
8895

89-
'cache-store' => 'file',
96+
'cache-store' => env('AWS_SECRETS_CACHE_STORE', 'file'),
9097

9198
/*
9299
|--------------------------------------------------------------------------

phpunit.xml.dist

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
35
backupGlobals="false"
46
backupStaticAttributes="false"
57
colors="true"
@@ -14,16 +16,19 @@
1416
<directory>tests</directory>
1517
</testsuite>
1618
</testsuites>
17-
<filter>
18-
<whitelist>
19+
<coverage processUncoveredFiles="true">
20+
<include>
1921
<directory suffix=".php">src/</directory>
20-
</whitelist>
21-
</filter>
22+
</include>
23+
<report>
24+
<html outputDirectory="build/coverage"/>
25+
<text outputFile="build/coverage.txt"/>
26+
<clover outputFile="build/logs/clover.xml"/>
27+
</report>
28+
</coverage>
2229
<logging>
23-
<log type="tap" target="build/report.tap"/>
24-
<log type="junit" target="build/report.junit.xml"/>
25-
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
26-
<log type="coverage-text" target="build/coverage.txt"/>
27-
<log type="coverage-clover" target="build/logs/clover.xml"/>
30+
<junit outputFile="build/report.junit.xml"/>
31+
<testdoxHtml outputFile="build/testdox.html"/>
32+
<testdoxText outputFile="build/testdox.txt"/>
2833
</logging>
2934
</phpunit>

src/LaravelAwsSecretsManager.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ class LaravelAwsSecretsManager
1515
protected $cacheExpiry;
1616
protected $cacheStore;
1717
protected $debug;
18-
protected $enabledEnvironments;
19-
protected $listTag;
18+
protected array $enabledEnvironments;
19+
protected bool $keyRotation;
20+
protected string $listTagName = '';
21+
protected string $listTagValue = '';
2022

2123
public function __construct()
2224
{

tests/ExampleTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tapp\LaravelAwsSecretsManager\Tests;
44

55
use Orchestra\Testbench\TestCase;
6+
use PHPUnit\Framework\Attributes\Test;
67
use Tapp\LaravelAwsSecretsManager\LaravelAwsSecretsManagerServiceProvider;
78

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

15-
/** @test */
16+
#[Test]
1617
public function true_is_true()
1718
{
1819
$this->assertTrue(true);

0 commit comments

Comments
 (0)