def test_delete_playbook_invalid_name(self): initial_playbook_files = [os.path.splitext(playbook)[0] for playbook in helpers.locate_playbooks_in_directory()] self.delete_with_status_check('/api/playbooks/junkPlaybookName', error='Playbook does not exist', headers=self.headers, status_code=OBJECT_DNE_ERROR) self.assertFalse(flask_server.running_context.controller.is_playbook_registered('junkPlaybookName')) final_playbook_files = [os.path.splitext(playbook)[0] for playbook in helpers.locate_playbooks_in_directory()] orderless_list_compare(self, final_playbook_files, initial_playbook_files)
def test_delete_playbook_no_file(self): initial_playbook_files = [os.path.splitext(playbook)[0] for playbook in helpers.locate_playbooks_in_directory()] data = {"name": "test_playbook"} self.app.put('/api/playbooks', headers=self.headers, content_type="application/json", data=json.dumps(data)) self.delete_with_status_check('/api/playbooks/test_playbook', headers=self.headers) self.assertTrue(flask_server.running_context.controller.is_playbook_registered('test')) self.assertFalse(flask_server.running_context.controller.is_playbook_registered('test_playbook')) final_playbook_files = [os.path.splitext(playbook)[0] for playbook in helpers.locate_playbooks_in_directory()] orderless_list_compare(self, final_playbook_files, initial_playbook_files)
def __func(): if 'new_name' not in data or not data['new_name']: current_app.logger.error('No new name provided to update playbook') return { "error": 'No new name provided to update playbook.' }, INVALID_INPUT_ERROR if running_context.controller.is_playbook_registered(data['new_name']): current_app.logger.warning( 'Could not update playbook {0}. Playbook already exists.'. format(playbook_name)) return {"error": "Playbook already exists."}, OBJECT_EXISTS_ERROR new_name = data['new_name'] running_context.controller.update_playbook_name( playbook_name, new_name) saved_playbooks = [ os.path.splitext(playbook)[0] for playbook in helpers.locate_playbooks_in_directory( walkoff.config.paths.workflows_path) ] if playbook_name in saved_playbooks: os.rename( os.path.join(walkoff.config.paths.workflows_path, '{0}.playbook'.format(playbook_name)), os.path.join(walkoff.config.paths.workflows_path, '{0}.playbook'.format(new_name))) current_app.logger.info('Playbook renamed from {0} to {1}'.format( playbook_name, new_name)) workflow = next( playbook for playbook in running_context.controller.get_all_workflows() if playbook['name'] == new_name)['workflows'] return workflow, SUCCESS
def test_delete_playbook(self): self.delete_with_status_check('/api/playbooks/test', headers=self.headers) self.assertFalse(flask_server.running_context.controller.is_playbook_registered('test')) playbooks = [os.path.splitext(playbook)[0] for playbook in helpers.locate_playbooks_in_directory(walkoff.config.paths.workflows_path)] self.assertNotIn('test', playbooks)
def load_playbooks(resource_collection=None): """Loads all playbooks from a directory. Args: resource_collection (str, optional): Path to the directory to load from. Defaults to the configuration workflows_path. """ if resource_collection is None: resource_collection = walkoff.config.Config.WORKFLOWS_PATH playbooks = [JsonPlaybookLoader.load_playbook(os.path.join(resource_collection, playbook)) for playbook in locate_playbooks_in_directory(resource_collection)] return [playbook for playbook in playbooks if playbook]
def load_playbooks(resource_collection=None): """Loads all playbooks from a directory. Args: resource_collection (str, optional): Path to the directory to load from. Defaults to the configuration workflows_path. """ if resource_collection is None: resource_collection = walkoff.config.Config.WORKFLOWS_PATH playbooks = [JsonPlaybookLoader.load_playbook(os.path.join(resource_collection, playbook)) for playbook in locate_playbooks_in_directory(resource_collection)] return [playbook for playbook in playbooks if playbook]
def __func(): running_context.controller.remove_playbook(playbook_name) current_app.logger.info( 'Deleted playbook {0} from controller'.format(playbook_name)) if playbook_name in [ os.path.splitext(playbook)[0] for playbook in helpers.locate_playbooks_in_directory() ]: try: os.remove( os.path.join(walkoff.config.paths.workflows_path, '{0}.playbook'.format(playbook_name))) current_app.logger.info( 'Deleted playbook {0} from workflow directory'.format( playbook_name)) except (IOError, OSError) as e: current_app.logger.error( 'Error deleting playbook {0}: {1}'.format( playbook_name, e)) return { 'error': 'Error occurred while remove playbook file: {0}.'.format(e) }, IO_ERROR return {}, SUCCESS