定制 brendantwhite/databasemask 二次开发

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

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

brendantwhite/databasemask

最新稳定版本:v1.0.1

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.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固