Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding default restricteds #8

Merged
merged 1 commit into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion log_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func request(context *gin.Context, restricteds []string) interface{} {
r["form"] = context.Request.Form
r["path"] = context.Request.URL.Path
r["method"] = context.Request.Method
r["headers"] = context.Request.Header
r["headers"] = restricted(context.Request.Header, restricteds)
r["url"] = context.Request.URL.String()
r["post_form"] = context.Request.PostForm
r["remote_addr"] = context.Request.RemoteAddr
Expand Down
8 changes: 6 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func WithHealthz(h gin.HandlerFunc) APIOption {
}
}

var defaultRestricteds = []string{
TransactionTokenHeader,
}

// New creates a new API server
func New(opts ...APIOption) *API {
server := &API{}
Expand All @@ -79,9 +83,9 @@ func New(opts ...APIOption) *API {
server.Engine.Use(gin.Recovery())
server.Engine.Use(SetMaxBodyBytesMiddleware(server.settings.API.MaxBodySize))

var restricteds []string
restricteds := defaultRestricteds
if server.settings.Log != nil {
restricteds = server.settings.Log.Restricteds
restricteds = append(restricteds, server.settings.Log.Restricteds...)
}

server.Engine.Use(LogMiddleware(restricteds))
Expand Down
7 changes: 6 additions & 1 deletion transactional_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"github.com/gin-gonic/gin"
)

const (
//TransactionTokenHeader ...
TransactionTokenHeader = "X-Transaction-Token"
)

type TransactionalToken interface {
Validate() gin.HandlerFunc
}
Expand Down Expand Up @@ -49,7 +54,7 @@ func (a *InternalTransactionalToken) Validate() gin.HandlerFunc {
return
}

token := c.Request.Header.Get("X-Transaction-Token")
token := c.Request.Header.Get(TransactionTokenHeader)

if len(token) <= 0 {
c.AbortWithStatusJSON(http.StatusForbidden, defaultError)
Expand Down