• This repository has been archived on 19/Oct/2023
  • Stars
    star
    237
  • Rank 166,119 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 6 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Faker-driven, configuration-based, platform-agnostic, locale-compatible data faker tool

Masquerade logo

Masquerade

Faker-driven, platform-agnostic, locale-compatible data faker tool

Point Masquerade to a database, give it a rule-set defined in YAML and Masquerade will anonymize the data for you automatically!

Out-of-the-box supported frameworks

  • Magento 2
  • Shopware 6

Customization

You can add your own configuration files in a directory named config in the same directory as where you run masquerade. The configuration files will be merged with any already present configuration files for that platform, overriding any out-of-the-box values.

See the Magento 2 YAML files as examples for notation.

For example, to override the admin.yaml for Magento 2, you place a file in config/magento2/admin.yaml. For example, if you want to completely disable/skip a group, just add this content;

admin:

You can add your own config files for custom tables or tables from 3rd party vendors. Here are a few examples:

To generate such files, you can run the masquerade identify command. This will look for columns that show a hint of personal identifiable data in the name, such as name or address. It will interactively ask you to add it to a config file for the chosen platform.

Partial anonymization

You can affect only certain records by including a 'where' clause - for example to avoid anonymising certain admin accounts, or to preserve data used in unit tests, like this:

customers:
  customer_entity:
    provider: # this sets options specific to the type of table
      where: "`email` not like '%@mycompany.com'" # leave mycompany.com emails alone

Delete Data

You might want to fully or partially delete data - eg. if your developers don't need sales orders, or you want to keep the database size a lot smaller than the production database. Specify the 'delete' option.

When deleting some Magento data, eg. sales orders, add the command line option --with-integrity which enforces foreign key checks, so for example sales_invoice records will be deleted automatically if their parent sales_order is deleted:

orders:
  sales_order:
    provider:
      delete: true
      where: "customer_id != 3" # delete all except customer 3's orders because we use that for testing
    # no need to specify columns if you're using 'delete'      

If you use 'delete' without a 'where', and without '--with-integrity', it will use 'truncate' to delete the entire table. It will not use truncate if --with-integrity is specified since that bypasses key checks.

Magento EAV Attributes

You can use the Magento2Eav table type to treat EAV attributes just like normal columns, eg.

products:
  catalog_product_entity: # specify the base table of the entity
    eav: true
    provider:
      where: "sku != 'TESTPRODUCT'" # you can still use 'where' and 'delete'
    columns:
      my_custom_attribute:
        formatter: sentence
      my_other_attribute:
        formatter: email

  catalog_category_entity:
    eav: true
    columns:
      description: # refer to EAV attributes like normal columns
        formatter: paragraph

Formatter Options

For formatters, you can use all default Faker formatters.

Custom Data Providers / Formatters

You can also create your own custom providers with formatters. They need to extend Faker\Provider\Base and they need to live in either ~/.masquerade or .masquerade relative from where you run masquerade.

An example file .masquerade/Custom/WoopFormatter.php;

<?php

namespace Custom;

use Faker\Provider\Base;

class WoopFormatter extends Base {

    public function woopwoop() {
        $woops = ['woop', 'wop', 'wopwop', 'woopwoop'];
        return $woops[array_rand($woops)];
    }
}

And then use it in your YAML file. A provider needs to be set on the column name level, not on the formatter level.

customer:
  customer_entity:
    columns:
      firstname:
        provider: \Custom\WoopFormatter
        formatter:
          name: woopwoop

Custom Table Type Providers

Some systems have linked tables containing related data - eg. Magento's EAV system, Drupal's entity fields and Wordpress's post metadata tables. You can provide custom table types. In order to do it you need to implement 2 interfaces:

  • Elgentos\Masquerade\DataProcessorFactory is to instantiate your custom processor. It receives table service factory, output object and whole array of yaml configuration specified for your table.

  • Elgentos\Masquerade\DataProcessor is to process various operations required by run command like:

    • truncate should truncate table in provided table via configuration
    • delete should delete table in provided table via configuration
    • updateTable should update table with values provided by generator based on columns definitions in the configuration. See Elgentos\Masquerade\DataProcessor\RegularTableProcessor::updateTable for a reference.

First you need to start with a factory that will instantiate an actual processor

An example file .masquerade/Custom/WoopTableFactory.php;

<?php

namespace Custom;

use Elgentos\Masquerade\DataProcessor;
use Elgentos\Masquerade\DataProcessor\TableServiceFactory;
use Elgentos\Masquerade\DataProcessorFactory;
use Elgentos\Masquerade\Output;
 
