addressed linting issues
#!/usr/bin/env python
-import yaml, sys
+"""
+This script performs inline filtering of the yaml output of an openshift resource
+and redacts the values of env vars likely to contain unfiltered passwords
+"""
+import sys
+import yaml
-def find_all_env_lists( obj, fn ):
+def find_all_env_lists(obj, modify_fn):
+ """Recursive search obj for env lists and call a function for each of the members"""
if isinstance(obj, dict):
- for k, v in obj.iteritems():
- if (k=="env" and isinstance(v, list)):
- for item in v:
+ for k, val in obj.iteritems():
+ if (k == "env" and isinstance(val, list)):
+ for item in val:
if "value" in item:
- item["value"] = fn( item["name"], item["value"] )
- elif isinstance( v, ( dict, list, tuple ) ):
- find_all_env_lists( v, fn )
+ item["value"] = modify_fn(item["name"], item["value"])
+ elif isinstance(val, (dict, list, tuple)):
+ find_all_env_lists(val, modify_fn)
elif isinstance(obj, (list, tuple)):
for item in obj:
- find_all_env_lists(item, fn)
+ find_all_env_lists(item, modify_fn)
return obj
def redact_secure_env_vars(key, value):
+ """Redacts values of probable password env var."""
if ("PASSWORD" in key or "PASSWD" in key):
value = "***REDACTED***"
return value
-y=yaml.safe_load(sys.stdin);
+y = yaml.safe_load(sys.stdin)
print(yaml.dump(find_all_env_lists(y, redact_secure_env_vars)))
