Skip to content

HMS-5390: omit null values in upload response #953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3669,9 +3669,6 @@ const docTemplate = `{
"definitions": {
"api.AddUploadsRequest": {
"type": "object",
"required": [
"uploads"
],
"properties": {
"artifacts": {
"description": "List of created artifacts",
Expand Down
3 changes: 0 additions & 3 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
"type": "array"
}
},
"required": [
"uploads"
],
"type": "object"
},
"api.Artifact": {
Expand Down
18 changes: 9 additions & 9 deletions pkg/api/uploads.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package api
import "time"

type AddUploadsRequest struct {
Uploads []Upload `json:"uploads" validate:"required"` // List of unfinished uploads
Artifacts []Artifact `json:"artifacts"` // List of created artifacts
Uploads []Upload `json:"uploads"` // List of unfinished uploads
Artifacts []Artifact `json:"artifacts"` // List of created artifacts
}

type Upload struct {
Expand All @@ -25,12 +25,12 @@ type UploadChunkRequest struct {
}

type UploadResponse struct {
ArtifactHref *string `json:"artifact_href"` // Artifact href if one exists (on create only)
CompletedChecksums []string `json:"completed_checksums"` // A list of already completed checksums
UploadUuid *string `json:"upload_uuid"` // Upload UUID
Created *time.Time `json:"created"` // Timestamp of creation
LastUpdated *time.Time `json:"last_updated"` // Timestamp of last update
Size int64 `json:"size"` // Size of the upload in bytes
Completed *time.Time `json:"completed,omitempty"` // Timestamp when upload is committed
ArtifactHref *string `json:"artifact_href,omitempty"` // Artifact href if one exists (on create only)
CompletedChecksums []string `json:"completed_checksums,omitempty"` // A list of already completed checksums
UploadUuid *string `json:"upload_uuid"` // Upload UUID
Created *time.Time `json:"created,omitempty"` // Timestamp of creation
LastUpdated *time.Time `json:"last_updated,omitempty"` // Timestamp of last update
Size int64 `json:"size"` // Size of the upload in bytes
Completed *time.Time `json:"completed,omitempty"` // Timestamp when upload is committed

}
37 changes: 19 additions & 18 deletions pkg/handler/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,33 +606,35 @@ func (rh *RepositoryHandler) createUpload(c echo.Context) error {
return err
}

if artifactHref != nil {
existingUUID, completedChunks, err := ph.DaoRegistry.Uploads.GetExistingUploadIDAndCompletedChunks(c.Request().Context(), orgId, req.Sha256, req.ChunkSize)
if err != nil {
return err
}

// pulp artifact has already been created and uploaded content is being reused
if artifactHref != nil && existingUUID != "" {
resp := &api.UploadResponse{
ArtifactHref: artifactHref,
UploadUuid: &existingUUID,
ArtifactHref: artifactHref,
Size: req.Size,
CompletedChecksums: completedChunks,
}

return c.JSON(http.StatusCreated, resp)
}

existingUUID, completedChunks, err := ph.DaoRegistry.Uploads.GetExistingUploadIDAndCompletedChunks(c.Request().Context(), orgId, req.Sha256, req.ChunkSize)

if err != nil {
return err
}

// pulp artifact has not been created yet, but uploaded content has been saved in our db and can be reused
if existingUUID != "" {
resp := &api.UploadResponse{
UploadUuid: &existingUUID,
Size: req.ChunkSize,
Size: req.Size,
CompletedChecksums: completedChunks,
ArtifactHref: utils.Ptr(""),
}

return c.JSON(http.StatusCreated, resp)
}

pulpResp, err := ph.createUploadInternal(c, req)

if err != nil {
return err
}
Expand All @@ -642,14 +644,13 @@ func (rh *RepositoryHandler) createUpload(c echo.Context) error {
uploadUuid = extractUploadUuid(*pulpResp.PulpHref)
}

// new content to upload
resp := &api.UploadResponse{
UploadUuid: &uploadUuid,
Created: pulpResp.PulpCreated,
LastUpdated: pulpResp.PulpLastUpdated,
Size: pulpResp.Size,
Completed: pulpResp.Completed,
ArtifactHref: utils.Ptr(""),
CompletedChecksums: make([]string, 0),
UploadUuid: &uploadUuid,
Created: pulpResp.PulpCreated,
LastUpdated: pulpResp.PulpLastUpdated,
Size: pulpResp.Size,
Completed: pulpResp.Completed,
}

return c.JSON(http.StatusCreated, resp)
Expand Down
Loading