From e6a1c158fce06713402be2180eb6676ecab8db61 Mon Sep 17 00:00:00 2001 From: Tenyo Grozev Date: Thu, 19 Nov 2020 18:21:36 -0500 Subject: [PATCH] fixup --- api/handlers_logs.go | 179 +------------------------------------------ 1 file changed, 1 insertion(+), 178 deletions(-) diff --git a/api/handlers_logs.go b/api/handlers_logs.go index 02b7eaa..4934db5 100644 --- a/api/handlers_logs.go +++ b/api/handlers_logs.go @@ -9,98 +9,6 @@ import ( "github.com/gorilla/mux" ) -// AttachmentCreateHandler adds an attachment file to a dataset -// func (s *server) AttachmentCreateHandler(w http.ResponseWriter, r *http.Request) { -// w = LogWriter{w} -// vars := mux.Vars(r) -// account := vars["account"] -// group := vars["group"] -// id := vars["id"] - -// service, ok := s.datasetServices[account] -// if !ok { -// msg := fmt.Sprintf("account not found: %s", account) -// handleError(w, apierror.New(apierror.ErrNotFound, msg, nil)) -// return -// } - -// metadata, err := service.MetadataRepository.Get(r.Context(), account, id) -// if err != nil { -// handleError(w, err) -// return -// } - -// attachmentRepo, ok := service.AttachmentRepository[metadata.DataStorage] -// if !ok { -// msg := fmt.Sprintf("requested attachment repository type not supported for this account: %s", metadata.DataStorage) -// handleError(w, apierror.New(apierror.ErrBadRequest, msg, nil)) -// return -// } - -// // limit total request size to 50 MB -// r.Body = http.MaxBytesReader(w, r.Body, 50<<20) -// defer r.Body.Close() - -// // parse the multipart form and keep up to 32 MB in memory (the rest on temp disk) -// err = r.ParseMultipartForm(32 << 20) -// if err != nil { -// handleError(w, apierror.New(apierror.ErrBadRequest, "failed to parse multipart request", err)) -// return -// } - -// // get the attachment name -// attachmentName := r.FormValue("name") -// if attachmentName == "" { -// handleError(w, apierror.New(apierror.ErrBadRequest, "failed to parse form value: name", err)) -// return -// } - -// log.Debugf("attachment name: %s", attachmentName) - -// // get the (first) attachment file -// attachment, attachmentHeader, err := r.FormFile("attachment") -// if err != nil { -// handleError(w, apierror.New(apierror.ErrBadRequest, "failed to parse attachment", err)) -// return -// } -// defer attachment.Close() - -// log.Debugf("attachment size (bytes): %v", attachmentHeader.Size) - -// if attachmentHeader.Size > maxAttachmentSize { -// msg := fmt.Sprintf("attachment size too big (max limit is %d bytes)", maxAttachmentSize) -// handleError(w, apierror.New(apierror.ErrBadRequest, msg, err)) -// return -// } - -// err = attachmentRepo.CreateAttachment(r.Context(), id, attachmentName, attachment) -// if err != nil { -// msg := fmt.Sprintf("failed to create attachment for dataset %s: %s", id, err) -// handleError(w, apierror.New(apierror.ErrInternalError, msg, err)) -// return -// } - -// output := []string{ -// attachmentName, -// } - -// j, err := json.Marshal(&output) -// if err != nil { -// msg := fmt.Sprintf("cannot encode dataset attachment output into json: %s", err) -// handleError(w, apierror.New(apierror.ErrBadRequest, msg, err)) -// return -// } - -// // write to audit log -// auditLog := service.AuditLogRepository.Log(r.Context(), group, id) -// msg := fmt.Sprintf("Created new attachment for dataset %s (Name: %s, Size: %d bytes)", id, attachmentName, attachmentHeader.Size) -// auditLog <- msg - -// w.Header().Set("Content-Type", "application/json") -// w.WriteHeader(http.StatusOK) -// w.Write(j) -// } - // LogListHandler returns the audit logs for a dataset func (s *server) LogListHandler(w http.ResponseWriter, r *http.Request) { w = LogWriter{w} @@ -116,31 +24,8 @@ func (s *server) LogListHandler(w http.ResponseWriter, r *http.Request) { return } - // metadata, err := service.MetadataRepository.Get(r.Context(), account, id) - // if err != nil { - // handleError(w, err) - // return - // } - - // attachmentRepo, ok := service.AttachmentRepository[metadata.DataStorage] - // if !ok { - // msg := fmt.Sprintf("requested attachment repository type not supported for this account: %s", metadata.DataStorage) - // handleError(w, apierror.New(apierror.ErrBadRequest, msg, nil)) - // return - // } - - // list attachments for this data repository - // datasetAttachments, err := attachmentRepo.ListAttachments(r.Context(), id, true) - // if err != nil { - // msg := fmt.Sprintf("failed to list attachments for dataset %s: %s", id, err) - // handleError(w, apierror.New(apierror.ErrInternalError, msg, err)) - // return - // } - - // write to audit log + // get audit log for this dataset auditLog, err := service.AuditLogRepository.GetLog(r.Context(), group, id) - // msg := fmt.Sprintf("Deleted attachment for dataset %s (Name: %s)", id, input.AttachmentName) - // auditLog <- msg j, err := json.Marshal(auditLog) if err != nil { @@ -153,65 +38,3 @@ func (s *server) LogListHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write(j) } - -// AttachmentDeleteHandler removes an attachment file from a dataset -// func (s *server) AttachmentDeleteHandler(w http.ResponseWriter, r *http.Request) { -// w = LogWriter{w} -// vars := mux.Vars(r) -// account := vars["account"] -// group := vars["group"] -// id := vars["id"] - -// service, ok := s.datasetServices[account] -// if !ok { -// msg := fmt.Sprintf("account not found: %s", account) -// handleError(w, apierror.New(apierror.ErrNotFound, msg, nil)) -// return -// } - -// input := struct { -// AttachmentName string `json:"attachment_name"` -// }{} - -// err := json.NewDecoder(r.Body).Decode(&input) -// if err != nil { -// msg := fmt.Sprintf("cannot decode body into delete attachment input: %s", err) -// handleError(w, apierror.New(apierror.ErrBadRequest, msg, err)) -// return -// } - -// if input.AttachmentName == "" { -// handleError(w, apierror.New(apierror.ErrBadRequest, "attachment_name is required", nil)) -// return -// } - -// metadata, err := service.MetadataRepository.Get(r.Context(), account, id) -// if err != nil { -// handleError(w, err) -// return -// } - -// attachmentRepo, ok := service.AttachmentRepository[metadata.DataStorage] -// if !ok { -// msg := fmt.Sprintf("requested attachment repository type not supported for this account: %s", metadata.DataStorage) -// handleError(w, apierror.New(apierror.ErrBadRequest, msg, nil)) -// return -// } - -// // delete attachment from this data repository -// err = attachmentRepo.DeleteAttachment(r.Context(), id, input.AttachmentName) -// if err != nil { -// msg := fmt.Sprintf("failed to delete attachment '%s' for dataset %s: %s", input.AttachmentName, id, err) -// handleError(w, apierror.New(apierror.ErrInternalError, msg, err)) -// return -// } - -// // write to audit log -// auditLog := service.AuditLogRepository.Log(r.Context(), group, id) -// msg := fmt.Sprintf("Deleted attachment for dataset %s (Name: %s)", id, input.AttachmentName) -// auditLog <- msg - -// w.Header().Set("Content-Type", "application/json") -// w.WriteHeader(http.StatusNoContent) -// w.Write([]byte{}) -// }