LogoLogo
Official SiteAPI Reference
stable/3.0
stable/3.0
  • Cement Developer Guide
  • Release Information
    • What's New!
    • Upgrading
    • ChangeLog
    • Deprecations
  • Getting Started
    • Installation
    • Developer Tools
    • Framework Overview
    • Beginner Tutorial
      • Part 1: Creating Your First Project
      • Part 2: Adding Features
      • Part 3: Extending a Project
      • Part 4: Making Everything Legit
  • Core Foundation
    • Interfaces and Handlers
    • Hooks
    • Configuration Settings
    • Arguments
    • Logging
    • Controllers
    • Output Rendering
    • Caching
    • Mail Messaging
    • Framework Extensions
    • Application Plugins
    • Templating
  • Utilities
    • Filesystem
    • Shell
    • Miscellaneous
  • Extensions
    • Alarm
    • Argparse
    • Colorlog
    • ConfigParser
    • Daemon
    • Dummy
    • Generate
    • Jinja2
    • Json
    • Logging
    • Memcached
    • Mustache
    • Plugin
    • Print
    • Redis
    • Scrub
    • SMTP
    • Tabulate
    • Yaml
    • Watchdog
  • Additional Topics
    • Extending The App Object
    • Unit Testing
    • Cleanup
    • Signal Handling
    • Pipenv
    • Autocomplete
    • Profiling with cProfile
    • Debugging with VSCode
  • Environment Variables
  • Terminology
  • Contributing
  • Privacy Policy
Powered by GitBook
On this page
  • Introduction
  • Requirements
  • Configuration
  • Application Configuration Settings
  • Application Meta Data
  • Usage
  1. Extensions

Scrub

PreviousRedisNextSMTP

Last updated 6 years ago

Introduction

The Scrub Extension provides an easy mechanism for obfuscating sensitive information from command line output. It is useful for debugging and for providing end-user output to developers without including sensitive info like IP addresses, phone numbers, credit card numbers, etc.

Scrubbing happens in a hook by iterating over the list of tuples in App.Meta.scruband calling re.sub() on the text provided by the output handler in use. Therefore, all output produced by app.render() will be scrubbed… including JSON, YAML, or any other output handler.

API References:

Requirements

  • No external dependencies

Configuration

Application Configuration Settings

This extension does not rely on any application level configuration settings or meta options.

Application Meta Data

This extension honors the following App.Meta options:

Option

Description

scrub

A list of tuples in the form of [ ( 'REGEX', 'REPLACEMENT' ) ]

Usage

from cement import App

class MyApp(App):
    class Meta:
        label = 'myapp'
        extensions = ['scrub', 'print']
        scrub = [
            # obfuscate ipv4 addresses
            (r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", '***.***.***.***'),
        ]

with MyApp() as app:
    app.run()
    app.print('This is an IPv4 Address: 192.168.1.100')
$ python myapp.py
This is an IPv4 Address: 192.168.1.100

$ python myapp.py --scrub
This is an IPv4 Address: ***.***.***.***

In order for scrubbing to work, output must be rendered via a registered . If only printing to console is desired, use the print extension along with app.print() (as in the above example).

output handler
Cement Scrub Extension
post_render