Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
raise error on blocked request (Issue #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
g0rbe committed Jan 17, 2023
1 parent 83a22e7 commit a828888
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions server/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
func InsertPut(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand Down
2 changes: 2 additions & 0 deletions server/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func LookupGet(c *gin.Context) {

// Block blacklisted IPs
if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
if c.GetHeader("Accept") == "text/plain" {
c.String(http.StatusForbidden, fault.ErrBlocked.Err)
} else {
Expand Down Expand Up @@ -49,6 +50,7 @@ func LookupGet(c *gin.Context) {
}

if len(subs) == 0 {
c.Error(fault.ErrNotFound)
if c.GetHeader("Accept") == "text/plain" {
c.String(http.StatusNotFound, fault.ErrNotFound.Err)
} else {
Expand Down
4 changes: 4 additions & 0 deletions server/other.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
func OtherGet(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand Down Expand Up @@ -88,6 +89,7 @@ func OtherGet(c *gin.Context) {
func OtherKeyPatch(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand Down Expand Up @@ -167,6 +169,7 @@ func OtherKeyPatch(c *gin.Context) {
func OtherNamePatch(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand Down Expand Up @@ -274,6 +277,7 @@ func OtherNamePatch(c *gin.Context) {
func OtherAdminPatch(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand Down
1 change: 1 addition & 0 deletions server/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func StatGet(c *gin.Context) {
}

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand Down
6 changes: 6 additions & 0 deletions server/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var openApiYaml []byte
func StaticOpenApiYamlGet(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand All @@ -28,6 +29,7 @@ var indexHtml []byte
func StaticIndexHtmlGet(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand All @@ -41,6 +43,7 @@ var faviconIco []byte
func StaticFaviconIcoGet(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand All @@ -54,6 +57,7 @@ var indexCss []byte
func StaticIndexCssGet(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand All @@ -67,6 +71,7 @@ var indexJs []byte
func StaticIndexJsGet(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand All @@ -80,6 +85,7 @@ var logoWhiteSvg []byte
func StaticLogoWhiteSvgGet(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand Down
8 changes: 6 additions & 2 deletions server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
func UserGet(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand All @@ -42,7 +43,6 @@ func UserGet(c *gin.Context) {
}

c.Error(err)

c.JSON(code, gin.H{"error": err.Error()})

return
Expand All @@ -56,6 +56,7 @@ func UserGet(c *gin.Context) {
func UserPut(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand Down Expand Up @@ -84,7 +85,6 @@ func UserPut(c *gin.Context) {
}

c.Error(err)

c.JSON(code, gin.H{"error": err.Error()})

return
Expand Down Expand Up @@ -150,6 +150,7 @@ func UserPut(c *gin.Context) {
func UserDelete(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand Down Expand Up @@ -210,6 +211,7 @@ func UserDelete(c *gin.Context) {
func UserKeyPatch(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand Down Expand Up @@ -257,6 +259,7 @@ func UserKeyPatch(c *gin.Context) {
func UserNamePatch(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand Down Expand Up @@ -326,6 +329,7 @@ func UserNamePatch(c *gin.Context) {
func UsersGet(c *gin.Context) {

if blacklist.IsBlocked(c.ClientIP()) {
c.Error(fault.ErrBlocked)
c.JSON(http.StatusForbidden, fault.ErrBlocked)
return
}
Expand Down

0 comments on commit a828888

Please sign in to comment.