The Great Linting Fixes, Drone configuration fix (again) and flatfile changes.
Great linting fixes has been applied, thanks to golangci-lint for extensive reporting. Fixed Drone configuration to use array for when-branch statement in Docker plugin. Flatfile storage from now will write files with 0600 permission for greater security.
This commit is contained in:
@@ -20,22 +20,22 @@ const KeepPastesForever = "forever"
|
||||
// POST for "/paste/" which will create new paste and redirect to
|
||||
// "/pastes/CREATED_PASTE_ID". This handler will do all the job for
|
||||
// requests comes from browsers via web interface.
|
||||
func pastePOSTWebInterface(ec echo.Context) error {
|
||||
func pastePOSTWebInterface(ectx echo.Context) error {
|
||||
// We should check if database connection available.
|
||||
dbConn := c.Database.GetDatabaseConnection()
|
||||
if c.Config.Database.Type != flatfiles.FlatFileDialect && dbConn == nil {
|
||||
// nolint:wrapcheck
|
||||
return ec.Redirect(http.StatusFound, "/database_not_available")
|
||||
return ectx.Redirect(http.StatusFound, "/database_not_available")
|
||||
}
|
||||
|
||||
params, err := ec.FormParams()
|
||||
params, err := ectx.FormParams()
|
||||
if err != nil {
|
||||
c.Logger.Error().Msg("Passed paste form is empty")
|
||||
|
||||
errtpl := templater.GetErrorTemplate(ec, "Cannot create empty paste")
|
||||
errtpl := templater.GetErrorTemplate(ectx, "Cannot create empty paste")
|
||||
|
||||
// nolint:wrapcheck
|
||||
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||
return ectx.HTML(http.StatusBadRequest, errtpl)
|
||||
}
|
||||
|
||||
c.Logger.Debug().Msgf("Received parameters: %+v", params)
|
||||
@@ -44,29 +44,29 @@ func pastePOSTWebInterface(ec echo.Context) error {
|
||||
if len(params["paste-contents"][0]) == 0 {
|
||||
c.Logger.Debug().Msg("Empty paste submitted, ignoring")
|
||||
|
||||
errtpl := templater.GetErrorTemplate(ec, "Empty pastes aren't allowed.")
|
||||
errtpl := templater.GetErrorTemplate(ectx, "Empty pastes aren't allowed.")
|
||||
|
||||
// nolint:wrapcheck
|
||||
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||
return ectx.HTML(http.StatusBadRequest, errtpl)
|
||||
}
|
||||
|
||||
if !strings.ContainsAny(params["paste-keep-for"][0], "Mmhd") && params["paste-keep-for"][0] != KeepPastesForever {
|
||||
c.Logger.Debug().Str("field value", params["paste-keep-for"][0]).Msg("'Keep paste for' field have invalid value")
|
||||
|
||||
errtpl := templater.GetErrorTemplate(ec, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).")
|
||||
errtpl := templater.GetErrorTemplate(ectx, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).")
|
||||
|
||||
// nolint:wrapcheck
|
||||
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||
return ectx.HTML(http.StatusBadRequest, errtpl)
|
||||
}
|
||||
|
||||
// Verify captcha.
|
||||
if !captcha.Verify(params["paste-captcha-id"][0], params["paste-captcha-solution"][0]) {
|
||||
c.Logger.Debug().Str("captcha ID", params["paste-captcha-id"][0]).Str("captcha solution", params["paste-captcha-solution"][0]).Msg("Invalid captcha solution")
|
||||
|
||||
errtpl := templater.GetErrorTemplate(ec, "Invalid captcha solution.")
|
||||
errtpl := templater.GetErrorTemplate(ectx, "Invalid captcha solution.")
|
||||
|
||||
// nolint:wrapcheck
|
||||
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||
return ectx.HTML(http.StatusBadRequest, errtpl)
|
||||
}
|
||||
|
||||
// nolint:exhaustivestruct
|
||||
@@ -101,10 +101,10 @@ func pastePOSTWebInterface(ec echo.Context) error {
|
||||
} else {
|
||||
c.Logger.Debug().Err(err).Msg("Failed to parse 'Keep for' integer")
|
||||
|
||||
errtpl := templater.GetErrorTemplate(ec, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).")
|
||||
errtpl := templater.GetErrorTemplate(ectx, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).")
|
||||
|
||||
// nolint:wrapcheck
|
||||
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||
return ectx.HTML(http.StatusBadRequest, errtpl)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,25 +138,25 @@ func pastePOSTWebInterface(ec echo.Context) error {
|
||||
_ = paste.CreatePassword(pastePassword[0])
|
||||
}
|
||||
|
||||
id, err2 := c.Database.SavePaste(paste)
|
||||
pasteID, err2 := c.Database.SavePaste(paste)
|
||||
if err2 != nil {
|
||||
c.Logger.Error().Err(err2).Msg("Failed to save paste")
|
||||
|
||||
errtpl := templater.GetErrorTemplate(ec, "Failed to save paste. Please, try again later.")
|
||||
errtpl := templater.GetErrorTemplate(ectx, "Failed to save paste. Please, try again later.")
|
||||
|
||||
// nolint:wrapcheck
|
||||
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||
return ectx.HTML(http.StatusBadRequest, errtpl)
|
||||
}
|
||||
|
||||
newPasteIDAsString := strconv.FormatInt(id, 10)
|
||||
newPasteIDAsString := strconv.FormatInt(pasteID, 10)
|
||||
c.Logger.Debug().Msg("Paste saved, URL: /paste/" + newPasteIDAsString)
|
||||
|
||||
// Private pastes have it's timestamp in URL.
|
||||
if paste.Private {
|
||||
// nolint:wrapcheck
|
||||
return ec.Redirect(http.StatusFound, "/paste/"+newPasteIDAsString+"/"+strconv.FormatInt(paste.CreatedAt.Unix(), 10))
|
||||
return ectx.Redirect(http.StatusFound, "/paste/"+newPasteIDAsString+"/"+strconv.FormatInt(paste.CreatedAt.Unix(), 10))
|
||||
}
|
||||
|
||||
// nolint:wrapcheck
|
||||
return ec.Redirect(http.StatusFound, "/paste/"+newPasteIDAsString)
|
||||
return ectx.Redirect(http.StatusFound, "/paste/"+newPasteIDAsString)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user