def write_yaml_with_docker(self, yml_text, yml_data, script_obj): """Write out the yaml file taking into account the dockerimage45 tag. If it is present will create 2 integration files One for 4.5 and below and one for 5.0. Arguments: output_path {str} -- output path yml_text {str} -- yml text yml_data {dict} -- yml object script_obj {dict} -- script object Returns: dict -- dictionary mapping output path to text data """ output_map = {self.dest_path: yml_text} if 'dockerimage45' in script_obj: # we need to split into two files 45 and 50. Current one will be from version 5.0 yml_text = re.sub(r'^\s*dockerimage45:.*\n?', '', yml_text, flags=re.MULTILINE) # remove the dockerimage45 line yml_text45 = yml_text if 'fromversion' in yml_data: # validate that this is a script/integration which targets both 4.5 and 5.0+. if server_version_compare(yml_data['fromversion'], '5.0.0') >= 0: raise ValueError('Failed: {}. dockerimage45 set for 5.0 and later only'.format(self.dest_path)) yml_text = re.sub(r'^fromversion:.*$', 'fromversion: 5.0.0', yml_text, flags=re.MULTILINE) else: yml_text = 'fromversion: 5.0.0\n' + yml_text if 'toversion' in yml_data: # validate that this is a script/integration which targets both 4.5 and 5.0+. if server_version_compare(yml_data['toversion'], '5.0.0') < 0: raise ValueError('Failed: {}. dockerimage45 set for 4.5 and earlier only'.format(self.dest_path)) yml_text45 = re.sub(r'^toversion:.*$', 'toversion: 4.5.9', yml_text45, flags=re.MULTILINE) else: yml_text45 = 'toversion: 4.5.9\n' + yml_text45 if script_obj.get('dockerimage45'): # we have a value for dockerimage45 set it as dockerimage yml_text45 = re.sub(r'(^\s*dockerimage:).*$', r'\1 ' + script_obj.get('dockerimage45'), yml_text45, flags=re.MULTILINE) else: # no value for dockerimage45 remove the dockerimage entry yml_text45 = re.sub(r'^\s*dockerimage:.*\n?', '', yml_text45, flags=re.MULTILINE) output_path45 = re.sub(r'\.yml$', '_45.yml', self.dest_path) output_map = { self.dest_path: yml_text, output_path45: yml_text45 } for file_path, file_text in output_map.items(): if os.path.isfile(file_path): raise ValueError('Output file already exists: {}.' ' Make sure to remove this file from source control' ' or rename this package (for example if it is a v2).'.format(self.dest_path)) with io.open(file_path, mode='w', encoding='utf-8') as file_: file_.write(file_text) return output_map
def is_valid_feed(self): # type: () -> bool if self.current_file.get("feed"): from_version = self.current_file.get("fromversion", "0.0.0") if not from_version or server_version_compare("5.5.0", from_version) == 1: print_error(Errors.feed_wrong_from_version(self.file_path, from_version)) return False return True
def is_docker_image_changed(self): """Check if the Docker image was changed or not.""" # Unnecessary to check docker image only on 5.0 and up if server_version_compare(self.old_file.get('fromversion', '0'), '5.0.0') < 0: old_docker = get_dockerimage45(self.old_file.get('script', {})) new_docker = get_dockerimage45(self.current_file.get('script', {})) if old_docker != new_docker: print_error(Errors.breaking_backwards_docker(self.file_path, old_docker, new_docker)) self.is_valid = False return True return False
def is_docker_image_changed(self): # type: () -> bool """Check if the docker image as been changed.""" # Unnecessary to check docker image only on 5.0 and up if server_version_compare(self.old_file.get('fromversion', '0'), '5.0.0') < 0: old_docker = get_dockerimage45(self.old_file) new_docker = get_dockerimage45(self.current_file) if old_docker != new_docker: print_error( Errors.breaking_backwards_docker(self.file_path, old_docker, new_docker)) return True return False
def test_server_version_compare(self, left, right, answer): assert server_version_compare(left, right) == answer