Contains the Concourse pipeline definition for building a line-server container
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
861 B

  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/andreimarcu/linx-server/backends"
  6. "github.com/zenazn/goji/web"
  7. )
  8. func deleteHandler(c web.C, w http.ResponseWriter, r *http.Request) {
  9. requestKey := r.Header.Get("Linx-Delete-Key")
  10. filename := c.URLParams["name"]
  11. // Ensure that file exists and delete key is correct
  12. metadata, err := storageBackend.Head(filename)
  13. if err == backends.NotFoundErr {
  14. notFoundHandler(c, w, r) // 404 - file doesn't exist
  15. return
  16. } else if err != nil {
  17. unauthorizedHandler(c, w, r) // 401 - no metadata available
  18. return
  19. }
  20. if metadata.DeleteKey == requestKey {
  21. err := storageBackend.Delete(filename)
  22. if err != nil {
  23. oopsHandler(c, w, r, RespPLAIN, "Could not delete")
  24. return
  25. }
  26. fmt.Fprintf(w, "DELETED")
  27. return
  28. } else {
  29. unauthorizedHandler(c, w, r) // 401 - wrong delete key
  30. return
  31. }
  32. }