class WoopTableFactory implements DataProcessorFactory 
{

    public function create(
        Output $output, 
        TableServiceFactory $tableServiceFactory,
        array $tableConfiguration
    ): DataProcessor {
        $tableService = $tableServiceFactory->create($tableConfiguration['name']);

        return new WoopTable($output, $tableService, $tableConfiguration);
    }
}

An example file .masquerade/Custom/WoopTable.php;

<?php

namespace Custom;

use Elgentos\Masquerade\DataProcessor;
use Elgentos\Masquerade\DataProcessor\TableService;
use Elgentos\Masquerade\Output;

class WoopTable implements DataProcessor
{
    /** @var Output */
    private $output;

    /** @var array */
    private $configuration;

    /** @var TableService */
    private $tableService;

    public function __construct(Output $output, TableService $tableService, array $configuration)
    {
        $this->output = $output;
        $this->tableService = $tableService;
        $this->configuration = $configuration;
    }

    public function truncate(): void
    {
        $this->tableService->truncate();
    }
    
    public function delete(): void
    {
        $this->tableService->delete($this->configuration['provider']['where'] ?? '');
    }
    
    public function updateTable(int $batchSize, callable $generator): void
    {
        $columns = $this->tableService->filterColumns($this->configuration['columns'] ?? []);
        $primaryKey = $this->configuration['pk'] ?? $this->tableService->getPrimaryKey();
        
        $this->tableService->updateTable(
            $columns, 
            $this->configuration['provider']['where'] ?? '', 
            $primaryKey,
            $this->output,
            $generator,
            $batchSize
        );
    }
}

And then use it in your YAML file. A processor factory needs to be set on the table level, and can be a simple class name, or a set of options which are available to your class.

customer:
  customer_entity:
    processor_factory: \Custom\WoopTableFactory
    some_custom_config:
      option1: "test"
      option2: false
    columns:
      firstname:
        formatter:
          name: firstName

Installation

Download the phar file:

curl -L -o masquerade.phar https://github.com/elgentos/masquerade/releases/latest/download/masquerade.phar

Usage

$ php masquerade.phar run --help

Description:
  List of tables (and columns) to be faked

Usage:
  run [options]

Options:
      --platform[=PLATFORM]
      --driver[=DRIVER]      Database driver [mysql]
      --database[=DATABASE]
      --username[=USERNAME]
      --password[=PASSWORD]
      --host[=HOST]          Database host [localhost]
      --port[=PORT]          Database port [3306]
      --prefix[=PREFIX]      Database prefix [empty]
      --locale[=LOCALE]      Locale for Faker data [en_US]
      --group[=GROUP]        Comma-separated groups to run masquerade on [all]
      --with-integrity       Run with foreign key checks enabled
      --batch-size=BATCH-SIZE  Batch size to use for anonymization [default: 500]

You can also set these variables in a config.yaml file in the same location as where you run masquerade from, for example:

platform: magento2
database: dbnamehere
username: userhere
password: passhere
host: localhost
port: porthere

Running it nightly

Check out the wiki on how to run Masquerade nightly in CI/CD;

Building from source

To build the phar from source you can use the build.sh script. Note that it depends on Box which is included in this repository.

# git clone https://github.com/elgentos/masquerade
# cd masquerade
# composer install
# chmod +x build.sh
# ./build.sh
# bin/masquerade

Debian Packaging

To build a deb for this project run:

# apt-get install debhelper cowbuilder git-buildpackage
# export ARCH=amd64
# export DIST=buster
# cowbuilder --create --distribution buster --architecture amd64 --basepath /var/cache/pbuilder/base-$DIST-amd64.cow --mirror http://ftp.debian.org/debian/ --components=main
# echo "USENETWORK=yes" > ~/.pbuilderrc
# git clone https://github.com/elgentos/masquerade
# cd masquerade
# gbp buildpackage --git-pbuilder --git-dist=$DIST --git-arch=$ARCH --git-ignore-branch -us -uc -sa --git-ignore-new

To generate a new debian/changelog for a new release:

export BRANCH=master
export VERSION=$(date "+%Y%m%d.%H%M%S")
gbp dch --debian-tag="%(version)s" --new-version=$VERSION --debian-branch $BRANCH --release --commit

Credits

More Repositories

1

magento2-regenerate-catalog-urls

This extension adds console commands to be able to regenerate; a product rewrite URL based on its url path; a category rewrite URL based on its url path; a category URL path based on its URL key and its parent categories.
PHP
262
star
2

awesome-shopware6

