kc token public key/token issue, path root set to 1

This commit is contained in:
h z
2024-12-06 10:04:03 +00:00
parent 4b9c1ba727
commit 48dd59f8e4
9 changed files with 139 additions and 82 deletions

View File

@@ -11,8 +11,8 @@ logger = logging.getLogger(__name__)
@resource_bp.route('/<identifier>', methods=['GET'])
@limiter.limit('10 per second')
def get_resource(identifier):
with get_db() as db:
resource = db.query(Resource).get(identifier)
with get_db() as session:
resource = session.query(Resource).get(identifier)
if resource is None:
logger.error(f"resource not found: {identifier}")
errno = RequestContext.get_error_id()
@@ -30,13 +30,13 @@ def create_resource():
if not identifier or not content or not data_type:
return jsonify({"error": "missing required fields"}), 400
resource_entry = Resource(id=identifier, content=content, data_type=data_type)
with get_db() as db:
with get_db() as session:
try:
db.add(resource_entry)
db.commit()
session.add(resource_entry)
session.commit()
return jsonify(resource_entry.to_dict()), 201
except Exception as e:
db.rollback()
session.rollback()
logger.error(f"Failed to create resource: {e}")
errno = RequestContext.get_error_id()
return jsonify({"error": f"failed to create resource - {errno}"}), 500
@@ -45,12 +45,12 @@ def create_resource():
@require_auth(roles=["admin"])
@limiter.limit('20 per minute')
def delete_resource(identifier):
with get_db() as db:
resource = db.query(Resource).get(identifier)
with get_db() as session:
resource = session.query(Resource).get(identifier)
if not resource:
logger.error(f"resource not found: {identifier}")
errno = RequestContext.get_error_id()
return jsonify({"error": f"Resource not found - {errno}"}), 404
db.delete(resource)
db.commit()
session.delete(resource)
session.commit()
return jsonify({"message": "Resource deleted"}), 200