How to use sanitize_pattern method in localstack

Best Python code snippet using localstack_python

sanitize.py

Source:sanitize.py Github

copy

Full Screen

1import re2from collections.abc import Mapping3from textwrap import dedent4SENSITIVE_THINGS = {5 "password",6 "passwd",7 "client_secret",8 "code",9 "authorization",10 "access_token",11 "refresh_token",12}13REPLACEMENT = "<REDACTED>"14SANITIZE_PATTERN = r"""15 (?<!_) # Negative-lookbehind for underscore.16 # Necessary to keep 'authorization_code' from matching 'code'17 ( # Start of capturing group--we'll keep this bit.18 (?: # non-capturing group19 {} # Template-in things we want to sanitize20 ) #21 ['\"]? # Might have a quote after them?22 \s* # Maybe some whitespace23 [=:,] # Probably a : , or = in tuple, dict or qs format24 \s* # Maybe more whitespace25 [([]? # Could be inside a list/tuple, parse_qs?26 ([bu][\"'])? # Python 227 [\"']? # Might be a quote here.28 ) # End of capturing group29 (?:[%=/+\w]+) # This is the bit we replace with '<REDACTED>'30"""31SANITIZE_PATTERN = dedent(SANITIZE_PATTERN.format("|".join(SENSITIVE_THINGS)))32SANITIZE_REGEX = re.compile(SANITIZE_PATTERN, re.VERBOSE | re.IGNORECASE | re.UNICODE)33def redacted(key, value):34 if key in SENSITIVE_THINGS:35 return (key, REPLACEMENT)36 return (key, value)37def sanitize(potentially_sensitive):38 if isinstance(potentially_sensitive, Mapping):39 # Makes new dict so we don't modify the original40 # Also case-insensitive--possibly important for HTTP headers.41 return dict(redacted(k.lower(), v) for k, v in potentially_sensitive.items())42 else:43 if not isinstance(potentially_sensitive, str):44 potentially_sensitive = str(potentially_sensitive)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful