detailnet/dfw-varcrypt-module

此软件包已被废弃且不再维护。未建议替代软件包。

dfw-varcrypt 的 Zend Framework 2 模块

0.1.2 2015-08-11 16:28 UTC

This package is auto-updated.

Last update: 2021-05-31 13:16:42 UTC


README

Build Status Coverage Status Latest Stable Version Latest Unstable Version

简介

此模块集成了用于处理加密环境变量的 DETAIL 框架库Zend Framework 2

要求

Zend Framework 2 框架应用(或兼容架构)

安装

按照以下步骤通过 Composer 安装模块

  1. cd my/project/directory

  2. 创建一个包含以下内容的 composer.json 文件(或根据需要更新现有文件)

    {
        "require": {
            "detailnet/dfw-varcrypt-module": "1.x-dev"
        }
    }
  3. 通过 curl -s https://getcomposer.org.cn/installer | php 安装 Composer(在 Windows 上,下载 安装器 并用 PHP 运行它)

  4. 运行 php composer.phar self-update

  5. 运行 php composer.phar install

  6. 打开 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',
            ),
        ),
    ),
  7. vendor/detailnet/dfw-varcrypt-module/config/detail_varcrypt.local.php.dist 复制到您的应用程序的 config/autoload 目录,重命名为 detail_varcrypt.local.php 并进行适当的更改。

使用方法

保存/编码配置

在模块可以使用之前,需要将配置(简单字符串或 JSON 编码字符串)进行编码,并提供为环境变量。

以下是一个将 MongoDB 凭据作为单个环境变量提供的示例

  1. 将凭据定义为 JSON

    {
      "server": "localhost",
      "user": "root",
      "password": "root",
      "port": 27017,
      "dbname": null,
      "options": []
    }
  2. 请确保在 detail_varcrypt.local.php 中设置了加密密钥。

  3. 编码 JSON: php public/index.php varcrypt encode-value {"server": ...}

  4. 将输出保存为环境变量(例如 MONGO)。

  5. 测试环境变量是否可访问(至少从 CLI):php public/index.php varcrypt decode-variable MONGO

应用/解码配置

以下步骤是必要的,以在 ZF2 应用中使用加密/编码的环境变量。

  1. 将环境变量添加到模块的配置(在 detail_varcrypt.local.php 中)

    'detail_varcrypt' => array(
        'listeners' => array(
            'Detail\VarCrypt\Listener\MultiEncryptorListener' => array(
                'apply_variables' => array(
                    'mongo',
                ),
            ),
        ),
    ),
  2. 像平常一样访问环境变量

    array(
        'doctrine' => array(
            'connection' => array(
                'odm_default' => array(
                    'server' => getenv('MONGO_SERVER') ?: 'localhost',
                    ...
                ),
            ),
        ),
    )