Example #1
0
 def replace_value(
     self,
     edge: Edge,
     original_val: List[Any],
     replaced_key: str,
     replaced_value: Any,
     keep_origin: bool,
     count: int = 0,
 ) -> Union[Any, List[Any]]:
     if count > 1:
         return original_val
     new_val = replace_string_value(
         original_str=original_val,
         str_to_replace=replaced_key,
         replaced_value=replaced_value,
         keep_origin=keep_origin,
     )
     curr_cache = self.replace_cache[edge.origin].get(edge.label, {}).get(
         replaced_key, [])
     # not_containing_dot = '.' not in new_val
     not_containing_dot = "." not in str(new_val)
     if not_containing_dot or new_val not in curr_cache or (
             len(curr_cache) > 0 and curr_cache[-1] != new_val):
         if not self.replace_cache[edge.origin].get(edge.label, {}):
             self.replace_cache[edge.origin][edge.label] = {}
         if not curr_cache:
             self.replace_cache[edge.origin][edge.label][replaced_key] = []
         self.replace_cache[edge.origin][edge.label][replaced_key].append(
             new_val)
         return new_val
     else:
         return self.replace_value(edge, original_val, replaced_key,
                                   replaced_value, not keep_origin,
                                   count + 1)
 def test_replace_interpolation(self):
     original_str = '${mapped-bucket-name}[module.bucket.name]-works-yay'
     replaced = replace_string_value(original_str,
                                     "module.bucket.name",
                                     "module-input-bucket",
                                     keep_origin=False)
     expected = '${mapped-bucket-name}[module-input-bucket]-works-yay'
     self.assertEqual(expected, replaced)
 def test_replace_with_map(self):
     original_str = '{\'module-input-bucket\':\'mapped-bucket-name\'}[module.bucket.name]-works-yay'
     replaced = replace_string_value(original_str,
                                     "module.bucket.name",
                                     "module-input-bucket",
                                     keep_origin=False)
     expected = '{\'module-input-bucket\':\'mapped-bucket-name\'}[module-input-bucket]-works-yay'
     self.assertEqual(expected, replaced)
Example #4
0
 def replace_value(
     self,
     edge: Edge,
     original_val: List[Any],
     replaced_key: str,
     replaced_value: Any,
     keep_origin: bool,
     count: int = 0,
 ) -> Union[Any, List[Any]]:
     if count > 1:
         return original_val
     new_val = replace_string_value(
         original_str=original_val,
         str_to_replace=replaced_key,
         replaced_value=replaced_value,
         keep_origin=keep_origin,
     )
     return new_val