dvsa/laminas-config-cloud-parameters

v2.0.0 2024-08-30 08:46 UTC

This package is auto-updated.

Last update: 2024-10-30 09:11:03 UTC


README

This Composer library facilitates the use of Laminas config placeholders, enabling the substitution of values with those supplied by cloud services dedicated to variable storage using Symfony ParameterBag.

How to use

In a Laminas MVC application

  1. Configure the Cloud providers in your configuration:

    <?php
    
    use Dvsa\LaminasConfigCloudParameters\Provider\SecretsManager;
    use Dvsa\LaminasConfigCloudParameters\Cast\Boolean;
    use Dvsa\LaminasConfigCloudParameters\Cast\Integer;
    
    return [
        'config_parameters' => [
            'providers' => [
                SecretsManager::class => [
                    'example-secret',
                    // ...
                ],
                
                // ...
            ],
    
            'casts' => [
                // Uses `symfony/property-access` to access the property. See https://symfony.com/doc/current/components/property_access.html#reading-from-arrays.
                '[foo]' => Boolean::class,
                '[bar][nested]' => Integer::class,
    
                // ...
            ],
        ],
        // ...
    ];
  2. Register the module with the Laminas ModuleManager:

    <?php
    // module.config.php
    
    return [
        'Dvsa\LaminasConfigCloudParameters',
        // ...
    ];
  3. Placeholders can be then added to the Laminas config:

    return [
        'foo' => '%bar%',
        'bar' => [
            'nested' => '%baz%',
        ],
    ];

Available cloud parameter providers

AWS

Secrets Manager

Only secrets that are stored in key/value pairs are supported.

Example configuration:

<?php

return [
    'config_parameters' => [
        'providers' => [
            SecretsManager::class => [
                'global-secrets',
                sprintf('environment-%s-secrets', $environment),
            ],
            
            // ...
        ],
    ],
];

Parameter Store

Parameters will be loaded recursively by path. The key will be parameter name without the path provided as the key.

Example configuration:

<?php

use Dvsa\LaminasConfigCloudParameters\Provider\ParameterStore;

return [
    'config_parameters' => [
        'providers' => [
            ParameterStore::class => [
                '/global',
                sprintf('/env-%s', $environment),
            ],
            
            // ...
        ],
    ],
];