def put(self, imp_uuid): ''' Replace imp ''' logging.info('request.arguments {0}'.format(self.request.arguments)) logging.info('request.body {0}'.format(self.request.body)) struct = yield check_json(self.request.body) logging.info('put received struct {0}'.format(struct)) format_pass = (True if not struct.get('errors') else False) if not format_pass: self.set_status(400) self.finish({'JSON':format_pass}) return account = self.request.arguments.get('account', [None])[0] result = yield self.replace_imp(account, imp_uuid, struct) if not result: self.set_status(400) system_error = errors.Error('missing') error = system_error.missing('imp', imp_uuid) self.finish(error) return self.set_status(200) self.finish({'message': 'replace completed successfully'})
def patch(self, node_uuid): ''' Modify node ''' logging.info('request.arguments {0}'.format(self.request.arguments)) logging.info('request.body {0}'.format(self.request.body)) struct = yield check_json(self.request.body) logging.info('patch receive struct {0}'.format(struct)) format_pass = (True if not dict(struct).get('errors', False) else False) if not format_pass: self.set_status(400) self.finish({'JSON':format_pass}) return account = self.request.arguments.get('account', [None])[0] result = yield self.modify_node(account, node_uuid.rstrip('/'), struct) if not result: self.set_status(400) system_error = errors.Error('missing') error= system_error.missing('node', node_uuid) self.finish(error) return self.set_status(200) self.finish({'message': 'update completed successfully'})
def post(self): ''' Create node ''' struct = yield check_json(self.request.body) format_pass = (True if struct and not struct.get('errors') else False) if not format_pass: self.set_status(400) self.finish({'JSON':format_pass}) return logging.info('new node structure {0}'.format(str(struct))) new_node = yield self.new_node(struct) if 'error' in new_node: model = 'node' reason = {'duplicates': [(model, 'account')]} message = yield self.let_it_crash(struct, model, new_node, reason) logging.warning(message) self.set_status(400) self.finish(message) return self.set_status(201) self.finish({'uuid':new_node})
def post(self): ''' Create index ''' # post structure struct = yield check_json(self.request.body) # format pass (). format_pass = (True if struct and not struct.get('errors') else False) if not format_pass: self.set_status(400) self.finish({'JSON':format_pass}) return # settings database db = self.settings.get('db') # logging new index structure logging.info('new index structure {0}'.format(str(struct))) # logging request query arguments logging.info(self.request.arguments) # request query arguments query_args = self.request.arguments # get account from new index struct account = struct.get('account', None) # get the current frontend logged username username = self.get_current_username() # if the user don't provide an account we use the frontend username as last resort account = (query_args.get('account', [username])[0] if not account else account) # we use the front-end username as last resort if not struct.get('account'): struct['account'] = account new_index = yield self.new_index(struct) if 'error' in new_index: scheme = 'index' reason = {'duplicates': [ (scheme, 'name'), (scheme, 'index_type') ]} message = yield self.let_it_crash(struct, scheme, new_index, reason) logging.warning(message) self.set_status(400) self.finish(message) return self.set_status(201) self.finish({'uuid':new_index})
def post(self): ''' Create imp ''' # post structure struct = yield check_json(self.request.body) # format pass (). format_pass = (True if struct and not struct.get('errors') else False) if not format_pass: self.set_status(400) self.finish({'JSON':format_pass}) return # settings database db = self.settings.get('db') # logging new imp structure logging.info('new imp structure {0}'.format(str(struct))) # logging request query arguments logging.info(self.request.arguments) # request query arguments query_args = self.request.arguments # get account from new imp struct account = struct.get('account', None) # get the current frontend logged username username = self.get_current_username() # if the user don't provide an account we use the frontend username as last resort account = (query_args.get('account', [username])[0] if not account else account) # we use the front-end username as last resort if not struct.get('account'): struct['account'] = account logging.warning(account) #if 'directory_uuid' in struct: # struct['has_directory'] = yield check_dir_exist( # db, # struct.get('directory_uuid') # ) new_imp = yield self.new_imp(struct) if 'error' in new_imp: scheme = 'imp' reason = {'duplicates': [ (scheme, 'account'), (scheme, 'phone_number') ]} message = yield self.let_it_crash(struct, scheme, new_imp, reason) logging.warning(message) self.set_status(400) self.finish(message) return if struct.get('has_directory'): resource = { 'directory': struct.get('directory_uuid'), 'resource': 'imps', 'uuid': new_imp } update = yield new_resource(db, resource, 'directories', 'directory') logging.info('update {0}'.format(update)) self.set_status(201) self.finish({'uuid':new_imp})