def unified_entity_uploader(self, path) -> int: """ Uploads unified entity folder Args: path: the folder path of a unified entity in the format `Pack/{Pack_Name}/Integration/{Integration_Name}` Returns: status code """ if get_parent_directory_name(path) not in UNIFIED_ENTITIES_DIR: return ERROR_RETURN_CODE yml_files = [] for file in glob.glob(f"{path}/*.yml"): if not file.endswith('_unified.yml'): yml_files.append(file) if len(yml_files) > 1: self.failed_uploaded_files.append( (path, "Entity Folder", "The folder contains more than one `.yml` file " "(not including `_unified.yml`)")) return ERROR_RETURN_CODE if not yml_files: self.failed_uploaded_files.append( (path, "Entity Folder", "The folder does not contain a `.yml` file")) return ERROR_RETURN_CODE return self.file_uploader(yml_files[0])
def upload(self): """Upload the pack / directory / file to the remote Cortex XSOAR instance. """ if self.demisto_version == "0": click.secho( "Could not connect to XSOAR server. Try checking your connection configurations.", fg="bright_red") return 1 status_code = 0 click.secho(f"Uploading {self.path} ...") if not os.path.exists(self.path): click.secho(f'Error: Given input path: {self.path} does not exist', fg='bright_red') return 1 # Uploading a file elif os.path.isfile(self.path): status_code = self.file_uploader(self.path) or status_code # Uploading an entity directory elif os.path.isdir(self.path): parent_dir_name = get_parent_directory_name(self.path) if parent_dir_name in UNIFIED_ENTITIES_DIR: status_code = self.unified_entity_uploader( self.path) or status_code elif os.path.basename( self.path.rstrip('/')) in CONTENT_ENTITIES_DIRS: status_code = self.entity_dir_uploader( self.path) or status_code elif parent_dir_name == PACKS_DIR: status_code = self.pack_uploader(self.path) or status_code if not self.successfully_uploaded_files and not self.failed_uploaded_files and \ not self.unuploaded_due_to_version: # if not uploaded any file click.secho( f'\nError: Given input path: {self.path} is not uploadable. ' f'Input path should point to one of the following:\n' f' 1. Pack\n' f' 2. A content entity directory that is inside a pack. For example: an Integrations directory or ' f'a Layouts directory\n' f' 3. Valid file that can be imported to Cortex XSOAR manually. ' f'For example a playbook: helloWorld.yml', fg='bright_red') return 1 print_summary(self.successfully_uploaded_files, self.unuploaded_due_to_version, self.failed_uploaded_files) return status_code
def upload(self): """Upload the pack / directory / file to the remote Cortex XSOAR instance. """ print(f"Uploading {self.path} ...") parent_dir_name = get_parent_directory_name(self.path) if not os.path.exists(self.path): print_error(f'Error: Given input path: {self.path} does not exist') self.status_code = 1 # Input is a file elif os.path.isfile(self.path): file_type = find_type(self.path) if file_type == FileType.INTEGRATION: self.integration_uploader(self.path) elif file_type in (FileType.SCRIPT, FileType.TEST_SCRIPT): self.script_uploader(self.path) elif file_type in (FileType.PLAYBOOK, FileType.TEST_PLAYBOOK): self.playbook_uploader(self.path) elif file_type == FileType.WIDGET: self.widget_uploader(self.path) elif file_type == FileType.INCIDENT_TYPE: self.incident_type_uploader(self.path) elif file_type == FileType.CLASSIFIER: self.classifier_uploader(self.path) elif file_type == FileType.OLD_CLASSIFIER: self.classifier_uploader(self.path) elif file_type == FileType.LAYOUT: self.layout_uploader(self.path) elif file_type == FileType.LAYOUTS_CONTAINER: self.layout_uploader(self.path) elif file_type == FileType.DASHBOARD: self.dashboard_uploader(self.path) elif file_type == FileType.INCIDENT_FIELD: self.incident_field_uploader(self.path) else: print_error( f'\nError: Given input path: {self.path} is not valid. ' f'Input path should point to one of the following:\n' f' 1. Pack\n' f' 2. A content entity directory that is inside a pack. For example: an Integrations directory or ' f'a Layouts directory\n' f' 3. Valid file that can be imported to Cortex XSOAR manually. ' f'For example a playbook: helloWorld.yml') self.status_code = 1 elif os.path.isdir(self.path): # Input is an integration directory (HelloWorld) if parent_dir_name == INTEGRATIONS_DIR: self.integration_uploader(self.path) # Input is a script directory (commonServerPython) elif parent_dir_name == SCRIPTS_DIR: self.script_uploader(self.path) # Input is a content entity directory (Integrations/Scripts/Playbook etc...) elif os.path.basename( self.path.rstrip('/')) in CONTENT_ENTITIES_DIRS: self.directory_uploader(self.path.rstrip('/')) # Input is a pack elif parent_dir_name == PACKS_DIR: self.pack_uploader() # Input is not supported else: print_error( f'\nError: Given input path: {self.path} is not valid. ' f'Input path should point to one of the following:\n' f' 1. Pack\n' f' 2. A content entity directory that is inside a pack. For example: an Integrations directory or ' f'a Layouts directory\n' f' 3. Valid file that can be imported to Cortex XSOAR manually. ' f'For example a playbook: helloWorld.yml') self.status_code = 1 self._print_summary() return self.status_code
def upload(self): """Upload the pack / directory / file to the remote Cortex XSOAR instance. """ if self.demisto_version == "0": click.secho( "Could not connect to XSOAR server. Try checking your connection configurations.", fg="bright_red") return ERROR_RETURN_CODE status_code = SUCCESS_RETURN_CODE if self.is_files_to_detached: item_detacher = ItemDetacher(client=self.client) list_detach_items_ids: list = item_detacher.detach_item_manager( upload_file=True) if self.reattach_files: item_reattacher = ItemReattacher(client=self.client) item_reattacher.reattach_item_manager( detached_files_ids=list_detach_items_ids) if not self.path: return SUCCESS_RETURN_CODE click.secho(f"Uploading {self.path} ...") if self.path is None or not os.path.exists(self.path): click.secho(f'Error: Given input path: {self.path} does not exist', fg='bright_red') return ERROR_RETURN_CODE # uploading a pack zip elif self.path.endswith('.zip'): status_code = self.zipped_pack_uploader( path=self.path, skip_validation=self.skip_upload_packs_validation) # Uploading a file elif os.path.isfile(self.path): status_code = self.file_uploader(self.path) or status_code # Uploading an entity directory elif os.path.isdir(self.path): parent_dir_name = get_parent_directory_name(self.path) if parent_dir_name in UNIFIED_ENTITIES_DIR: status_code = self.unified_entity_uploader( self.path) or status_code elif os.path.basename( self.path.rstrip('/')) in CONTENT_ENTITIES_DIRS: status_code = self.entity_dir_uploader( self.path) or status_code else: status_code = self.pack_uploader(self.path) or status_code if status_code == ABORTED_RETURN_CODE: return status_code if not self.successfully_uploaded_files \ and not self.failed_uploaded_files \ and not self.unuploaded_due_to_version: # if not uploaded any file click.secho( f'\nError: Given input path: {self.path} is not uploadable. ' f'Input path should point to one of the following:\n' f' 1. Pack\n' f' 2. A content entity directory that is inside a pack. For example: an Integrations directory or ' f'a Layouts directory\n' f' 3. Valid file that can be imported to Cortex XSOAR manually. ' f'For example a playbook: helloWorld.yml', fg='bright_red') return ERROR_RETURN_CODE print_summary(self.successfully_uploaded_files, self.unuploaded_due_to_version, self.failed_uploaded_files) return status_code
def upload(self): """Upload the pack / directory / file to the remote Cortex XSOAR instance. """ print(f"Uploading {self.path} ...") parent_dir_name = get_parent_directory_name(self.path) if not os.path.exists(self.path): print_error(f'Error: Given input path: {self.path} does not exist') self.status_code = 1 # Input is a file elif os.path.isfile(self.path): file_type = find_type(self.path) if file_type == 'integration': self.integration_uploader(self.path) elif file_type == 'script': self.script_uploader(self.path) elif file_type == 'playbook': self.playbook_uploader(self.path) elif file_type == 'widget': self.widget_uploader(self.path) elif file_type == 'incidenttype': self.incident_type_uploader(self.path) elif file_type == 'classifier': self.classifier_uploader(self.path) elif file_type == 'classifier_5_9_9': self.classifier_uploader(self.path) elif file_type == 'layout': self.layout_uploader(self.path) elif file_type == 'dashboard': self.dashboard_uploader(self.path) elif file_type == 'incidentfield': self.incident_field_uploader(self.path) else: print_error( f'\nError: Given input path: {self.path} is not valid. ' f'Input path should point to one of the following:\n' f' 1. Pack\n' f' 2. A content entity directory that is inside a pack. For example: an Integrations directory or ' f'a Layouts directory\n' f' 3. Valid file that can be imported to Cortex XSOAR manually. ' f'For example a playbook: helloWorld.yml') self.status_code = 1 elif os.path.isdir(self.path): # Input is an integration directory (HelloWorld) if parent_dir_name == INTEGRATIONS_DIR: self.integration_uploader(self.path) # Input is a script directory (commonServerPython) elif parent_dir_name == SCRIPTS_DIR: self.script_uploader(self.path) # Input is a content entity directory (Integrations/Scripts/Playbook etc...) elif os.path.basename(self.path) in CONTENT_ENTITIES_DIRS: self.directory_uploader(self.path) # Input is a pack elif parent_dir_name == PACKS_DIR: self.pack_uploader() # Input is not supported else: print_error( f'\nError: Given input path: {self.path} is not valid. ' f'Input path should point to one of the following:\n' f' 1. Pack\n' f' 2. A content entity directory that is inside a pack. For example: an Integrations directory or ' f'a Layouts directory\n' f' 3. Valid file that can be imported to Cortex XSOAR manually. ' f'For example a playbook: helloWorld.yml') self.status_code = 1 self._print_summary() return self.status_code