Exemple #1
0
def display_available_workflow_templates():
    templates = {
        os.path.splitext(workflow)[0]: helpers.get_workflow_names_from_file(
            os.path.join(config.templatesPath, workflow))
        for workflow in locate_workflows_in_directory(config.templatesPath)
    }
    return json.dumps({"templates": templates})
Exemple #2
0
 def __func():
     if playbook_name == "templates":
         templates = {
             os.path.splitext(workflow)[0]:
             helpers.get_workflow_names_from_file(
                 os.path.join(core.config.paths.templates_path, workflow))
             for workflow in helpers.locate_playbooks_in_directory(
                 core.config.paths.templates_path)
         }
         return templates, SUCCESS
     else:
         try:
             playbooks = running_context.controller.get_all_workflows()
             playbook = next((playbook for playbook in playbooks
                              if playbook['name'] == playbook_name), None)
             if playbook is not None:
                 return playbook['workflows'], SUCCESS
             else:
                 current_app.logger.error(
                     'Playbook {0} was not found'.format(playbook_name))
                 return {
                     "error": "Playbook does not exist."
                 }, OBJECT_DNE_ERROR
         except Exception as e:
             return {"error": "{0}".format(e)}, INVALID_INPUT_ERROR
Exemple #3
0
def display_available_playbooks():
    try:
        workflows = {
            os.path.splitext(workflow)[0]:
            helpers.get_workflow_names_from_file(
                os.path.join(config.workflowsPath, workflow))
            for workflow in locate_workflows_in_directory()
        }
        return json.dumps({"status": "success", "playbooks": workflows})
    except Exception as e:
        return json.dumps({"status": "error: {0}".format(e)})
 def test_load_all_workflows_from_directory(self):
     path = config.test_workflows_path
     workflows = helpers.locate_workflows_in_directory(path)
     keys = []
     for workflow in workflows:
         for name in helpers.get_workflow_names_from_file(
                 os.path.join(config.test_workflows_path, workflow)):
             playbook_name = workflow.split('.')[0]
             keys.append(_WorkflowKey(playbook_name, name))
     self.controller.load_all_workflows_from_directory(path=path)
     for key in keys:
         self.assertTrue(key in self.controller.workflows)
Exemple #5
0
 def test_load_all_workflows_from_directory(self):
     path = config.test_workflows_path
     workflows = helpers.locate_workflows_in_directory(path)
     keys = []
     invalid_workflows = [
         'invalidActionWorkflow', 'invalidAppWorkflow',
         'tooManyStepInputsWorkflow', 'invalidInputWorkflow'
     ]
     for workflow in workflows:
         for name in helpers.get_workflow_names_from_file(
                 os.path.join(config.test_workflows_path, workflow)):
             playbook_name = workflow.split('.')[0]
             if playbook_name not in invalid_workflows:
                 keys.append(_WorkflowKey(playbook_name, name))
     self.controller.load_all_workflows_from_directory(path=path)
     for key in keys:
         self.assertTrue(key in self.controller.workflows)
Exemple #6
0
def display_playbook_workflows(name):
    try:
        workflows = {
            os.path.splitext(workflow)[0]:
            helpers.get_workflow_names_from_file(
                os.path.join(config.workflowsPath, workflow))
            for workflow in locate_workflows_in_directory()
        }
        if name in workflows:
            return json.dumps({
                "status": "success",
                "workflows": workflows[name]
            })
        else:
            return json.dumps({"status": "error: name not found"})
    except Exception as e:
        return json.dumps({"status": "error: {0}".format(e)})
Exemple #7
0
def read_playbook_get_templates(playbook_name):
    if playbook_name == "templates":
        templates = {
            os.path.splitext(workflow)[0]:
            helpers.get_workflow_names_from_file(
                os.path.join(core.config.paths.templates_path, workflow))
            for workflow in helpers.locate_workflows_in_directory(
                core.config.paths.templates_path)
        }
        return json.dumps({"status": "success", "templates": templates})
    else:
        try:
            workflows = running_context.controller.get_all_workflows()
            if playbook_name in workflows:
                return json.dumps({
                    "status": "success",
                    "workflows": workflows[playbook_name]
                })
            else:
                return json.dumps({"status": "error: name not found"})
        except Exception as e:
            return json.dumps({"status": "error: {0}".format(e)})