def post(self): """Method to create an application""" appeui = self.args['appeui'] name = self.args['name'] domain = self.args['domain'] appnonce = self.args['appnonce'] appkey = self.args['appkey'] fport = self.args['fport'] appinterface_id = self.args['appinterface_id'] message = {} # Check for required args required = {'appeui', 'name', 'appnonce', 'appkey', 'fport'} for r in required: if self.args[r] is None: message[r] = "Missing the {} parameter.".format(r) if message: abort(400, message=message) # Check this application does not currently exist exists = yield Application.exists(where=['appeui = ?', appeui]) if exists: message = { 'error': "Application EUI {} currently exists".format(euiString(appeui)) } abort(400, message=message) # Check the appkey doesn't exist exists = yield Application.exists(where=['appkey = ?', appkey]) if exists: message = { 'error': "Application key {} currently exists".format( intHexString(appkey, 16)) } abort(400, message=message) # Create and validate app = Application(appeui=appeui, name=name, domain=domain, appnonce=appnonce, appkey=appkey, fport=fport, appinterface_id=appinterface_id) (valid, message) = yield app.valid() if not valid: abort(400, message=message) try: a = yield app.save() if a is None: abort(500, message={'error': "Error saving the application."}) location = self.restapi.api.prefix + '/app/' + str(appeui) returnValue(({}, 201, {'Location': location})) except TimeoutError: # Exception returns 500 to client log.error("REST API timeout for application POST request")
def _test_application(self): """Create a test application object. We must load dynamically as it depends on the adbapi intialisation""" return Application( appeui=int('0x0A0B0C0D0A0B0C0D', 16), name='app', domain='fluentnetworks.com.au', appnonce=int('0xC28AE9', 16), appkey=int('0x017E151638AEC2A6ABF7258809CF4F3C', 16), fport=15, )