Beispiel #1
0
 def get(self, id=None):
     queryData = request.args.to_dict()
     if id:
         eval = EvalModel.find_by_id(id)
         if eval: return eval.json(), 200
         else: return {'error': 'evaluation not found'}, 404
     eval = EvalModel.find(**queryData)
     return {'evals': list(map(lambda x: x.json(), eval))}, 200
Beispiel #2
0
 def post(self, **somedata):
     data = json.loads(request.data)
     data["status"] = "NEW"
     eval = EvalModel(**data)
     try:
         eval.save_to_db()
     except:
         return {"error": "An error occurred creating the eval."}, 500
     return eval.json(), 201
Beispiel #3
0
    def evalApplication(self, eval_id):
        eval = EvalModel.find_by_id(eval_id)
        total = self.evaluation(eval)
        if total:
            self.rootLogger.debug(
                'Rules for the evaluation {} are satisfied'.format(eval.id))
            eval.status = "SUCCESSFUL"

        if not total:
            self.rootLogger.debug(
                'Rules for the evaluation {} are not satisfied'.format(
                    eval.id))
            eval.status = "FAILED"
        EvalModel.commit()
        return eval
Beispiel #4
0
 def delete(self, id):
     eval = EvalModel.find_by_id(id)
     if eval:
         eval.delete_from_db()
     else:
         return {'error': 'evaluation not found'}, 404
     return {'success': 'evaluation deleted'}, 202
Beispiel #5
0
 def put(self, id):
     data = json.loads(request.data)
     eval = EvalModel.find_by_id(id)
     if eval:
         eval.update(**data)
     else:
         return {'error': 'evaluation not found'}, 404
     return eval.json(), 201
Beispiel #6
0
 def ProcessEval(self, eval_list, compliance_id):
     for eval_element in eval_list:
         eval = EvalModel(**eval_element)
         eval.compliance_id = compliance_id
         try:
             eval.save_to_db(commit=True)
             print(eval)
             print(eval.json())
         except:
             return {
                 "error": "An error occurred creating the evaluation."
             }, 500
     return
Beispiel #7
0
 def saveJobToDb(self, link, data, workflow_id):
     if link["uid"] in self.elements:
         node_id = link["uid"]
         link["uid"] = self.elements[link["uid"]]
     if link["uid"] == "success" or link["uid"] == "fail":
         return link
     else:
         if link["node_type"] == "job":
             for job_node in data["job_list"]:
                 if job_node == link["uid"]:
                     if data["job_list"][job_node][
                             "agent_type"] == "configuration_differ_postcheck" and "job" in data[
                                 "job_list"][job_node]["parameters"][
                                     "jobID"]:
                         try:
                             data["job_list"][job_node]["parameters"][
                                 "jobID"] = self.elements[data["job_list"][
                                     job_node]["parameters"]["jobID"]]
                         except:
                             data["job_list"][job_node]["parameters"][
                                 "jobID"] = None
                     if data["job_list"][job_node].get('login'):
                         data["job_list"][job_node][
                             'login'] = cipher_suite.encrypt(
                                 data["job_list"][job_node].get('login').
                                 encode('ascii')).decode('ascii')
                     if data["job_list"][job_node].get('password'):
                         data["job_list"][job_node][
                             'password'] = cipher_suite.encrypt(
                                 data["job_list"][job_node].get('password').
                                 encode('ascii')).decode('ascii')
                     job = JobModel(**data["job_list"][job_node])
                     job.workflow_id = workflow_id
                     try:
                         job.save_to_db(commit=True)
                     except:
                         return {
                             "error": "An error occurred creating the job."
                         }, 500
                     self.elements.update(
                         {'{}'.format(link["uid"]): job.id})
                     if link["uid"] == data["start"]:
                         first_job = data["job_list"][job_node]
                     link["uid"] = job.id
         elif link["node_type"] == "eval":
             for eval_node in data["eval_list"]:
                 if eval_node == link["uid"]:
                     eval = EvalModel(**data["eval_list"][eval_node])
                     eval.workflow_id = workflow_id
                     try:
                         eval.save_to_db(commit=True)
                     except:
                         return {
                             "error":
                             "An error occurred creating the evaluation."
                         }, 500
                     self.elements.update(
                         {'{}'.format(link["uid"]): eval.id})
                     node_id = eval.id
                     link["uid"] = eval.id
     return link