def get(self): metadata_entity = store.GetMetadataEntity(self.request) auth_level = store.GetAuthLevel(self.request, metadata_entity) (app, kind, id) = store.extract_path(self.request.path) if not store.IsEncryptionSufficient(self.request, metadata_entity): self.response.set_status(403) self.response.clear() return if not store.IsAuthorized(app, kind, id, auth_level, store.READ): self.response.set_status(401) self.response.clear() return self.response.headers["Access-Control-Allow-Origin"] = "*" self.response.headers["Access-Control-Allow-Headers"] = "Auth-Token" #logging.info("%s, %s, %s" % (app, kind, id)) entity = None if (app is not None and kind is not None and id is not None): include_revisions = self.request.params.get('rev') == '*' (entity, revision_list) = store.get_entity(app, kind, id, include_revisions) if entity: self.response.out.write( store.output_entity_json(entity, revision_list)) self.response.out.write("\n") self.response.headers["X-Num-Results"] = str(1) else: self.response.set_status(404) self.response.clear() return elif (app is not None and kind is not None): results = store.get_entities(app, kind, metadata_entity, self.request.params) self.response.out.write("[\n") first = True count = 0 for r in results: if not first: self.response.out.write(",\n") first = False self.response.out.write(store.output_entity_json(r)) count += 1 self.response.out.write("\n]\n") self.response.headers["X-Num-Results"] = str(count) else: self.response.set_status(404) self.response.clear() return
def get(self): metadata_entity = store.GetMetadataEntity(self.request) auth_level = store.GetAuthLevel(self.request, metadata_entity) (app, kind, id) = store.extract_path(self.request.path) if not store.IsEncryptionSufficient(self.request, metadata_entity): self.response.set_status(403) self.response.clear() return if not store.IsAuthorized(app, kind, id, auth_level, store.READ): self.response.set_status(401) self.response.clear() return self.response.headers["Access-Control-Allow-Origin"] = "*" self.response.headers["Access-Control-Allow-Headers"] = "Auth-Token" # logging.info("%s, %s, %s" % (app, kind, id)) entity = None if app is not None and kind is not None and id is not None: include_revisions = self.request.params.get("rev") == "*" (entity, revision_list) = store.get_entity(app, kind, id, include_revisions) if entity: self.response.out.write(store.output_entity_json(entity, revision_list)) self.response.out.write("\n") self.response.headers["X-Num-Results"] = str(1) else: self.response.set_status(404) self.response.clear() return elif app is not None and kind is not None: results = store.get_entities(app, kind, metadata_entity, self.request.params) self.response.out.write("[\n") first = True count = 0 for r in results: if not first: self.response.out.write(",\n") first = False self.response.out.write(store.output_entity_json(r)) count += 1 self.response.out.write("\n]\n") self.response.headers["X-Num-Results"] = str(count) else: self.response.set_status(404) self.response.clear() return
def post(self): metadata_entity = store.GetMetadataEntity(self.request) auth_level = store.GetAuthLevel(self.request, metadata_entity) (app, kind, id) = store.extract_path(self.request.path) if not store.IsEncryptionSufficient(self.request, metadata_entity): self.response.set_status(403) self.response.clear() return if not store.IsAuthorized(app, kind, id, auth_level, store.WRITE): self.response.set_status(401) self.response.clear() return user = store.GetUser(self.request) # logging.info("%s, %s, %s" % (app, kind, id)) data = self.request.body_file.getvalue() data_obj = {} if len(data) == 0: return if app is not None and kind is not None and id is not None: try: data_obj = json.loads(data, use_decimal=True) except json.JSONDecodeError: self.response.set_status(500) self.response.clear() return datastore.RunInTransaction(store.update_entity, app, kind, id, data_obj, metadata_entity, user) elif self.request.headers["Content-type"].startswith("text/csv") and id is None: key_column = self.request.get("key", None) result = csv_import.ImportCSV(app, kind, key_column, self.request.body_file, metadata_entity, user) if result == -1: self.response.set_status(500) self.response.clear() return self.response.out.write(result) self.response.out.write("\n") elif app is not None and kind is not None and id is None: try: data_obj = json.loads(data, use_decimal=True) except json.JSONDecodeError: self.response.set_status(500) self.response.clear() return if not isinstance(data_obj, list): self.response.set_status(500) self.response.clear() return for data in data_obj: if not "key" in data: self.response.set_status(500) self.response.clear() return count = 0 for data in data_obj: datastore.RunInTransaction(store.update_entity, app, kind, data["key"], data, metadata_entity, user) count += 1 self.response.out.write(count) self.response.out.write("\n")
def post(self): metadata_entity = store.GetMetadataEntity(self.request) auth_level = store.GetAuthLevel(self.request, metadata_entity) (app, kind, id) = store.extract_path(self.request.path) if not store.IsEncryptionSufficient(self.request, metadata_entity): self.response.set_status(403) self.response.clear() return if not store.IsAuthorized(app, kind, id, auth_level, store.WRITE): self.response.set_status(401) self.response.clear() return user = store.GetUser(self.request) #logging.info("%s, %s, %s" % (app, kind, id)) data = self.request.body_file.getvalue() data_obj = {} if (len(data) == 0): return if (app is not None and kind is not None and id is not None): try: data_obj = json.loads(data, use_decimal=True) except json.JSONDecodeError: self.response.set_status(500) self.response.clear() return datastore.RunInTransaction(store.update_entity, app, kind, id, data_obj, metadata_entity, user) elif self.request.headers['Content-type'].startswith( 'text/csv') and id is None: key_column = self.request.get('key', None) result = csv_import.ImportCSV(app, kind, key_column, self.request.body_file, metadata_entity, user) if result == -1: self.response.set_status(500) self.response.clear() return self.response.out.write(result) self.response.out.write("\n") elif (app is not None and kind is not None and id is None): try: data_obj = json.loads(data, use_decimal=True) except json.JSONDecodeError: self.response.set_status(500) self.response.clear() return if not isinstance(data_obj, list): self.response.set_status(500) self.response.clear() return for data in data_obj: if not 'key' in data: self.response.set_status(500) self.response.clear() return count = 0 for data in data_obj: datastore.RunInTransaction(store.update_entity, app, kind, data['key'], data, metadata_entity, user) count += 1 self.response.out.write(count) self.response.out.write("\n")