Skip to main content

Scrub sensitive fields for production and data that keeps changing for testing.

Project description

Scrub

A Python library for cleaning sensitive data for production and normalizing data for testing.

>>> from scrub import scrub_headers
>>> sensitive_headers = {
        "x-api-key": "--key--",
        "x-date": "--filtered--",
        "Set-Cookie": "--filtered--",
    }
>>> scrubber = scrub_headers(sensitive_headers)
>>> scrubber({
        "x-api-key": "3faf",
        "x-date": "Oct 18 2001",
        "Set-Cookie": "secret=3faf00",
        "Accept": "application/json",
    })
{
    'Accept': 'application/json',
    'Set-Cookie': '--filtered--',
    'x-api-key': '--key--',
    'x-date': '--filtered--'
}
>>>

Quick Start

Install using pip/pipenv/etc. (we recommend poetry for sane dependency management):

$ poetry add --dev scrub

Import a scrubber that you need:

from scrub import scrub_headers scrub_body, scrub_request

Available Scrubbers

scrub_headers

Scrubs HTTP headers, or more generally a plain python dict. Initialize with a key replacements dict:

{
    "x-api-key": "--key--",
    "x-date": "--filtered--",
    "Set-Cookie": "--filtered--",
}

scrub_body

Scrubs HTTP body, or more generally any piece of text. Initialize with content matching replacement dict:

{
    "<Secret>.*</Secret>": "<Secret>{}</Secret>".format(
        base64.b64encode(b"--filtered--").decode()
    ),
    "{.*}": "{}",
}

scrub_request

Scrubs a requests request. Give it headers and body scrubbers, or identity function if you don't want to replace anything there.

from scrub import scrub_request
scrubber = scrub_request(headerscrubber, lambda x: x)

scrubber(req)

Thanks:

To all Contributors - you make this happen, thanks!

Copyright

Copyright (c) 2018 @jondot. See LICENSE for further details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrub-0.1.2.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

scrub-0.1.2-py2.py3-none-any.whl (3.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file scrub-0.1.2.tar.gz.

File metadata

  • Download URL: scrub-0.1.2.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.5 CPython/3.7.0 Darwin/17.5.0

File hashes

Hashes for scrub-0.1.2.tar.gz
Algorithm Hash digest
SHA256 22ea8b5400b3db78da78c3c3323c44d68373786322dfb2b12608b2652f993657
MD5 6c40f0f323be625bcf4273f369f89ca3
BLAKE2b-256 114bb8b531376040f4ebe9b301cb833ab5d7b1781510ff2bc3556941fe057c64

See more details on using hashes here.

File details

Details for the file scrub-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: scrub-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.5 CPython/3.7.0 Darwin/17.5.0

File hashes

Hashes for scrub-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c7ba8e0bd8c331da7eae4d36446f4eceafaae998f4bc3dc59ece86e9a7e26945
MD5 01785f95bc24e3a9c4011262139eb0ab
BLAKE2b-256 d9940f14f878435766786bc5c987cfe804c9b748c1b1a059963141c4272b029a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page