MCPcopy
hub / github.com/harness/harness / UploadPackageFile

Method UploadPackageFile

registry/app/api/handler/python/upload.go:25–61  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

23)
24
25func (h *handler) UploadPackageFile(w http.ResponseWriter, r *http.Request) {
26 file, fileHeader, err := r.FormFile("content")
27
28 if err != nil {
29 h.HandleError(r.Context(), w, err)
30 return
31 }
32
33 defer file.Close()
34
35 contextInfo := request.ArtifactInfoFrom(r.Context())
36 info, ok := contextInfo.(*pythontype.ArtifactInfo)
37 if !ok {
38 h.HandleError(r.Context(), w, fmt.Errorf("failed to fetch info from context"))
39 return
40 }
41
42 // TODO: Can we extract this out to ArtifactInfoProvider
43 if info.Filename == "" {
44 info.Filename = fileHeader.Filename
45 request.WithArtifactInfo(r.Context(), info)
46 }
47
48 response := h.controller.UploadPackageFile(r.Context(), *info, file, fileHeader)
49
50 if response.GetError() != nil {
51 h.HandleError(r.Context(), w, response.GetError())
52 return
53 }
54
55 response.ResponseHeaders.WriteToResponse(w)
56 _, err = w.Write([]byte(fmt.Sprintf("Pushed.\nSha256: %s", response.Sha256)))
57 if err != nil {
58 h.HandleError(r.Context(), w, err)
59 return
60 }
61}

Callers

nothing calls this directly

Calls 9

HandleErrorMethod · 0.95
ArtifactInfoFromFunction · 0.92
WithArtifactInfoFunction · 0.92
WriteToResponseMethod · 0.80
CloseMethod · 0.65
UploadPackageFileMethod · 0.65
GetErrorMethod · 0.65
WriteMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected