diff --git a/configdb/db/db_api.py b/configdb/db/db_api.py index 218229423ef50c059b354e7d2f94cac402a42d89..3347e6491096965746fe9ac86b16525bdaa70e52 100644 --- a/configdb/db/db_api.py +++ b/configdb/db/db_api.py @@ -241,3 +241,21 @@ class AdmDbApi(object): self.schema.acl_check_entity(ent, auth_context, 'r', None) return self.db.get_audit(query, session) + + @with_session + def get_timestamp(self, session, entity_name, auth_context): + """Get the timestamp of the last update on an entity. + + """ + ent = self.schema.get_entity(entity_name) + if not ent: + raise exceptions.NotFound(entity_name) + + self.schema.acl_check_entity(ent, auth_context, 'r', None) + + obj = self.db.get_by_name('__timestamp', entity_name, session) + if not obj: + raise exceptions.NotFound(entity_name) + return obj + + diff --git a/configdb/server/wsgiapp.py b/configdb/server/wsgiapp.py index e6f818bc9a6df402e88b41995c48973e7d3d02d4..b98b079c754f9ba75ad6be7f7e9623088f2b627a 100644 --- a/configdb/server/wsgiapp.py +++ b/configdb/server/wsgiapp.py @@ -156,6 +156,14 @@ def find(class_name): def delete(class_name, object_name): return g.api.delete(class_name, object_name, g.auth_ctx) +@api_app.route('/timestamp/<class_name>') +@authenticate +def ts(class_name): + try: + res = g.api.get_timestamp(class_name, g.auth_ctx) + return str(res.ts) + except exceptions.NotFound: + return "0" @api_app.route('/audit', methods=['POST']) @authenticate