diff --git a/internal/api/fs.go b/internal/api/fs.go index 3df8e1d..be9a3ae 100644 --- a/internal/api/fs.go +++ b/internal/api/fs.go @@ -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 diff --git a/internal/api/zone.go b/internal/api/zone.go index 8e516db..d4e599a 100644 --- a/internal/api/zone.go +++ b/internal/api/zone.go @@ -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 {