refactor authentication (#1950)

This commit is contained in:
zryfish
2020-03-15 17:55:55 +08:00
committed by GitHub
parent abf0d66b22
commit eb8a3c0dc6
32 changed files with 522 additions and 381 deletions

View File

@@ -22,38 +22,38 @@ func (h S2iBinaryHandler) UploadS2iBinaryHandler(req *restful.Request, resp *res
err := req.Request.ParseMultipartForm(bytefmt.MEGABYTE * 20)
if err != nil {
klog.Errorf("%+v", err)
api.HandleBadRequest(resp, err)
api.HandleBadRequest(resp, nil, err)
return
}
if len(req.Request.MultipartForm.File) == 0 {
err := restful.NewError(http.StatusBadRequest, "could not get file from form")
klog.Errorf("%+v", err)
api.HandleBadRequest(resp, err)
api.HandleBadRequest(resp, nil, err)
return
}
if len(req.Request.MultipartForm.File["s2ibinary"]) == 0 {
err := restful.NewError(http.StatusBadRequest, "could not get file from form")
klog.Errorf("%+v", err)
api.HandleInternalError(resp, err)
api.HandleInternalError(resp, nil, err)
return
}
if len(req.Request.MultipartForm.File["s2ibinary"]) > 1 {
err := restful.NewError(http.StatusBadRequest, "s2ibinary should only have one file")
klog.Errorf("%+v", err)
api.HandleInternalError(resp, err)
api.HandleInternalError(resp, nil, err)
return
}
defer req.Request.MultipartForm.RemoveAll()
file, err := req.Request.MultipartForm.File["s2ibinary"][0].Open()
if err != nil {
klog.Error(err)
api.HandleInternalError(resp, err)
api.HandleInternalError(resp, nil, err)
return
}
filemd5, err := hashutil.GetMD5(file)
if err != nil {
klog.Error(err)
api.HandleInternalError(resp, err)
api.HandleInternalError(resp, nil, err)
return
}
md5, ok := req.Request.MultipartForm.Value["md5"]
@@ -61,7 +61,7 @@ func (h S2iBinaryHandler) UploadS2iBinaryHandler(req *restful.Request, resp *res
if md5[0] != filemd5 {
err := restful.NewError(http.StatusBadRequest, fmt.Sprintf("md5 not match, origin: %+v, calculate: %+v", md5[0], filemd5))
klog.Error(err)
api.HandleInternalError(resp, err)
api.HandleInternalError(resp, nil, err)
return
}
}
@@ -69,7 +69,7 @@ func (h S2iBinaryHandler) UploadS2iBinaryHandler(req *restful.Request, resp *res
s2ibin, err := h.s2iUploader.UploadS2iBinary(ns, name, filemd5, req.Request.MultipartForm.File["s2ibinary"][0])
if err != nil {
klog.Errorf("%+v", err)
api.HandleInternalError(resp, err)
api.HandleInternalError(resp, nil, err)
return
}
resp.WriteAsJson(s2ibin)
@@ -83,7 +83,7 @@ func (h S2iBinaryHandler) DownloadS2iBinaryHandler(req *restful.Request, resp *r
url, err := h.s2iUploader.DownloadS2iBinary(ns, name, fileName)
if err != nil {
klog.Errorf("%+v", err)
api.HandleInternalError(resp, err)
api.HandleInternalError(resp, nil, err)
return
}
http.Redirect(resp.ResponseWriter, req.Request, url, http.StatusFound)