PHP code example of nohnaimer / yii2-vault-project-configuration
1. Go to this page and download the library: Download nohnaimer/yii2-vault-project-configuration library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nohnaimer / yii2-vault-project-configuration example snippets
...
const PROJECT_CONFIGURATION_USE_DEFAULT = YII_ENV_DEV;
...
$db_name = config('db.name', 'site-db-name');
$db_host = config('db.host', 'localhost');
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => "mysql:host={$db_host};dbname={$db_name}",
'username' => config('db.username', 'root'),
'password' => config('db.password', '****'),
'enableSchemaCache' => true,
'charset' => 'utf8',
],
],
];
return [
'components' => [
'vault' => [
'class' => nohnaimer\config\storage\VaultStorage::class,
'kv' => [
'class' => nohnaimer\vault\services\KVv1::class,
'path' => '/kv',
'client' => [
'class' => nohnaimer\vault\Client::class,
'url' => 'url',
'token' => 'token',
],
],
],
],
];
class m221103_161325_vault_init extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$vault = Yii::$app->vault;
//add
$vault->setValue('/my/secret/key', 'value');
//delete secret with all keys
$vault->deleteValue('/my/secret/key');
}
}
yaml
...
php:
image: php:latest
container_name: php
restart: on-failure
working_dir: /var/www
environment:
VAULT_ADDR: https://127:0:0:1:8200/
VAULT_TOKEN: hvs.hrpvk3rEpD2HaHckeb976Ppw
volumes:
- .:/var/www:cached
depends_on:
- postgres
...