Awesome Shopware 6 plugins, resources, themes, etc
174
star
3

magento2-cypress-testing-suite

A community-driven Cypress testing suite for Magento 2
JavaScript
170
star
4

magento2-upgrade-gui

Magento 2 Upgrade GUI
Vue
110
star
5

magento2-php8-cc

Magento 2 PHP 8.x compatibility checker
PHP
95
star
6

LargeConfigProducts

Large Configurable Products workaround for Magento 2
PHP
91
star
7

magento2-serversideanalytics

Server side analytics for Magento 2
PHP
64
star
8

magento2-lightspeed

Magento 2 - Lightspeed for Google Lighthouse optimizations
PHP
63
star
9

magento2-prismicio

Magento 2 Prismic integration
PHP
36
star
10

magerun2-addons

Addon modules for n98-magerun2
PHP
29
star
11

magento2-composer-quality-patches

elgentos/magento2-composer-quality-patches
PHP
22
star
12

CategoryTiling

Adds tiling display option to categories for showing sub-categories as tiles
PHP
20
star
13

magento2-gallery-replacement

Simple Magento 2 gallery replacement
HTML
20
star
14

magento2-backend-launcher

PHP
17
star
15

magento2-imgix

Imgix extension for Magento 2 - automatically optimize your images
PHP
16
star
16

shopware-seo-canonical-url

Use parent product canonical URL for SEO for product variants
Twig
15
star
17

http-statuscode-checker

CLI HTTP statuscode checker
PHP
15
star
18

magento2-structured-data

PHP
14
star
19

frontend2fa

Magento 2 module for 2FA on the frontend
PHP
14
star
20

EasyAttributes

Batch add attribute options and drag & drop to rearrange their order!
HTML
13
star
21

magento2-hyva-checkout-ab-test

Set up an A/B test with different available Hyvรค and Luma checkouts
PHP
13
star
22

Mailcheck

Magento implementation of Mailcheck
PHP
12
star
23

GoogleTagManager

Inserts Google Tag Manager script in header.
PHP
12
star
24

TableRates

Table rates generator for Magento
JavaScript
12
star
25

shopware-total-qty-in-cart-rule

Adds a Total Quantity In Cart Rule to the Rule Builder
PHP
12
star
26

magento2-clientside-cache

Clientside Cache
HTML
11
star
27

shopware-dutch-email-templates

Dutch email templates for Shopware 6
Twig
10
star
28

magento2-baseurlpath

Allow Magento config to have a base url path instead of root without moving Magento 2 into a subdirectory
PHP
10
star
29

magento2-review-reminder

Send out review reminder mails X days after shipment has been made
PHP
10
star
30

magento2-rumvision

Frontend implementation for https://www.rumvision.com/
PHP
9
star
31

magento2-filtered-product-list-noindex

PHP
9
star
32

hyva-vat-switcher

PHP
8
star
33

AutoInvoice

Automatically invoice some/specific orders.
PHP
8
star
34

TurpentineExtended

Extension to the excellent Nexcess Turpentine extension with shotgun mode
PHP
8
star
35

magento2-eu-tax-rates

Import EU VAT tax rates into Magento 2 with a simple console command
PHP
8
star
36

magento2-link-guest-orders-to-customer

Link existing guest orders to newly created or existing customer based on e-mail address
PHP
7
star
37

magento2-apicacheindexmanagement

Extension to invalidate caches and reindex indexers through the REST API.
PHP
7
star
38

MyFavorites

This extension shows a 'MyFavorites' block in the 'My Account' page with the most ordered products for that customer.
PHP
7
star
39

shopware-default-sort-order

Set the default sort order for category listings
PHP
6
star
40

testing-suite

6
star
41

magento2-secondaryemailaddress

B2B extension to enter secondary email address for logging in, order confirmation, invoice, etc
PHP
6
star
42

CodebaseExceptions

Magento Exceptions to Codebase
PHP
6
star
43

Automanufacturers

Create a category with the manufacturers name after saving a product.
PHP
6
star
44

magento2-consentmode-v2

HTML
6
star
45

FalconMollie

Mollie implementation for Deity Falcon
PHP
6
star
46

ServerSideAnalytics

This extension aims to solve the problem of discrepancies between Magento revenue reports and the revenue reports in Google Analytics.
PHP
6
star
47

LocalStorageVersioning

Highly experimental extension to clear localStorage along with Magento 2's static versioning
JavaScript
6
star
48

magento2-alternate-urls

PHP
5
star
49

Tierpercentages

Elgentos Tierpercentages - this module allows you to fill out percentages in the Tier pricing part under Prices
PHP
5
star
50

