Skip to content

Commit

Permalink
Merge pull request #695 from rajulkumar/add_uploader_info
Browse files Browse the repository at this point in the history
Record uploader info in S3 metadata during upload [RHELDST-234411]
  • Loading branch information
crungehottman committed Apr 30, 2024
2 parents a35cbe2 + 50b00bd commit 6bdea55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion exodus_gw/routers/upload.py
Expand Up @@ -71,7 +71,15 @@
import logging
import textwrap

from fastapi import APIRouter, HTTPException, Path, Query, Request, Response
from fastapi import (
APIRouter,
Depends,
HTTPException,
Path,
Query,
Request,
Response,
)

from .. import auth, deps
from ..aws.client import S3ClientWrapper
Expand Down Expand Up @@ -126,6 +134,7 @@ async def multipart_upload(
),
),
settings: Settings = deps.settings,
caller_name: str = Depends(auth.caller_name),
):
"""Create or complete a multi-part upload.
Expand All @@ -144,6 +153,8 @@ async def multipart_upload(
if uploads == "" and uploadId is None:
# Means a new upload is requested
metadata = extract_request_metadata(request, settings)
# add uploader info in the metadata to track the object modifying entity
metadata["gw-uploader"] = caller_name
return await create_multipart_upload(s3, env, key, metadata)

if uploads is None and uploadId:
Expand Down Expand Up @@ -176,6 +187,7 @@ async def upload(
None, description="Part number, where multi-part upload is used."
),
settings: Settings = deps.settings,
caller_name: str = Depends(auth.caller_name),
):
"""Write to an object, either as a standalone operation or within a multi-part upload.
Expand All @@ -196,6 +208,8 @@ async def upload(
if uploadId is None and partNumber is None:
# Single-part upload
metadata = extract_request_metadata(request, settings)
# add uploader info in the metadata to track the object modifying entity
metadata["gw-uploader"] = caller_name
return await object_put(s3, env, key, request, metadata)

# If either is set, both must be set.
Expand Down
1 change: 1 addition & 0 deletions tests/routers/upload/test_upload.py
Expand Up @@ -39,6 +39,7 @@ async def test_full_upload(
Metadata={
"exodus-migration-md5": "94e19d5d30b26306167e9e7bae6b28fd",
"exodus-migration-src": "original/source",
"gw-uploader": "user fake-user",
},
)

Expand Down

0 comments on commit 6bdea55

Please sign in to comment.