def handle_delete_api(self, user_id, is_admin): mode = self.get_argument("mode", None) if (mode is None) or (mode != "delete"): return False api_name = self.get_argument("api_name", None) if api_name is None: self.log_error("missing api_name") self.send_error() return True publisher = user_id if is_admin: publisher = self.get_argument("publisher", publisher) try: api = JBoxAPISpec(api_name=api_name) if api.get_publisher() != publisher: response = {"code": -1, "data": "No delete permission on this API"} self.write(response) return True api.delete() response = {"code": 0, "data": "API " + api_name + " was deleted"} self.write(response) return True except JBoxDBItemNotFound: response = {"code": 1, "data": "No such API - " + api_name} self.write(response) return True
def handle_delete_api(self, user_id, is_admin): mode = self.get_argument('mode', None) if (mode is None) or (mode != "delete"): return False api_name = self.get_argument('api_name', None) if api_name is None: self.log_error("missing api_name") self.send_error() return True publisher = user_id if is_admin: publisher = self.get_argument('publisher', publisher) try: api = JBoxAPISpec(api_name=api_name) if api.get_publisher() != publisher: response = {'code': -1, 'data': 'No delete permission on this API'} self.write(response) return True api.delete() response = {'code': 0, 'data': 'API ' + api_name + ' was deleted'} self.write(response) return True except JBoxDBItemNotFound: response = {'code': 1, 'data': 'No such API - ' + api_name} self.write(response) return True
def reset(self, api_name): self.api_name = api_name self.num_outstanding = 0 self.mean_outstanding = 0 spec = JBoxAPISpec(api_name) timeout_secs = spec.get_timeout_secs() self.timeout = timedelta(seconds=timeout_secs) if timeout_secs is not None else None self.cmd = spec.get_cmd() self.image_name = spec.get_image_name()
def reset(self, api_name): self.api_name = api_name self.num_outstanding = 0 self.mean_outstanding = 0 spec = JBoxAPISpec(api_name) timeout_secs = spec.get_timeout_secs() self.timeout = timedelta( seconds=timeout_secs) if timeout_secs is not None else None self.cmd = spec.get_cmd() self.image_name = spec.get_image_name()
def handle_create_api(self, user_id, is_admin): mode = self.get_argument('mode', None) if (mode is None) or (mode != "create"): return False api_name = self.get_argument('api_name', '', strip=True) cmd = self.get_argument('cmd', '', strip=True) description = self.get_argument('description', '', strip=True) for val in (api_name, cmd, description): if len(val) == 0: self.log_error("mandatory parameters missing") response = { 'code': -1, 'data': 'manadatory attributes missing' } self.write(response) return True if len(api_name) > 32 or len(cmd) > 512 or len(description) > 512: self.log_error("api specification fields too large") response = { 'code': -1, 'data': 'API specification fields too large' } self.write(response) return True publisher = user_id if is_admin: publisher = self.get_argument('publisher', publisher, strip=True) try: JBoxAPISpec(api_name=api_name) response = {'code': -1, 'data': 'API already exists'} self.write(response) return True except JBoxDBItemNotFound: pass api = JBoxAPISpec(api_name, cmd=cmd, description=description, publisher=publisher, create=True) if api.get_publisher() != publisher: # API got created by someone else! response = {'code': -1, 'data': 'API already exists'} self.write(response) return True response = {'code': 0, 'data': ''} self.write(response) return True
def handle_create_api(self, user_id, is_admin): mode = self.get_argument("mode", None) if (mode is None) or (mode != "create"): return False api_name = self.get_argument("api_name", "", strip=True) cmd = self.get_argument("cmd", "", strip=True) description = self.get_argument("description", "", strip=True) for val in (api_name, cmd, description): if len(val) == 0: self.log_error("mandatory parameters missing") response = {"code": -1, "data": "manadatory attributes missing"} self.write(response) return True if len(api_name) > 32 or len(cmd) > 512 or len(description) > 512: self.log_error("api specification fields too large") response = {"code": -1, "data": "API specification fields too large"} self.write(response) return True publisher = user_id if is_admin: publisher = self.get_argument("publisher", publisher, strip=True) try: JBoxAPISpec(api_name=api_name) response = {"code": -1, "data": "API already exists"} self.write(response) return True except JBoxDBItemNotFound: pass api = JBoxAPISpec(api_name, cmd=cmd, description=description, publisher=publisher, create=True) if api.get_publisher() != publisher: # API got created by someone else! response = {"code": -1, "data": "API already exists"} self.write(response) return True response = {"code": 0, "data": ""} self.write(response) return True
def handle_get_api_info(self, user_id, is_admin): mode = self.get_argument("mode", None) if (mode is None) or (mode != "info"): return False publisher = user_id api_name = None if is_admin: publisher = self.get_argument("publisher", user_id) api_name = self.get_argument("api_name", None) apiinfo = JBoxAPISpec.get_api_info(publisher, api_name) response = {"code": 0, "data": apiinfo} self.write(response) return True
def handle_get_api_info(self, user_id, is_admin): mode = self.get_argument('mode', None) if (mode is None) or (mode != "info"): return False publisher = user_id api_name = None if is_admin: publisher = self.get_argument('publisher', user_id) api_name = self.get_argument('api_name', None) apiinfo = JBoxAPISpec.get_api_info(publisher, api_name) response = {'code': 0, 'data': apiinfo} self.write(response) return True