Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Tenyo Grozev committed Nov 19, 2020
1 parent 663bfeb commit e6a1c15
Showing 1 changed file with 1 addition and 178 deletions.
179 changes: 1 addition & 178 deletions api/handlers_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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 {
Expand All @@ -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{})
// }

0 comments on commit e6a1c15

Please sign in to comment.