定制 brendantwhite/databasemask 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

brendantwhite/databasemask

Composer 安装命令:

composer require brendantwhite/databasemask

包简介

Mask data from Production using Faker to use safely elsewhere

README 文档

README

Mask data from Production using Faker to use safely elsewhere.

Use Case

Ever wanted to use a copy of your Laravel project's Production database in your test environments? But you can't, because it's a security risk?

Now, you can get a copy of the Production database and mask just the values that need masking - names, phone numbers, email addresses etc - while keeping your data otherwise intact.

Installation

From the command line run:

composer require brendantwhite/databasemask

Configuration

First, ensure you have a Model Factory defined for each Eloquent model class that you want to mask.

Then, add a $masked property to your Eloquent model classes, specifying which attributes on your model should be masked.

    <?php

    // in app/Models/User.php

    /**
     * The attributes that should be masked by DatabaseMask.
     *
     * @var array
     */
    protected $masked = [
        'name',
        'email',
        'password',
    ];

If you have any models that you don't need to be masked at all, add the $masked property anyway, but make it an empty array.

    <?php

    // in app/Models/SomeOtherModel.php

    /**
     * The attributes that should be masked by DatabaseMask.
     *
     * @var array
     */
    protected $masked = [];

Usage

To mask your data, run the php artisan dbm:mask command. This will loop through all your Eloquent models, looking for the $masked property.

  • If the $masked property is null or the empty set, that model will be skipped.

  • If the $masked property is missing, that model will be flagged with a warning.

  • If the $masked property is not empty, but no Factory has been created for that model, an error is returned.

But if the $masked property contains field names, and a Factory has been created, then the fields in the $masked property will be replaced with Faker values. All other fields will be left untouched.

Backup and Restore

This package also contains light wrappers around Spatie's excellent laravel-db-snapshots package, to make backups and restores even easier.

To use these commands you will first need to install laravel-db-snapshots as per their installation instructions.

Then, run php artisan dbm:backup to create a backup file of your database on your snapshots disk. Run php artisan dbm:restore to choose a backup file and restore it to your current enviroment.

Generally, you'll want to backup from your Production enviornment, and restore to some other environment, and then mask that data in the other environment.

You do not need to install laravel-db-snapshots if you only want to use the dbm:mask command.

Testing DatabaseMask

TODO: write some tests.

Disclaimer

I cannot, and do not, guarantee that using DatabaseMask will make your data 100% de-identified.

I can and will make a good-faith effort to ensure that, when configured correctly, DatabaseMask will remove personally idendifiable information from your data.

However I cannot guarantee that this software is 100% bug-free, and I certainly can't guarantee that you have configured it correctly. So use this software at your own risk.

License

This package is open-sourced software licensed under the MIT license.

brendantwhite/databasemask 适用场景与选型建议

brendantwhite/databasemask 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 10 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「laravel」 「obfuscation」 「privacy」 「Masking」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 brendantwhite/databasemask 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 brendantwhite/databasemask 我们能提供哪些服务?
定制开发 / 二次开发

基于 brendantwhite/databasemask 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-31