def on_put(self, req, resp, tenant_id, event_producer_id): #verify the tenant exists tenant = find_tenant(self.db, tenant_id=tenant_id, when_not_found=_tenant_not_found) #verify the event_producer exists event_producer = find_event_producer(self.db, id=event_producer_id, when_not_found= _producer_not_found) #verify the event_producer belongs to the tenant if not event_producer in tenant.event_producers: _producer_not_found() body = load_body(req) #if a key is present, update the event_producer with the value if 'name' in body.keys(): event_producer.name = body['name'] if 'pattern' in body.keys(): event_producer.pattern = body['pattern'] if 'durable' in body.keys(): event_producer.durable = body['durable'] if 'encrypted' in body.keys(): event_producer.encrypted = body['encrypted'] self.db.commit() resp.status = falcon.HTTP_200
def on_get(self, req, resp, tenant_id, event_producer_id): #verify the tenant exists tenant = find_tenant(self.db, tenant_id=tenant_id, when_not_found=_tenant_not_found) #verify the event_producer exists event_producer = find_event_producer(self.db, id=event_producer_id, when_not_found= _producer_not_found) #verify the event_producer belongs to the tenant if not event_producer in tenant.event_producers: _producer_not_found() resp.status = falcon.HTTP_200 resp.body = json.dumps(event_producer.format())
def on_delete(self, req, resp, tenant_id, event_producer_id): #verify the tenant exists tenant = find_tenant(self.db, tenant_id=tenant_id, when_not_found=_tenant_not_found) #verify the event_producer exists event_producer = find_event_producer(self.db, id=event_producer_id, when_not_found= _producer_not_found) #verify the event_producer belongs to the tenant if not event_producer in tenant.event_producers: _producer_not_found() self.db.delete(event_producer) self.db.commit() resp.status = falcon.HTTP_200
def on_post(self, req, resp, tenant_id): tenant = find_tenant(self.db, tenant_id=tenant_id, when_not_found=_tenant_not_found) body = load_body(req) profile_name = body['name'] # Check if the tenant already has a profile with this name for profile in tenant.profiles: if profile.name == profile_name: abort(falcon.HTTP_400, 'Profile with name {0} already exists.' .format(profile.name, profile.id)) # Create the new profile for the host new_host_profile = HostProfile(tenant.id, profile_name) tenant.profiles.append(new_host_profile) if 'event_producer_ids' in body.keys(): event_producer_ids = body['event_producer_ids'] for event_producer_id in event_producer_ids: event_producer = find_event_producer(self.db, id=event_producer_id, when_not_found= _producer_not_found) if event_producer in tenant.event_producers: new_host_profile.event_producers.append(event_producer) else: _producer_not_found() self.db.add(new_host_profile) self.db.commit() resp.status = falcon.HTTP_201 resp.set_header('Location', '/v1/{0}/profiles/{1}' .format(tenant_id, new_host_profile.id))