### Example Validate Command Usage Source: https://github.com/greenmaskio/greenmask/blob/main/docs/commands/validate.md Demonstrates how to start the validation process with a comprehensive set of flags, including configuration file, warnings, data diff, schema comparison, and output formatting options. ```shell greenmask --config=config.yml validate \ --warnings \ --data \ --diff \ --schema \ --format=text \ --table-format=vertical \ --transformed-only \ --rows-limit=1 ``` -------------------------------- ### View Install Script Options Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/installation.md Download the install script first, then execute it with the --help flag to see all available installation options and configurations. ```shell curl -fsSL -o install.sh https://greenmask.io/install.sh sh install.sh --help ``` -------------------------------- ### View Install Script Options Source: https://github.com/greenmaskio/greenmask/blob/main/docs/installation.md Download the installation script first, then execute it with the --help flag to see available configuration options. This allows for customization of the installation process. ```shell curl -fsSL -o install.sh https://greenmask.io/install.sh sh install.sh --help ``` -------------------------------- ### Install Greenmask via Script Source: https://github.com/greenmaskio/greenmask/blob/main/docs/installation.md Use this command to download and execute the official installation script for Greenmask. This is a quick way to get started on supported systems. ```shell curl -fsSL https://greenmask.io/install.sh | sh ``` -------------------------------- ### Start Greenmask Playground with Make Source: https://github.com/greenmaskio/greenmask/blob/main/docs/playground.md An alternative method to start the Greenmask Playground using the 'make' command, which wraps the docker-compose command. ```shell make greenmask-latest ``` -------------------------------- ### Full Dump Section Configuration Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/configuration.md An example demonstrating the complete `dump` section configuration, including `pg_dump_options` and detailed `transformation` rules for multiple tables with various transformers and overrides. ```yaml dump: pg_dump_options: dbname: "host=/run/postgresql user=postgres dbname=demo" jobs: 10 exclude-schema: "(\"teSt\"*|test*)" table: "bookings.flights" load-via-partition-root: true transformation: - schema: "bookings" name: "flights" query: "select * from bookings.flights3 limit 1000000" columns_type_override: post_code: "int4" # (1) transformers: - name: "RandomDate" params: min: "2023-01-01 00:00:00.0+03" max: "2023-01-02 00:00:00.0+03" column: "scheduled_departure" - name: "NoiseDate" params: ratio: "01:00:00" column: "scheduled_arrival" - name: "RegexpReplace" params: column: "status" regexp: "On Time" replace: "Delayed" - name: "RandomInt" # (2) params: column: "post_code" min: "11" max: "99" - schema: "bookings" name: "aircrafts_data" subset_conds: # (3) - "bookings.aircrafts_data.model = 'Boeing 777-300-2023'" transformers: - name: "Json" params: column: "model" operations: - operation: "set" path: "en" value: "Boeing 777-300-2023" - operation: "set" path: "crewSize" value: 10 - name: "NoiseInt" params: ratio: 0.9 column: "range" ``` -------------------------------- ### Installing Greenmask with the official script Source: https://github.com/greenmaskio/greenmask/blob/main/docs/release_notes/greenmask_0_2_14.md Shows the command to install Greenmask using the official installation script. ```bash curl -fsSL https://greenmask.io/install.sh | bash ``` -------------------------------- ### Full Restore Configuration Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/configuration.md An example of a complete restore configuration, including pre-data scripts, error exclusions, and pg_restore options like job count, database connection, and table restoration. ```yaml restore: scripts: pre-data: # (1) - name: "pre-data before script [1] with query" when: "before" query: "create table script_test(stage text)" insert_error_exclusions: tables: - schema: "production" name: "productreview" constraints: - "PK_ProductReview_ProductReviewID" error_codes: - "23505" global: error_codes: - "23505" pg_restore_options: jobs: 10 exit-on-error: false dbname: "postgresql://postgres:example@localhost:54316/transformed" table: - "productreview" pgzip: true inserts: true on-conflict-do-nothing: true restore-in-order: true ``` -------------------------------- ### JSON Output Example for show-dump Source: https://github.com/greenmaskio/greenmask/blob/main/docs/commands/show-dump.md This example demonstrates the JSON output format for the show-dump command, providing structured data about the dump's metadata, transformers, and entries. ```json { "startedAt": "2023-10-29T20:50:19.948017+02:00", // (1) "completedAt": "2023-10-29T20:50:22.19333+02:00", // (2) "originalSize": 4053842, // (3) "compressedSize": 686557, // (4) "transformers": [ // (5) { "Schema": "bookings", // (6) "Name": "flights", // (7) "Query": "", // (8) "Transformers": [ // (9) { "Name": "RandomDate", // (10) "Params": { // (11) "column": "c2NoZWR1bGVkX2RlcGFydHVyZQ==", "max": "MjAyMy0wMS0wMiAwMDowMDowMC4wKzAz", "min": "MjAyMy0wMS0wMSAwMDowMDowMC4wKzAz" } } ], "ColumnsTypeOverride": null // (12) } ], "header": { // (13) "creationDate": "2023-10-29T20:50:20+02:00", "dbName": "demo", "tocEntriesCount": 15, "dumpVersion": "16.0 (Homebrew)", "format": "TAR", "integer": 4, "offset": 8, "dumpedFrom": "16.0 (Debian 16.0-1.pgdg120+1)", "dumpedBy": "16.0 (Homebrew)", "tocFileSize": 8090, "compression": 0 }, "entries": [ // (14) { "dumpId": 3416, "databaseOid": 0, "objectOid": 0, "objectType": "ENCODING", "schema": "", "name": "ENCODING", "owner": "", "section": "PreData", "originalSize": 0, "compressedSize": 0, "fileName": "", "dependencies": null }, { "dumpId": 3417, "databaseOid": 0, "objectOid": 0, "objectType": "STDSTRINGS", "schema": "", "name": "STDSTRINGS", "owner": "", "section": "PreData", "originalSize": 0, "compressedSize": 0, "fileName": "", "dependencies": null }, { "dumpId": 3418, "databaseOid": 0, "objectOid": 0, "objectType": "SEARCHPATH", "schema": "", "name": "SEARCHPATH", "owner": "", "section": "PreData", "originalSize": 0, "compressedSize": 0, "fileName": "", "dependencies": null }, { "dumpId": 3419, "databaseOid": 16384, "objectOid": 1262, "objectType": "DATABASE", "schema": "", "name": "demo", "owner": "postgres", "section": "PreData", "originalSize": 0, "compressedSize": 0, "fileName": "", "dependencies": null }, { "dumpId": 3420, "databaseOid": 0, "objectOid": 0, "objectType": "DATABASE PROPERTIES", "schema": "", "name": "demo", "owner": "postgres", "section": "PreData", "originalSize": 0, "compressedSize": 0, "fileName": "", "dependencies": null }, { "dumpId": 222, "databaseOid": 16414, ``` -------------------------------- ### SQL Schema and Data Setup Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/transformation_inheritance.md Defines three tables with composite primary keys and foreign key relationships, then inserts sample data. This setup is used to demonstrate transformation inheritance. ```sql CREATE TABLE tablea ( id1 INT, id2 INT, data VARCHAR(50), PRIMARY KEY (id1, id2) ); CREATE TABLE tableb ( id1 INT, id2 INT, detail VARCHAR(50), PRIMARY KEY (id1, id2), FOREIGN KEY (id1, id2) REFERENCES tablea (id1, id2) ON DELETE CASCADE ); CREATE TABLE tablec ( id1 INT, id2 INT, description VARCHAR(50), PRIMARY KEY (id1, id2), FOREIGN KEY (id1, id2) REFERENCES tableb (id1, id2) ON DELETE CASCADE ); INSERT INTO tablea (id1, id2, data) VALUES (1, 1, 'Data A1'), (2, 1, 'Data A2'), (3, 1, 'Data A3'); INSERT INTO tableb (id1, id2, detail) VALUES (1, 1, 'Detail B1'), (2, 1, 'Detail B2'), (3, 1, 'Detail B3'); INSERT INTO tablec (id1, id2, description) VALUES (1, 1, 'Description C1'), (2, 1, 'Description C2'), (3, 1, 'Description C3'); ``` -------------------------------- ### Start Greenmask Playground with Docker Compose Source: https://github.com/greenmaskio/greenmask/blob/main/docs/playground.md Start the Greenmask Playground environment using Docker Compose. This command runs the greenmask service. ```shell docker-compose run greenmask ``` -------------------------------- ### Text Output Example for show-dump Source: https://github.com/greenmaskio/greenmask/blob/main/docs/commands/show-dump.md This example shows the typical text-based output when inspecting a dump's metadata. It includes archive details, database information, and a table of contents. ```text ; ; Archive created at 2023-10-30 12:52:38 UTC ; dbname: demo ; TOC Entries: 17 ; Compression: -1 ; Dump Version: 15.4 ; Format: DIRECTORY ; Integer: 4 bytes ; Offset: 8 bytes ; Dumped from database version: 15.4 ; Dumped by pg_dump version: 15.4 ; ; ; Selected TOC Entries: ; 3444; 0 0 ENCODING - ENCODING 3445; 0 0 STDSTRINGS - STDSTRINGS 3446; 0 0 SEARCHPATH - SEARCHPATH 3447; 1262 24970 DATABASE - demo postgres 3448; 0 0 DATABASE PROPERTIES - demo postgres 222; 1259 24999 TABLE bookings flights postgres 223; 1259 25005 SEQUENCE bookings flights_flight_id_seq postgres 3460; 0 0 SEQUENCE OWNED BY bookings flights_flight_id_seq postgres 3281; 2604 25030 DEFAULT bookings flights flight_id postgres 3462; 0 24999 TABLE DATA bookings flights postgres 3289; 2606 25044 CONSTRAINT bookings flights flights_flight_no_scheduled_departure_key postgres 3291; 2606 25046 CONSTRAINT bookings flights flights_pkey postgres 3287; 1259 42848 INDEX bookings flights_aircraft_code_status_idx postgres 3292; 1259 42847 INDEX bookings flights_status_aircraft_code_idx postgres 3293; 2606 25058 FK CONSTRAINT bookings flights flights_aircraft_code_fkey postgres 3294; 2606 25063 FK CONSTRAINT bookings flights flights_arrival_airport_fkey postgres 3295; 2606 25068 FK CONSTRAINT bookings flights flights_departure_airport_fkey postgres ``` -------------------------------- ### SQL Schema for Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/parameters_env_vars_interpolation.md This SQL statement creates a simple table named 'test' with a 'password' column to be used in the interpolation example. ```sql create table test (password text); insert into test (password) values ('secure'); ``` -------------------------------- ### Create Table and Insert Data Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/built_in_transformers/standard_transformers/random_company.md Example SQL to create a table named 'company_data' with an 'id' and 'name' column, and insert initial sample data. ```sql CREATE TABLE company_data ( id SERIAL PRIMARY KEY, name VARCHAR(100) ); -- Insert sample data into the table INSERT INTO personal_data (name, surname, sex) VALUES ('ACME Corp'), ('Foo LLP'), ('Bar Inc.'); ``` -------------------------------- ### SQL Schema Setup Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/built_in_transformers/parameters_env_vars_interpolation.md This SQL code sets up a simple table with a password column for demonstrating environment variable interpolation. ```sql create table test (password text); insert into test (password) values ('secure'); ``` -------------------------------- ### Schema Diff Changed Output Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/commands/validate.md This example shows the typical output when the database schema has changed. It includes warnings about renamed, type-changed, created columns, and created tables. ```text 2024-03-15T19:46:12+02:00 WRN Database schema has been changed Hint="Check schema changes before making new dump" 2024-03-15T19:46:12+02:00 WRN Column renamed Event=ColumnRenamed Signature={"CurrentColumnName":"id1","PreviousColumnName":"id","TableName":"test","TableSchema":"public"} 2024-03-15T19:46:12+02:00 WRN Column type changed Event=ColumnTypeChanged Signature={"ColumnName":"id","CurrentColumnType":"bigint","CurrentColumnTypeOid":"20","PreviousColumnType":"integer","PreviousColumnTypeOid":"23","TableName":"test","TableSchema":"public"} 2024-03-15T19:46:12+02:00 WRN Column created Event=ColumnCreated Signature={"ColumnName":"name","ColumnType":"text","TableName":"test","TableSchema":"public"} 2024-03-15T19:46:12+02:00 WRN Table created Event=TableCreated Signature={"SchemaName":"public","TableName":"test1","TableOid":"20563"} ``` -------------------------------- ### Run Greenmask Playground from Source Source: https://github.com/greenmaskio/greenmask/blob/main/docs/release_notes/greenmask_0_2_0_b1.md Execute this command to set up and run the Greenmask playground for the beta version v0.2.0b1. Ensure you have Git and Docker installed. ```bash git checkout tags/v0.2.0b1 -b v0.2.0b1 docker-compose run greenmask-from-source ``` -------------------------------- ### JSON Output Example for show-transformer Source: https://github.com/greenmaskio/greenmask/blob/main/docs/commands/show-transformer.md This example demonstrates the JSON output format for the show-transformer command, detailing a transformer's properties and parameters. Note that default values in JSON format are base64 encoded. ```json [ { "properties": { "name": "NoiseFloat", "description": "Make noise float for int", "is_custom": false }, "parameters": [ { "name": "column", "description": "column name", "required": true, "is_column": true, "is_column_container": false, "column_properties": { "max_length": -1, "affected": true, "allowed_types": [ "float4", "float8", "numeric" ], "skip_on_null": true } }, { "name": "ratio", "description": "max random percentage for noise", "required": false, "is_column": false, "is_column_container": false, "default_value": "MC4x" }, { "name": "decimal", "description": "decimal of noised float value (number of digits after coma)", "required": false, "is_column": false, "is_column_container": false, "default_value": "NA==" } ] } ] ``` -------------------------------- ### Debug SQL Query Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/database_subset.md This is an example of a debug log output showing a generated SQL query. It includes schema and table names, join conditions, and subset filters applied. ```sql 2024-08-29T19:06:18+03:00 DBG internal/db/postgres/context/context.go:202 > Debug query Schema=person Table=businessentitycontact pid=1638339 2024-08-29T19:06:18+03:00 DBG internal/db/postgres/context/context.go:203 > SELECT "person"."businessentitycontact".* FROM "person"."businessentitycontact" INNER JOIN "person"."businessentity" ON "person"."businessentitycontact"."businessentityid" = "person"."businessentity"."businessentityid" AND ( person.businessentity.businessentityid between 400 and 800 OR person.businessentity.businessentityid between 800 and 900 ) INNER JOIN "person"."person" ON "person"."businessentitycontact"."personid" = "person"."person"."businessentityid" WHERE TRUE AND (("person"."person"."businessentityid") IN (SELECT "person"."businessentity"."businessentityid" FROM "person"."businessentity" WHERE ( ( person.businessentity.businessentityid between 400 and 800 OR person.businessentity.businessentityid between 800 and 900 ) ))) pid=1638339 ``` -------------------------------- ### Cmd Transformer Configuration Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/standard_transformers/cmd.md Configuration for the Cmd transformer, specifying the driver, exit code, skip behaviors, timeout, and executable path. ```yaml - schema: "humanresources" name: "employee" transformers: - name: "Cmd" params: driver: name: "text" expected_exit_code: -1 skip_on_null_input: true validate: true skip_on_behaviour: "any" timeout: 60s executable: "/var/lib/playground/test.py" columns: - name: "jobtitle" skip_original_data: true skip_on_null_input: true ``` -------------------------------- ### NoiseDate Transformer Example with Dynamic Min Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/standard_transformers/noise_date.md This example demonstrates adding noise to the 'hiredate' column with a dynamic minimum threshold based on the 'birthdate' column. It uses a hash engine for deterministic noise generation and truncates the result to the month. A default value is provided if 'birthdate' is NULL. ```yaml - schema: "humanresources" name: "employee" transformers: - name: "NoiseDate" params: column: "hiredate" max_ratio: "1 year 2 mons 3 day 04:05:06.07" truncate: "month" max: "2020-01-01 00:00:00" engine: "hash" dynamic_params: min: column: "birthdate" default: "1990-01-01" ``` -------------------------------- ### Connect to Original DB Source: https://github.com/greenmaskio/greenmask/blob/main/docs/playground.md Use this alias to connect to the original database via psql for schema and data setup. ```shell psql_o ``` -------------------------------- ### NoiseDate Transformer Example with Dynamic Min Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/built_in_transformers/standard_transformers/noise_date.md This example demonstrates adding noise to the 'hiredate' column with a dynamic minimum threshold set to the 'birthdate' column. It uses a hash engine for deterministic output and truncates the result to the month part. ```yaml - schema: "humanresources" name: "employee" transformers: - name: "NoiseDate" params: column: "hiredate" max_ratio: "1 year 2 mons 3 day 04:05:06.07" truncate: "month" max: "2020-01-01 00:00:00" engine: "hash" dynamic_params: min: column: "birthdate" default: "1990-01-01" ``` -------------------------------- ### Environment Variable Mapping Example Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/configuration.md Illustrates how a YAML configuration key is transformed into an environment variable. The dot separator is replaced with an underscore and the key is uppercased. ```text LOG_LEVEL=debug ``` -------------------------------- ### YAML Configuration Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/configuration.md This YAML configuration sets the log level to debug. It demonstrates how Greenmask maps dot notation to environment variables. ```yaml log: level: debug ``` -------------------------------- ### Json Transformer Example Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/built_in_transformers/advanced_transformers/json.md This example demonstrates setting, templating, and deleting operations within a JSON document. It shows how to set specific string and templated integer values, add nested properties, and remove elements based on their path. The `error_not_exist` and `skip_not_exist` parameters are illustrated for error handling. ```yaml - schema: "bookings" name: "aircrafts_data" transformers: - name: "Json" params: column: "model" operations: - operation: "set" path: "en" value: "Boeing 777-300-2023" - operation: "set" path: "seats" error_not_exist: True value_template: "{{ randomInt 100 400 }}" - operation: "set" path: "details.preperties.1" value: {"name": "somename", "description": null} skip_not_exist: true - operation: "delete" path: "values.:2" ``` -------------------------------- ### RandomUsername Transformer Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/standard_transformers/random_username.md Configure the RandomUsername transformer to populate the 'username' column in the 'user_accounts' table. This setup is ideal for creating a diverse and realistic user base for development, testing, or demonstration purposes. Existing non-NULL values will be replaced unless `keep_null` is set to `true`. ```yaml - schema: "public" name: "user_accounts" transformers: - name: "RandomUsername" params: column: "username" keep_null: false ``` -------------------------------- ### Install Greenmask via Homebrew Source: https://github.com/greenmaskio/greenmask/blob/main/docs/installation.md Install the production build of Greenmask using the Homebrew package manager on macOS. Ensure Homebrew is installed before running this command. ```shell brew install greenmask ``` -------------------------------- ### CSV Line Example Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/built_in_transformers/standard_transformers/cmd.md Example of a CSV line demonstrating quoted attributes and empty values for non-transformed columns. ```csv "123","","2023-01-03 01:00:00.0+03" ``` -------------------------------- ### Create Table and Insert Data Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/standard_transformers/random_mac.md Sets up a table named 'mac_addresses' with relevant columns and inserts sample data, including MAC addresses. ```sql CREATE TABLE mac_addresses ( id SERIAL PRIMARY KEY, device_name VARCHAR(50), mac_address MACADDR, description TEXT ); INSERT INTO mac_addresses (device_name, mac_address, description) VALUES ('Device A', '00:1A:2B:3C:4D:5E', 'Description for Device A'), ('Device B', '01:2B:3C:4D:5E:6F', 'Description for Device B'), ('Device C', '02:3C:4D:5E:6F:70', 'Description for Device C'), ('Device D', '03:4D:5E:6F:70:71', 'Description for Device D'), ('Device E', '04:5E:6F:70:71:72', 'Description for Device E'); ``` -------------------------------- ### JSON Text Format Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/standard_transformers/cmd.md Example of JSON data in text format with indexes. Use this for non-binary datatypes. ```json { "column1": { "d": "some_value1", "n": false, }, "column2": { "d": "some_value2", "n": false, } } ``` -------------------------------- ### JSON Text Format Example Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/built_in_transformers/standard_transformers/cmd.md Example of JSON data format for text-based interaction, showing attribute indexes and values. ```json { "column1": { "d": "some_value1", "n": false, }, "column2": { "d": "some_value2", "n": false, } } ``` -------------------------------- ### Create Table and Insert Sample Data Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/standard_transformers/random_person.md SQL statements to create a table named 'personal_data' and insert initial sample records. This table includes columns for ID, name, surname, and sex. ```sql CREATE TABLE personal_data ( id SERIAL PRIMARY KEY, name VARCHAR(100), surname VARCHAR(100), sex CHAR(1) CHECK (sex IN ('M', 'F')) ); -- Insert sample data into the table INSERT INTO personal_data (name, surname, sex) VALUES ('John', 'Doe', 'M'), ('Jane', 'Smith', 'F'), ('Alice', 'Johnson', 'F'), ('Bob', 'Lee', 'M'); ``` -------------------------------- ### CSV Line Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/standard_transformers/cmd.md Example of a CSV line where columns not mentioned in the `columns` list are empty. NULL values are represented as `\N`. ```csv "123","","2023-01-03 01:00:00.0+03" ``` -------------------------------- ### Run Greenmask Playground from Source Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/release_notes/greenmask_0_2_0_b1.md Execute these commands to check out the beta tag and run the Greenmask playground from source. ```bash git checkout tags/v0.2.0b1 -b v0.2.0b1 docker-compose run greenmask-from-source ``` -------------------------------- ### Install Greenmask via Homebrew Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/installation.md Install the production build of Greenmask using the Homebrew package manager. This is a convenient option for macOS users. ```shell brew install greenmask ``` -------------------------------- ### Create Users and Orders Tables Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/transformation_inheritance.md Sets up a `users` table with UUID primary keys and an `orders` table that references `users.user_id`. This demonstrates a typical one-to-many relationship. ```sql -- Enable the extension for UUID generation (if not enabled) CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE TABLE users ( user_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), username VARCHAR(50) NOT NULL ); CREATE TABLE orders ( order_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), user_id UUID REFERENCES users (user_id), order_date DATE NOT NULL ); INSERT INTO users (username) VALUES ('john_doe'); INSERT INTO users (username) VALUES ('jane_smith'); INSERT INTO orders (user_id, order_date) VALUES ((SELECT user_id FROM users WHERE username = 'john_doe'), '2024-10-31'), ((SELECT user_id FROM users WHERE username = 'jane_smith'), '2024-10-30'); ``` -------------------------------- ### External Transformer in Python Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/standard_transformers/cmd.md Example of an external transformer script written in Python. It reads from stdin and writes to stdout, processing each line. ```python #!/usr/bin/env python3 import signal import sys signal.signal(signal.SIGTERM, lambda sig, frame: exit(0)) # If we want to implement a simple generator, we need read the line from stdin and write any result to stdout for _ in sys.stdin: # Writing the result to stdout with new line and flushing the buffer sys.stdout.write("New Job Title") sys.stdout.write("\n") sys.stdout.flush() ``` -------------------------------- ### JSON Bytes Format Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/standard_transformers/cmd.md Example of JSON data in bytes format with indexes. Use this for binary datatypes, with data represented in base64. ```json { "column1": { "d": "aGVsbG8gd29ybHNeODcxMjE5MCUlJSUlJQ==", "n": false, }, "column2": { "d": "aGVsbG8gd29ybHNeODcxMjE5MCUlJSUlJQ==", "n": false, } } ``` -------------------------------- ### Run Greenmask Playground from Source Source: https://github.com/greenmaskio/greenmask/blob/main/docs/release_notes/greenmask_0_2_0_b2.md Execute this command to set up and run the Greenmask playground for the beta version v0.2.0b2. Ensure you have Docker and Docker Compose installed. ```bash git checkout tags/v0.2.0b2 -b v0.2.0b2 docker-compose run greenmask-from-source ``` -------------------------------- ### Create Table and Insert Sample Data Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/standard_transformers/random_company.md SQL statements to create a table named 'company_data' and insert initial sample data. Note that the INSERT statement references 'personal_data' which might be a typo and should likely be 'company_data'. ```sql CREATE TABLE company_data ( id SERIAL PRIMARY KEY, name VARCHAR(100) ); -- Insert sample data into the table INSERT INTO personal_data (name, surname, sex) VALUES ('ACME Corp'), ('Foo LLP'), ('Bar Inc.'); ``` -------------------------------- ### Run Greenmask Playground (Beta v0.2.0b2) Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/release_notes/greenmask_0_2_0_b2.md Execute these commands to check out the beta tag and run the Greenmask playground from source using Docker Compose. ```bash git checkout tags/v0.2.0b2 -b v0.2.0b2 docker-compose run greenmask-from-source ``` -------------------------------- ### List Available Transformers Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/commands/list-transformers.md Use this command to display a list of all available transformers. Ensure you have a configuration file specified. ```shell greenmask --config=config.yml list-transformers ``` -------------------------------- ### Validation Warning Output Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/commands/validate.md Shows an example of a validation warning message generated by the `validate` command, detailing a possible constraint violation with specific metadata about the column, constraint, and transformer. ```text 2024-03-15T19:46:12+02:00 WRN ValidationWarning={"hash":"aa808fb574a1359c6606e464833feceb","meta":{"ColumnName":"birthdate","ConstraintDef":"CHECK (birthdate >= '1930-01-01'::date AND birthdate <= (now() - '18 years'::interval))","ConstraintName":"humanresources","ConstraintSchema":"humanresources","ConstraintType":"Check","ParameterName":"column","SchemaName":"humanresources","TableName":"employee","TransformerName":"NoiseDate"},"msg":"possible constraint violation: column has Check constraint","severity":"warning"} ``` -------------------------------- ### RandomUuid Transformer Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/standard_transformers/random_uuid.md This example demonstrates how to configure the RandomUuid transformer to replace existing UUID values in the 'rowguid' column with newly generated random UUIDs. NULL values will not be replaced. ```yaml - schema: "humanresources" name: "employee" transformers: - name: "RandomUuid" params: column: "rowguid" keep_null: false ``` -------------------------------- ### Replace Transformer Example Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/built_in_transformers/standard_transformers/replace.md This example demonstrates replacing the 'jobtitle' column with 'programmer'. It uses `keep_null: false` to ensure NULL values are also replaced, and `validate: true` to perform type checking. ```yaml - schema: "humanresources" name: "employee" transformers: - name: "Replace" params: column: "jobtitle" value: "programmer" keep_null: false validate: true ``` -------------------------------- ### NoiseDate Transformer Example Source: https://github.com/greenmaskio/greenmask/blob/main/docs/built_in_transformers/standard_transformers/noise_date.md This example demonstrates how to use the NoiseDate transformer to add noise to the 'hiredate' column. It specifies a maximum noise ratio, truncates the result to the month, and sets a maximum date threshold. ```yaml - schema: "humanresources" name: "jobcandidate" transformers: - name: "NoiseDate" params: column: "hiredate" max_ratio: "1 year 2 mons 3 day 04:05:06.07" truncate: "month" max: "2020-01-01 00:00:00" ``` -------------------------------- ### Configuration with Environment Variable Interpolation Source: https://github.com/greenmaskio/greenmask/blob/main/docs/configuration.md Demonstrates how to use environment variables for dynamic configuration values in log, storage, and dump settings. Use quoted strings for values containing YAML special characters. ```yaml log: level: ${LOG_LEVEL:-info} format: ${LOG_FORMAT:-text} storage: type: "s3" s3: endpoint: "${S3_ENDPOINT:-http://localhost:9000}" bucket: "${S3_BUCKET?S3 bucket name must be set}" region: "${AWS_REGION:-us-east-1}" access_key_id: "${AWS_ACCESS_KEY_ID?AWS access key ID must be set}" secret_access_key: "${AWS_SECRET_ACCESS_KEY?AWS secret access key must be set}" dump: pg_dump_options: dbname: "host=${DB_HOST:-localhost} user=${DB_USER:-postgres} dbname=${DB_NAME:-mydb}" ``` -------------------------------- ### Subset condition example Source: https://github.com/greenmaskio/greenmask/blob/main/docusaurus/database_subset.md Define a subset condition for a table using the 'subset_conds' attribute. This example filters records in the 'person.businessentity' table based on 'businessentityid'. Ensure schema, table, and column names are specified for clarity. ```yaml subset_conds: - 'person.businessentity.businessentityid IN (274, 290, 721, 852)' ```