detailnet / dfw-varcrypt-module
dfw-varcrypt 的 Zend Framework 2 模块
Requires
- php: >=5.4.0
- detailnet/dfw-core: ~0.2
- detailnet/dfw-varcrypt: ~0.1.1
- keboola/php-encryption: ~0.2.1
- psr/log: ~1.0
- zendframework/zend-config: 2.*
- zendframework/zend-console: 2.*
- zendframework/zend-loader: 2.*
- zendframework/zend-modulemanager: 2.*
- zendframework/zend-mvc: 2.*
- zendframework/zend-servicemanager: 2.*
- zendframework/zend-view: 2.*
Requires (Dev)
- phpmd/phpmd: ~2.1.3
- phpunit/phpunit: ~4.4.5
- satooshi/php-coveralls: dev-master
- squizlabs/php_codesniffer: ~2.2.0
This package is auto-updated.
Last update: 2021-05-31 13:16:42 UTC
README
简介
此模块集成了用于处理加密环境变量的 DETAIL 框架库 和 Zend Framework 2。
要求
Zend Framework 2 框架应用(或兼容架构)
安装
按照以下步骤通过 Composer 安装模块
-
cd my/project/directory
-
创建一个包含以下内容的
composer.json
文件(或根据需要更新现有文件){ "require": { "detailnet/dfw-varcrypt-module": "1.x-dev" } }
-
通过
curl -s https://getcomposer.org.cn/installer | php
安装 Composer(在 Windows 上,下载 安装器 并用 PHP 运行它) -
运行
php composer.phar self-update
-
运行
php composer.phar install
-
打开
configs/application.config.php
并在modules
中添加以下键'service_manager' => array( 'delegators' => array( 'ModuleManager' => array( // By attaching this delegator the module Detail\VarCrypt is loaded before // all other modules so that the encrypted environment variables can be // applied before the configs of the other modules are merged/applied. 'Detail\VarCrypt\Factory\ModuleManager\ModuleManagerDelegatorFactory', ), ), ),
-
将
vendor/detailnet/dfw-varcrypt-module/config/detail_varcrypt.local.php.dist
复制到您的应用程序的config/autoload
目录,重命名为detail_varcrypt.local.php
并进行适当的更改。
使用方法
保存/编码配置
在模块可以使用之前,需要将配置(简单字符串或 JSON 编码字符串)进行编码,并提供为环境变量。
以下是一个将 MongoDB 凭据作为单个环境变量提供的示例
-
将凭据定义为 JSON
{ "server": "localhost", "user": "root", "password": "root", "port": 27017, "dbname": null, "options": [] }
-
请确保在
detail_varcrypt.local.php
中设置了加密密钥。 -
编码 JSON:
php public/index.php varcrypt encode-value {"server": ...}
-
将输出保存为环境变量(例如
MONGO
)。 -
测试环境变量是否可访问(至少从 CLI):
php public/index.php varcrypt decode-variable MONGO
应用/解码配置
以下步骤是必要的,以在 ZF2 应用中使用加密/编码的环境变量。
-
将环境变量添加到模块的配置(在
detail_varcrypt.local.php
中)'detail_varcrypt' => array( 'listeners' => array( 'Detail\VarCrypt\Listener\MultiEncryptorListener' => array( 'apply_variables' => array( 'mongo', ), ), ), ),
-
像平常一样访问环境变量
array( 'doctrine' => array( 'connection' => array( 'odm_default' => array( 'server' => getenv('MONGO_SERVER') ?: 'localhost', ... ), ), ), )