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.

45 lines
959 B

  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "os"
  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 requested file actually exists
  12. if _, readErr := fileBackend.Exists(filename); os.IsNotExist(readErr) {
  13. notFoundHandler(c, w, r) // 404 - file doesn't exist
  14. return
  15. }
  16. // Ensure delete key is correct
  17. metadata, err := metadataRead(filename)
  18. if err != nil {
  19. unauthorizedHandler(c, w, r) // 401 - no metadata available
  20. return
  21. }
  22. if metadata.DeleteKey == requestKey {
  23. fileDelErr := fileBackend.Delete(filename)
  24. metaDelErr := metaStorageBackend.Delete(filename)
  25. if (fileDelErr != nil) || (metaDelErr != nil) {
  26. oopsHandler(c, w, r, RespPLAIN, "Could not delete")
  27. return
  28. }
  29. fmt.Fprintf(w, "DELETED")
  30. return
  31. } else {
  32. unauthorizedHandler(c, w, r) // 401 - wrong delete key
  33. return
  34. }
  35. }