wow woah, we don't need to save locally actually

This commit is contained in:
grumbulon 2023-02-04 21:49:23 -05:00 committed by Gitea
parent f7f0a49512
commit bca521eb4e
2 changed files with 14 additions and 35 deletions

View file

@ -28,27 +28,22 @@ func makeLocal(where path, zone *ZoneRequest) error {
return errEmptyFile
}
switch where {
case Tmp:
path = fmt.Sprintf("/tmp/tmpfile-%s-%s", zone.RawFileName, zone.User)
case Perm:
c, err = internal.ReadConfig()
c, err = internal.ReadConfig()
if err != nil {
logHandler(genericResponseFields{"error": err.Error(), "message": "no config file defined"})
if err != nil {
logHandler(genericResponseFields{"error": err.Error(), "message": "no config file defined"})
return fmt.Errorf("unable to parse directory: %w", err)
}
return fmt.Errorf("unable to parse directory: %w", err)
}
path = fmt.Sprintf("%s/%s/", c.ZoneDir, zone.RawFileName)
path = fmt.Sprintf("%s/%s/", c.ZoneDir, zone.RawFileName)
file = zone.RawFileName
file = zone.RawFileName
if err = os.MkdirAll(path, 0o750); err != nil {
logHandler(genericResponseFields{"error": err.Error(), "message": "unable to make directory for zone files"})
if err = os.MkdirAll(path, 0o750); err != nil {
logHandler(genericResponseFields{"error": err.Error(), "message": "unable to make directory for zone files"})
return fmt.Errorf("unable to make zone directory: %w", err)
}
return fmt.Errorf("unable to make zone directory: %w", err)
}
f, err := os.Create(filepath.Clean(path + file)) //nolint: gosec

View file

@ -5,8 +5,6 @@ import (
"io"
"log"
"net/http"
"os"
"path/filepath"
"strings"
"git.freecumextremist.com/grumbulon/pomme/internal"
@ -68,8 +66,8 @@ func ReceiveFile(w http.ResponseWriter, r *http.Request) {
zoneFile := newDNSRequest(header.Filename, claims["username"].(string), b)
if err := zoneFile.save(Tmp); err != nil {
APIError(w, r, genericResponseFields{"message": "Unable to save zonefile", "status": http.StatusInternalServerError, "error": err.Error()})
if err := zoneFile.parse(); err != nil {
APIError(w, r, genericResponseFields{"message": "Unable to parse zonefile", "status": http.StatusInternalServerError, "error": err.Error()})
return
}
@ -90,12 +88,6 @@ func ReceiveFile(w http.ResponseWriter, r *http.Request) {
},
})
if err := zoneFile.parse(); err != nil {
APIError(w, r, genericResponseFields{"message": "Unable to parse zonefile", "status": http.StatusInternalServerError, "error": err.Error()})
return
}
if err := zoneFile.save(Perm); err != nil {
APIError(w, r, genericResponseFields{"message": "Unable to save zonefile", "status": http.StatusInternalServerError, "error": err.Error()})
@ -139,16 +131,8 @@ func (zone *ZoneRequest) parse() error {
return nil
}
func (zone *ZoneRequest) save(path) error {
// clean up the tmp file
defer func() (err error) {
if err = os.Remove(filepath.Clean("/tmp/" + zone.FileName)); err != nil {
return
}
return
}()
return makeLocal(Perm, zone)
func (zone *ZoneRequest) save(p path) error {
return makeLocal(p, zone)
}
func validateContentType(file io.Reader) bool {