def post(self): """Method to create an Application Interface""" klass = self.args['type'] name = self.args['name'] message = {} try: if klass == 'azure': protocol = self.args['protocol'] iothost = self.args['iothost'] keyname = self.args['keyname'] keyvalue = self.args['keyvalue'] poll_interval = self.args['pollinterval'] # Check for required args required = { 'type', 'name', 'protocol', 'iothost', 'keyname', 'keyvalue', 'pollinterval' } for r in required: if self.args[r] is None: message[r] = "Missing the {} parameter.".format(r) if message: abort(400, message=message) if protocol != 'https': message = "Unknown protocol type {}.".format(protocol) abort(400, message=message) # Check this interface does not currently exist exists = yield AzureIotHttps.exists(where=['name = ?', name]) if exists: message = { 'error': "Azure Https Interface {} currently exists".format( name) } abort(400, message=message) # Create the interface interface = AzureIotHttps(name=name, iothost=iothost, keyname=keyname, keyvalue=keyvalue, poll_interval=poll_interval) elif klass == 'reflector': # Required args required = {'type', 'name'} for r in required: if self.args[r] is None: message[r] = "Missing the {} parameter.".format(r) if message: abort(400, message=message) # Create the interface interface = Reflector(name=name) else: message = {'error': "Unknown interface type"} abort(400, message=message) (valid, message) = yield interface.valid() if not valid: abort(400, message=message) # Add the new interface id = interfaceManager.createInterface(interface) location = self.restapi.api.prefix + '/interface/' + str(id) returnValue(({}, 201, {'Location': location})) except TimeoutError: # Exception returns 500 to client log.error( "REST API timeout for application interface POST request")
def post(self): """Method to create an Application Interface""" klass = self.args['type'] name = self.args['name'] message = {} try: if klass == 'azure': protocol = self.args['protocol'] iothost = self.args['iothost'] keyname = self.args['keyname'] keyvalue = self.args['keyvalue'] poll_interval = self.args['pollinterval'] # Check for required args required = { 'type', 'name', 'protocol', 'iothost', 'keyname', 'keyvalue' } for r in required: if self.args[r] is None: message[r] = "Missing the {} parameter.".format(r) if protocol == 'https' and poll_interval is None: message[ 'poll_interval'] = "Missing the poll_interval parameter." if message: abort(400, message=message) # Check protocol type if not protocol in {'https', 'mqtt'}: message = "Unknown protocol type {}.".format(protocol) abort(400, message=message) # Create the interface if protocol == 'https': interface = AzureIotHttps(name=name, iothost=iothost, keyname=keyname, keyvalue=keyvalue, poll_interval=poll_interval) elif protocol == 'mqtt': interface = AzureIotMqtt(name=name, iothost=iothost, keyname=keyname, keyvalue=keyvalue) elif klass == 'filetext': file = self.args['file'] required = {'type', 'name', 'file'} for r in required: if self.args[r] is None: message[r] = "Missing the {} parameter.".format(r) if message: abort(400, message=message) # Create the interface interface = FileTextStore(name=name, file=file) elif klass == 'reflector': # Required args required = {'type', 'name'} for r in required: if self.args[r] is None: message[r] = "Missing the {} parameter.".format(r) if message: abort(400, message=message) # Create the interface interface = Reflector(name=name) else: message = {'error': "Unknown interface type"} abort(400, message=message) (valid, message) = yield interface.valid() if not valid: abort(400, message=message) # Add the new interface id = interfaceManager.createInterface(interface) location = self.restapi.api.prefix + '/interface/' + str(id) returnValue(({}, 201, {'Location': location})) except TimeoutError: # Exception returns 500 to client log.error( "REST API timeout for application interface POST request")