Esempio n. 1
0
class TargetsResource(ApiResource):

    validator = get_validator(target_schema)

    def on_post(self, req, resp, tenant_id):
        target_id = str(uuid.uuid4())

        body = self.load_body(req, self.validator)
        body['id'] = target_id

        target = Target.build_target_from_dict(tenant_id, body)
        duplicate_target = Target.get_target(tenant_id, target_id=target.name)

        if duplicate_target:
            raise falcon.exceptions.HTTPConflict(
                'Duplicate Target Name',
                'Target names must be unique: {0}'.format(target.name))

        Target.save_target(target)

        resp.status = falcon.HTTP_201
        resp.body = self.format_response_body({'target_id': target_id})

    def on_get(self, req, resp, tenant_id):
        targets = Target.get_targets(tenant_id)
        target_list = [target.summary_dict() for target in targets]

        resp.body = self.format_response_body({'targets': target_list})
Esempio n. 2
0
class JobsResource(ApiResource):

    validator = get_validator(job_schema)

    def on_post(self, req, resp, tenant_id):
        body = self.load_body(req, self.validator)
        body['tenant_id'] = tenant_id

        job = Job.build_job_from_dict(body)
        Job.save_job(job)

        resp.status = falcon.HTTP_201
        resp.body = self.format_response_body({'job_id': job.id})

    def on_get(self, req, resp, tenant_id):
        jobs_list = [job.summary_dict() for job in Job.get_jobs(tenant_id)]
        resp.body = self.format_response_body({'jobs': jobs_list})
Esempio n. 3
0
class SchedulesResource(ApiResource):

    validator = get_validator(schedule_schema)

    def on_get(self, req, resp, tenant_id):
        schedules_list = [
            s.as_dict() for s in Schedule.get_schedules(tenant_id)
        ]
        resp.body = self.format_response_body({'schedules': schedules_list})

    def on_post(self, req, resp, tenant_id):
        schedule_id = str(uuid.uuid4())
        body = self.load_body(req, self.validator)
        body['id'] = schedule_id

        schedule = Schedule.build_schedule_from_dict(tenant_id, body)

        Schedule.save_schedule(schedule)

        resp.status = falcon.HTTP_201
        resp.body = self.format_response_body({'schedule_id': schedule_id})
Esempio n. 4
0
 def validates(self, body):
     body = json.loads(body)
     validator = get_validator(schedule_schema)
     validator.validate(body)
Esempio n. 5
0
 def fails_to_falidate(self, body):
     body = json.loads(body)
     validator = get_validator(schedule_schema)
     expect(validator.validate, [body]).to.raise_a(ValidationError)
Esempio n. 6
0
 def validates(self, body):
     body = json.loads(body)
     validator = get_validator(schedule_schema)
     validator.validate(body)
Esempio n. 7
0
 def fails_to_falidate(self, body):
     body = json.loads(body)
     validator = get_validator(schedule_schema)
     expect(validator.validate, [body]).to.raise_a(ValidationError)
Esempio n. 8
0
 def validates(self, body):
     validator = get_validator(target_schema)
     validator.validate(body)
Esempio n. 9
0
 def fails_to_validate(self, body):
     validator = get_validator(target_schema)
     expect(validator.validate, [body]).to.raise_a(ValidationError)
Esempio n. 10
0
 def validates(self, body):
     validator = get_validator(target_schema)
     validator.validate(body)
Esempio n. 11
0
 def fails_to_validate(self, body):
     validator = get_validator(target_schema)
     expect(validator.validate, [body]).to.raise_a(ValidationError)