diff --git a/docs/docs.go b/docs/docs.go index 2b132ad..3e42963 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -19,7 +19,7 @@ const docTemplate = `{ "paths": { "/api/login": { "post": { - "description": "login", + "description": "login to Pomme\nRate limited: 5 requests every 5 second", "consumes": [ "application/json" ], @@ -29,7 +29,7 @@ const docTemplate = `{ "tags": [ "accounts" ], - "summary": "auth a regular user", + "summary": "authenticate as a regular user", "parameters": [ { "type": "string", @@ -69,7 +69,7 @@ const docTemplate = `{ "Bearer": [] } ], - "description": "parse your zonefile -- you must specify \"Bearer\" before entering your token", + "description": "parse your zonefile\nRate limited: 10 requests every 10 second\nyou must specify \"Bearer\" before entering your token", "consumes": [ "multipart/form-data" ], @@ -119,7 +119,7 @@ const docTemplate = `{ "Bearer": [] } ], - "description": "upload a file -- you must specify \"Bearer\" before entering your token", + "description": "upload takes files from the user and stores it locally to be parsed. Uploads are associated with a specific user.\nRate limited: 10 requests every 10 second\nyou must specify \"Bearer\" before entering your token", "consumes": [ "multipart/form-data" ], diff --git a/docs/swagger.json b/docs/swagger.json index 0b8a0e3..ad189e9 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -10,7 +10,7 @@ "paths": { "/api/login": { "post": { - "description": "login", + "description": "login to Pomme\nRate limited: 5 requests every 5 second", "consumes": [ "application/json" ], @@ -20,7 +20,7 @@ "tags": [ "accounts" ], - "summary": "auth a regular user", + "summary": "authenticate as a regular user", "parameters": [ { "type": "string", @@ -60,7 +60,7 @@ "Bearer": [] } ], - "description": "parse your zonefile -- you must specify \"Bearer\" before entering your token", + "description": "parse your zonefile\nRate limited: 10 requests every 10 second\nyou must specify \"Bearer\" before entering your token", "consumes": [ "multipart/form-data" ], @@ -110,7 +110,7 @@ "Bearer": [] } ], - "description": "upload a file -- you must specify \"Bearer\" before entering your token", + "description": "upload takes files from the user and stores it locally to be parsed. Uploads are associated with a specific user.\nRate limited: 10 requests every 10 second\nyou must specify \"Bearer\" before entering your token", "consumes": [ "multipart/form-data" ], diff --git a/docs/swagger.yaml b/docs/swagger.yaml index f8f707e..fa70452 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -37,7 +37,9 @@ paths: post: consumes: - application/json - description: login + description: |- + login to Pomme + Rate limited: 5 requests every 5 second parameters: - description: Username in: query @@ -60,15 +62,17 @@ paths: description: Unauthorized schema: $ref: '#/definitions/api.httpError' - summary: auth a regular user + summary: authenticate as a regular user tags: - accounts /api/parse: post: consumes: - multipart/form-data - description: parse your zonefile -- you must specify "Bearer" before entering - your token + description: |- + parse your zonefile + Rate limited: 10 requests every 10 second + you must specify "Bearer" before entering your token parameters: - description: Zonefile name in: query @@ -100,8 +104,10 @@ paths: post: consumes: - multipart/form-data - description: upload a file -- you must specify "Bearer" before entering your - token + description: |- + upload takes files from the user and stores it locally to be parsed. Uploads are associated with a specific user. + Rate limited: 10 requests every 10 second + you must specify "Bearer" before entering your token parameters: - description: Zonefile to upload in: formData diff --git a/internal/api/auth.go b/internal/api/auth.go index f3e7c4e..39aa347 100644 --- a/internal/api/auth.go +++ b/internal/api/auth.go @@ -31,8 +31,11 @@ type httpInternalServerError struct { // Auth godoc // -// @Summary auth a regular user -// @Description login +// @Summary authenticate as a regular user +// @Description login to Pomme +// +// @Description Rate limited: 5 requests every 5 second +// // @Tags accounts // @Accept json // @Produce json diff --git a/internal/api/zone.go b/internal/api/zone.go index 753b3ae..259d6a6 100644 --- a/internal/api/zone.go +++ b/internal/api/zone.go @@ -34,7 +34,11 @@ type Zone struct { // Upload godoc // // @Summary upload a zonefile -// @Description upload a file -- you must specify "Bearer" before entering your token +// @Description upload takes files from the user and stores it locally to be parsed. Uploads are associated with a specific user. +// +// @Description Rate limited: 10 requests every 10 second +// @Description you must specify "Bearer" before entering your token +// // @Tags DNS // @Accept mpfd // @Produce json @@ -71,7 +75,7 @@ func ReceiveFile(w http.ResponseWriter, r *http.Request) { } if err = util.MakeLocal(name[0], claims["username"].(string), buf); err != nil { - internalServerError(w, "internal server error") + internalServerError(w, err.Error()) return } @@ -98,7 +102,11 @@ func ReceiveFile(w http.ResponseWriter, r *http.Request) { // Parse godoc // // @Summary parse your zonefile -// @Description parse your zonefile -- you must specify "Bearer" before entering your token +// @Description parse your zonefile +// +// @Description Rate limited: 10 requests every 10 second +// @Description you must specify "Bearer" before entering your token +// // @Tags DNS // @Accept mpfd // @Produce json diff --git a/internal/util/fs.go b/internal/util/fs.go index 4358573..c46b092 100644 --- a/internal/util/fs.go +++ b/internal/util/fs.go @@ -7,6 +7,10 @@ import ( ) func MakeLocal(filename, username string, buf bytes.Buffer) error { + if _, err := os.Stat(fmt.Sprintf("/tmp/tmpfile-%s-%s", filename, username)); !os.IsNotExist(err) { + return fmt.Errorf("file %s already exists: %w", filename, err) + } + defer buf.Reset() f, err := os.Create("/tmp/tmpfile-" + filename + "-" + username) //nolint: gosec