Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix re.sub hanging #158

Merged
merged 3 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions kapitan/refs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
logger = logging.getLogger(__name__)

# e.g. ?{ref:my/secret/token} or ?{ref:my/secret/token|func:param1:param2}
REF_TOKEN_TAG_PATTERN = r"(\?{([\w\:\.\-\/]+)([\|\w\:\.\-\/]+)*})"
REF_TOKEN_TAG_PATTERN = r"(\?{([\w\:\.\-\/]+)([\|\w\:\.\-\/]+)?=*})"


class Ref(object):
Expand Down Expand Up @@ -175,6 +175,7 @@ class Revealer(object):
def __init__(self, ref_controller):
"reveal files and objects"
self.ref_controller = ref_controller
self.regex = re.compile(REF_TOKEN_TAG_PATTERN)

def reveal_path(self, path):
"detects if path is file or dir, returns list of RevealObj"
Expand Down Expand Up @@ -276,12 +277,12 @@ def reveal_raw_file(self, filename):
out_raw = ''
if filename is None:
for line in sys.stdin:
revealed = re.sub(REF_TOKEN_TAG_PATTERN, self._reveal_replace_match, line)
revealed = self.regex.sub(self._reveal_replace_match, line)
out_raw += revealed
else:
with open(filename) as fp:
for line in fp:
revealed = re.sub(REF_TOKEN_TAG_PATTERN, self._reveal_replace_match, line)
revealed = self.regex.sub(self._reveal_replace_match, line)
out_raw += revealed
return out_raw

Expand All @@ -291,15 +292,15 @@ def compile_raw(self, data, **kwargs):
kwargs are passed to ref compile function
returns string with compile content
"""
compiled = re.sub(REF_TOKEN_TAG_PATTERN, self._compile_replace_match_with_args(**kwargs), data)
compiled = self.regex.sub(self._compile_replace_match_with_args(**kwargs), data)
return compiled

def reveal_raw(self, data):
"""
read data and reveal content (per line search and replace) with refs
returns string with revealed content
"""
revealed = re.sub(REF_TOKEN_TAG_PATTERN, self._reveal_replace_match, data)
revealed = self.regex.sub(self._reveal_replace_match, data)
return revealed

def reveal_obj(self, obj):
Expand All @@ -310,7 +311,7 @@ def reveal_obj(self, obj):
elif isinstance(obj, list):
obj = [self.reveal_obj(item) for item in obj]
elif isinstance(obj, str):
obj = re.sub(REF_TOKEN_TAG_PATTERN, self._reveal_replace_match, obj)
obj = self.regex.sub(self._reveal_replace_match, obj)
return obj

def compile_obj(self, obj, **kwargs):
Expand All @@ -324,7 +325,7 @@ def compile_obj(self, obj, **kwargs):
elif isinstance(obj, list):
obj = [self.compile_obj(item, **kwargs) for item in obj]
elif isinstance(obj, str):
obj = re.sub(REF_TOKEN_TAG_PATTERN, self._compile_replace_match_with_args(**kwargs), obj)
obj = self.regex.sub(self._compile_replace_match_with_args(**kwargs), obj)
return obj


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jsonschema>=2.6.0
python-gnupg==0.4.3
six>=1.11.0
cryptography==2.3
requests>=2.19.1
requests>=2.20.0

# Reclass dependencies
pyparsing