jc-it/yii2-secrets 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jc-it/yii2-secrets

Composer 安装命令:

composer require jc-it/yii2-secrets

包简介

Secrets storage and extractor for Yii2

README 文档

README

codecov Continous integration Packagist Total Downloads Packagist Monthly Downloads GitHub tag (latest by date) Packagist Version

This extension provides secret storage and extractor for Yii2.

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require jc-it/yii2-secrets

or add

"jc-it/yii2-secrets": "^<latest version>"

to the require section of your composer.json file.

Configuration

Secrets

It is recommended to use this package only in configuration files before your application is loaded, this way they won't be dumped by your application on chrashes or something unexpected.

$secrets = new \JCIT\secrets\SecretsService(
    new \JCIT\secrets\storages\Chained(
        new \JCIT\secrets\storages\Cache(getenv()),
        new \JCIT\secrets\storages\Json('/run/env.json'),
        new \JCIT\secrets\storages\Filesystem(__DIR__ . '/secrets'),
    )
);

Note that the order in the Chained storage does matter, wherever a secret is found first that value will be returned.

Secret extraction

When deploying a new environment it can be a hassle finding out what all secrets are to be configured. This package contains a console command to extract the secret usages.

  • Create an action in a console controller
      class SecretsController extends Controller
      {
          public function actions(): array
          {
              return [
                  'extract' => [
                      'class' => Extract::class,
                      'calls' => ['$secrets->get', '$secrets->getAndThrowOnNull'],
                      'sourcePath' => '@app/',
                  ],
              ];
          }
      }
  • In dependency injection add the storage (which should only be used for the extract command)
    ...
    'container' => [
        'definitions' => [
            \JCIT\secrets\interfaces\StorageInterface::class => function() {
                return new \JCIT\secrets\storages\Filesystem(__DIR__ . '/../../../secrets')
            }
        ]
    ],

Credits

统计信息

  • 总下载量: 40
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固