Skip to content

Commit

Permalink
Merge pull request #13 from 10up/feature/json-config-support
Browse files Browse the repository at this point in the history
Feature/json config support
  • Loading branch information
darylldoyle authored Dec 10, 2024
2 parents 869c291 + 0a284d0 commit e9ed7e6
Show file tree
Hide file tree
Showing 19 changed files with 5,698 additions and 275 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: PHPUnit

on:
push:
branches:
- develop
- trunk
pull_request:
branches:
- develop

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
php: ['8.0', '8.1', '8.2', '8.3', '8.4']
fail-fast: false

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2

- name: Validate composer.json
run: composer validate

- name: Lint PHP
run: |
find . -name '*.php' -not -path './vendor/*' -print0 | xargs -0 -n1 -P4 php -dxdebug.mode=off -l
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: composer run-script phpunit
152 changes: 152 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,158 @@ In addition to CLI arguments, three filters are available to developers

WP Scrubber scrubs PII based on where WordPress core stores data (users, comments, standard user/comment meta keys). It does not have knowledge of PII stored by third party plugins. Even when using this tool you should audit your database for third party PII.

## JSON Configuration
WP Scrubber also includes the option to configure scrubbing rules using a JSON configuration file. This allows for more detailed and flexible scrubbing rules for post types, taxonomies, options, user data, custom tables, and truncating tables.
To use the JSON configuration, create a `wp-scrubber.json` file in the root of your WordPress installation. The plugin will automatically detect and use this file for scrubbing rules.

### JSON Configuration Structure

#### Post Types
Define which post types and their associated fields and meta fields to scrub.

```json
{
"post_types": [
{
"name": "post",
"fields": [
{ "name": "post_title", "action": "faker", "faker_type": "sentence" }
// More fields...
],
"meta_fields": [
{ "key": "meta_key_name", "action": "replace", "value": "new value" }
// More meta_fields...
]
},
// More post_types...
]
}
```

- `name`: The post type (e.g., post, page).
- `fields`: Fields to scrub within the post type.
- `name`: Field name.
- `action`: Scrubbing action (`faker`, `replace`, `remove`).
- `faker_type`: Type of fake data from Faker (e.g., `sentence`).
- `value`: Replacement value for `replace` action.
- `meta_fields`: Post meta fields to scrub.
- `key`: Meta key.
- `action`, `faker_type`, `value`: As described above.

#### Taxonomies
Define taxonomies and their terms and meta fields to scrub.

```json
{
"taxonomies": [
{
"name": "category",
"fields": [
{ "name": "name", "action": "faker", "faker_type": "sentence" }
// More fields...
],
"meta_fields": [
{ "key": "meta_key_name", "action": "replace", "value": "new value" }
// More meta_fields...
]
},
// More taxonomies...
]
}
```

- `name`: Taxonomy name.
- `fields`: Fields to scrub within the terms.
- `name`, `action`, `faker_type`, `value`: As described above.
- `meta_fields`: Term meta fields to scrub.
- `key`, `action`, `faker_type`, `value`: As described above.

#### Options
Define WordPress options to scrub.

```json
{
"options": [
{ "name": "admin_email", "action": "faker", "faker_type": "email" }
// More options...
]
}
```

- `name`: Option name.
- `action`, `faker_type`, `value`: As described above.

#### User Data
Define user data fields to scrub.

```json
{
"user_data": [
"fields": [
{ "name": "user_email", "action": "faker", "faker_type": "email" }
// More user_data...
],
"meta_fields": [
{ "key": "meta_key_name", "action": "replace", "value": "new value" }
// More meta_fields...
]
]
}
```

- `fields`: Fields to scrub within the user.
- `name`, `action`, `faker_type`, `value`: As described above.
- `meta_fields`: User meta fields to scrub.
- `key`, `action`, `faker_type`, `value`: As described above.

#### Custom Tables
Define custom tables and columns to scrub.

```json
{
"custom_tables": [
{
"name": "custom_table_name",
"primary_key": "id",
"columns": [
{ "name": "column_name", "action": "faker", "faker_type": "name" }
// More columns...
]
},
// More custom_tables...
]
}
```

- `name`: Custom table name.
- `primary_key`: Primary key column name.
- `columns`: Columns within the custom table to scrub.
- `name`, `action`, `faker_type`, `value`: As described above.

#### Truncate Tables
List tables to be entirely truncated.

```json
{
"truncate_tables": [
"table_to_truncate"
// More tables to truncate...
]
}
```

- `truncate_tables`: List of table names to truncate.

### Scrubbing Actions
- `action`: Defines the scrubbing action (`faker`, `replace`, `remove`).
- `faker_type`: Specifies the type of fake data (e.g., `name`, `email`) when using the `faker` action.
- `value`: For the `replace` action, the specific value to replace the original data.

### Full Example
See a full example JSON config at [`/config-example`](/config-example.json).



## Definition of Beta

10up considers this tool production ready for 10up projects. Publicly we define it as beta because we are wary of people relying on this tool solely when third party software can store PII in unknown locations.
Expand Down
15 changes: 15 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

// First we need to load the composer autoloader, so we can use WP Mock
require_once __DIR__ . '/vendor/autoload.php';

// Load WordPress and WP-CLI dependencies if needed.
if ( ! class_exists( 'WP_CLI' ) ) {
require_once dirname( __DIR__ ) . '/vendor/wp-cli/wp-cli/php/class-wp-cli.php';
}

// Use patchwork
WP_Mock::setUsePatchwork( true );

// Bootstrap WP_Mock to initialize built-in features
WP_Mock::bootstrap();
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "10up/wp-scrubber",
"description": "A WordPress plugin that scrubs sensitive data from the database.",
"type": "wordpress-plugin",
"license": "GPL-2.0-or-later",
"authors": [
Expand All @@ -9,14 +10,19 @@
}
],
"require": {
"php": ">=7.3"
"php": ">=8.0",
"fakerphp/faker": "^1.23"
},
"require-dev": {
"10up/phpcs-composer": "dev-master"
"10up/phpcs-composer": "^3.0.0",
"10up/wp_mock": "^1.0",
"phpunit/phpunit": "^9.6",
"wp-cli/wp-cli": "^2.11"
},
"scripts": {
"lint": "phpcs .",
"lint-fix": "phpcbf ."
"lint": "phpcs -s .",
"lint-fix": "phpcbf .",
"phpunit": "phpunit"
},
"autoload": {
"psr-4": {
Expand All @@ -32,4 +38,4 @@
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
}
Loading

0 comments on commit e9ed7e6

Please sign in to comment.