SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def container_environment_copy(event, _):
  2.     result = event['fragment']
  3.     environments_to_inherit = list(dpath.util.search(result, '**/Environment/*/inheritFrom', yielded=True))
  4.  
  5.     if not environments_to_inherit:
  6.         raise ValueError("No parameter found with the name inheritFrom in any Environment section")
  7.  
  8.     for environment in environments_to_inherit:
  9.         source_path = environment[0].rsplit('/', maxsplit=2)[0]
  10.         _delete_macro_trigger(result, environment)
  11.         inherited_values = dpath.util.get(result, environment[1])
  12.         original_values = dpath.util.get(result, source_path)
  13.         _merge_dictionaries(result, source_path, original_values, inherited_values)
  14.  
  15.     return {
  16.         "requestId": event['requestId'],
  17.         "status": "success",
  18.         "fragment": result,
  19.     }
  20.    
  21.    
  22. def _delete_macro_trigger(result, environment):
  23.     dpath.util.delete(result, environment[0].rsplit('/', maxsplit=1)[0])
  24.  
  25.  
  26. def _merge_dictionaries(result, source_path, original_values, inherited_values):
  27.     dpath.util.set(result, source_path, _merge_variables(original_values, inherited_values))
  28.  
  29.  
  30. def _merge_variables(original_values, inherited_values):
  31.     original_values_names = set(filter(lambda x: x is not None, map(lambda x: x.get('Name'), original_values)))
  32.     resulting_environment = list(filter(lambda x: x and x.get('Name') not in original_values_names, inherited_values))
  33.     resulting_environment.extend(original_values)
  34.     return resulting_environment
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top