Skip to content

Commit abf2609

Browse files
committed
feat(api): Repurpose submitter
After we decided that giving superprivileges subtokens is bad idea, we can reuse "submitter" for pipeline API, to identify if node origin is pipeline service, or it is user submission (retry, patchset, etc). This might help to filter some of nodes from going to kcidb, for example. Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent ce9ea25 commit abf2609

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

api/main.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import os
1212
import re
13-
import hashlib
1413
from typing import List, Union, Optional
1514
from fastapi import (
1615
Depends,
@@ -317,17 +316,6 @@ async def authorize_user(node_id: str,
317316
return user
318317

319318

320-
def calculate_submitter(hdr: str):
321-
"""Calculate submitter hash from Auth header token"""
322-
token = hdr.split(' ')[1]
323-
if not token:
324-
raise HTTPException(
325-
status_code=status.HTTP_400_BAD_REQUEST,
326-
detail="Token not provided"
327-
)
328-
return hashlib.md5(token.encode()).hexdigest()
329-
330-
331319
@app.get('/users', response_model=PageModel, tags=["user"],
332320
response_model_exclude={"items": {"__all__": {
333321
"hashed_password"}}})
@@ -584,8 +572,9 @@ async def post_node(node: Node,
584572

585573
await _verify_user_group_existence(node.user_groups)
586574
node.owner = current_user.username
587-
# Subtract 'Bearer ' from the token
588-
node.submitter = calculate_submitter(authorization)
575+
# if node.submitter is not set, set it to "pipeline"
576+
if not node.submitter:
577+
node.submitter = "service:pipeline"
589578

590579
# The node is handled as a generic Node by the DB, regardless of its
591580
# specific kind. The concrete Node submodel (Kbuild, Checkout, etc.)
@@ -661,7 +650,15 @@ async def put_nodes(
661650
user: str = Depends(authorize_user)):
662651
"""Add a hierarchy of nodes to an existing root node"""
663652
nodes.node.id = ObjectId(node_id)
664-
submitter = calculate_submitter(authorization)
653+
# Retrieve the root node from the DB and submitter
654+
node_from_id = await db.find_by_id(Node, node_id)
655+
if not node_from_id:
656+
raise HTTPException(
657+
status_code=status.HTTP_404_NOT_FOUND,
658+
detail=f"Node not found with id: {node_id}"
659+
)
660+
submitter = node_from_id.submitter
661+
665662
await _set_node_ownership_recursively(user, nodes, submitter)
666663
obj_list = await db.create_hierarchy(nodes, Node)
667664
data = _get_node_event_data('updated', obj_list[0], True)

0 commit comments

Comments
 (0)