Magento-VR

JavaScript
5
star
51

AddressWithEmail

PHP
5
star
52

CustomDiscount

Set a custom price for a customer on request (sort of quotation)
PHP
5
star
53

prismic-importer

Transforms & bundles (Gatsby) Markdown files into Prismic.io JSON files
PHP
5
star
54

magento2-mollie-hide-payment-by-category

JavaScript
5
star
55

AutoConnect

Automatically create the opposite upsell, cross-sell and related products connection when a connection is made
PHP
5
star
56

BlockIP

This extension allows the shop administrator to block certain IP's from accessing the shop.
PHP
4
star
57

ExtendedAoeJsCssTstamp

Extends Aoe_JsCssTstamp to also version JS files that were included with addJs instead of addItem
PHP
4
star
58

Openkvk

OpenKvK extension for Magento
JavaScript
4
star
59

magento2-algolia-performance

Magento 2 module that makes it possible to set a debounce and a minimum character amount for Algolia Autocomplete
PHP
4
star
60

GrouponCoupons

Easily import Groupon Coupon codes into your installation (also works for other coupons)
PHP
4
star
61

RelatedBundles

This extension creates a new product relation type, Related Bundles.
PHP
4
star
62

parser

Use this library to turn your day-to-day configurations into usable arrays/objects.
PHP
3
star
63

ClientLog

Enable client side Javascript error logging through Mage::log
JavaScript
3
star
64

magento2-kiyoh

Magento 2 extension for Kiyoh
PHP
3
star
65

magento2-vurbis-punchout

Unofficial version of the Vurbis Magento 2 connector
PHP
3
star
66

Quickadd

Provides a rewritable configurable link to directly add products into the shopping cart
PHP
3
star
67

magento2-react

Magento 2 module to add React to Knockout-driven frontend
JavaScript
2
star
68

module-feedbackcompany-magento2

PHP
2
star
69

hypernode-api-cli

PHAR distribution of the hypernode-api-php client library for stand-alone use
PHP
2
star
70

HidePaymentMethod

Hide banktransfer payment method in the frontend while keeping it enabled for the backend
PHP
2
star
71

magetitans

HTML
2
star
72

setup

Makefile
2
star
73

magento2-prismicio-sample-data

Magento 2 - PrismicIO Sample Data
HTML
2
star
74

CustomFields

Add custom fields to registration page
PHP
2
star
75

Bundlequick

Bundlequick allows you to quickly create a bundled product based on two or more simple products you have selected by using the Bundlequick mass update action.
PHP
2
star
76

magento2-notifier-mail-adapter

PHP
2
star
77

SendInvoiceEmail

This small extension allows to send out invoice emails for payment methods that do not do this themselves, like PayPal Express and Authorize.net
PHP
2
star
78

Dataprovider

Connection with Dataprovider.com to autofill checkout page
PHP
2
star
79

Backorders

Adds a menu option beneath 'Sales' to show all current orders that contain backorders.
PHP
2
star
80

laravel-coding-standards

2
star
81

Dynamiclinks

This module will dynamically show upsell products based on the previous set of products they have seen in the category view.
PHP
2
star
82

module-categorygridlist

Magento 2 - Offers an option in the backend to toggle grid or list view on a category basis, instead of on a global basis
PHP
2
star
83

FormRedirect

With this extension you can send your contactform thank you page to any page you want!
PHP
2
star
84

github-cli-docker

For all the docker peeps out there, run Github-CLI via docker locally
Shell
1
star
85

magento2-composer-plugin

Magento 2 Composer plugin
PHP
1
star
86

CheckoutTelephoneInputType

HTML
1
star
87

magento2-openkvk

PHP
1
star
88

best-practices

HTML
1
star
89

OneLineStoreName

Reformat the 'store' line in the order grid to allow for a compacter view
PHP
1
star
90

HideOutOfStockCrosssell

Hides products in cross-sell recommendations that are out of stock (when backorders are enabled)
PHP
1
star
91

gdpr-dump-magento-2-extensions

GDPR dump templates for popular Magento 2 extensions
1
star
92

magento2-elasticsuite-prismic-search

Magento 2 ElasticSuite Prismic Search
PHP
1
star
93

magento2-legacy-email-enable

Enable Magento 2 legacy email templates
PHP
1
star
94

magento-module-facebook

PHP
1
star
95

hypernode-ssh-brancher

Simple SSH script to connect to your active branchers
Shell
1
star
96

magento2-customer-specific-checkmo

Allows customers based on an attribute to checkout using checkmo
PHP
1
star