diff --git a/actions/access_keys/routes.go b/actions/access_keys/routes.go index 6d70a2cf0..785a534d1 100644 --- a/actions/access_keys/routes.go +++ b/actions/access_keys/routes.go @@ -22,9 +22,10 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi action := &Action{actions.Action{AppConfig: a.AppConfig, Services: a.Services}} // V1 Requests - router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/access-key", router.Request(require.Wrap(action.get))) - router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/access-key/search", router.Request(require.Wrap(action.search))) - router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/access-key/search", router.Request(require.Wrap(action.search))) - router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/access-key", router.Request(require.Wrap(action.create))) - router.HTTPRouter.DELETE("/"+config.CurrentMajorVersion+"/access-key", router.Request(require.Wrap(action.revoke))) + router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/access-key", action.Request(router, require.Wrap(action.get))) + router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/access-key/search", action.Request(router, require.Wrap(action.search))) + router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/access-key/search", action.Request(router, require.Wrap(action.search))) + router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/access-key", action.Request(router, require.Wrap(action.create))) + router.HTTPRouter.DELETE("/"+config.CurrentMajorVersion+"/access-key", action.Request(router, require.Wrap(action.revoke))) + } diff --git a/actions/base/routes.go b/actions/base/routes.go index 4395589cc..742093a16 100644 --- a/actions/base/routes.go +++ b/actions/base/routes.go @@ -21,7 +21,7 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi action := &Action{actions.Action{AppConfig: appConfig, Services: services}} // Set the main index page (navigating to slash) - router.HTTPRouter.GET("/", router.Request(index)) + router.HTTPRouter.GET("/", action.Request(router, router.Request(index))) router.HTTPRouter.OPTIONS("/", router.SetCrossOriginHeaders) router.HTTPRouter.HEAD("/", actions.Head) diff --git a/actions/destinations/routes.go b/actions/destinations/routes.go index 474b139e1..8b04cc9c8 100644 --- a/actions/destinations/routes.go +++ b/actions/destinations/routes.go @@ -19,16 +19,16 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi require.Use(a.RequireAuthentication) // Use the authentication middleware wrapper - this will only check for a valid xPub - a, requireBasic := actions.NewStack(appConfig, services) - requireBasic.Use(a.RequireBasicAuthentication) + aBasic, requireBasic := actions.NewStack(appConfig, services) + requireBasic.Use(aBasic.RequireBasicAuthentication) // Load the actions and set the services action := &Action{actions.Action{AppConfig: a.AppConfig, Services: a.Services}} // V1 Requests - router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/destination", router.Request(requireBasic.Wrap(action.get))) - router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/destination/search", router.Request(requireBasic.Wrap(action.search))) - router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/destination/search", router.Request(requireBasic.Wrap(action.search))) - router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/destination", router.Request(require.Wrap(action.create))) - router.HTTPRouter.PATCH("/"+config.CurrentMajorVersion+"/destination", router.Request(require.Wrap(action.update))) + router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/destination", action.Request(router, requireBasic.Wrap(action.get))) + router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/destination/search", action.Request(router, requireBasic.Wrap(action.search))) + router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/destination/search", action.Request(router, requireBasic.Wrap(action.search))) + router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/destination", action.Request(router, require.Wrap(action.create))) + router.HTTPRouter.PATCH("/"+config.CurrentMajorVersion+"/destination", action.Request(router, require.Wrap(action.update))) } diff --git a/actions/middleware.go b/actions/middleware.go index 13ee9d640..fb859329e 100644 --- a/actions/middleware.go +++ b/actions/middleware.go @@ -70,6 +70,15 @@ func (a *Action) RequireAdminAuthentication(fn httprouter.Handle) httprouter.Han } } +// Request will process the request in the router +func (a *Action) Request(router *apirouter.Router, h httprouter.Handle) httprouter.Handle { + if a.AppConfig.RequestLogging { + return router.Request(h) + } else { + return router.RequestNoLogging(h) + } +} + // CheckAuthentication will check the authentication func CheckAuthentication(appConfig *config.AppConfig, bux bux.ClientInterface, req *http.Request, adminRequired bool, requireSigning bool) (*http.Request, dictionary.ErrorMessage) { diff --git a/actions/paymail/routes.go b/actions/paymail/routes.go index 03388366d..9dc7a0901 100644 --- a/actions/paymail/routes.go +++ b/actions/paymail/routes.go @@ -26,8 +26,8 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi action := &Action{actions.Action{AppConfig: a.AppConfig, Services: a.Services}} // V1 Requests - router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/paymail", router.Request(requireAdmin.Wrap(action.create))) - router.HTTPRouter.DELETE("/"+config.CurrentMajorVersion+"/paymail", router.Request(requireAdmin.Wrap(action.delete))) + router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/paymail", action.Request(router, requireAdmin.Wrap(action.create))) + router.HTTPRouter.DELETE("/"+config.CurrentMajorVersion+"/paymail", action.Request(router, requireAdmin.Wrap(action.delete))) if appConfig.Debug { logger.Data(2, logger.DEBUG, "registered paymail routes and model") diff --git a/actions/transactions/routes.go b/actions/transactions/routes.go index 4d3f99eca..270f4d751 100644 --- a/actions/transactions/routes.go +++ b/actions/transactions/routes.go @@ -19,17 +19,17 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi require.Use(a.RequireAuthentication) // Use the authentication middleware wrapper - this will only check for a valid xPub - a, requireBasic := actions.NewStack(appConfig, services) - requireBasic.Use(a.RequireBasicAuthentication) + aBasic, requireBasic := actions.NewStack(appConfig, services) + requireBasic.Use(aBasic.RequireBasicAuthentication) // Load the actions and set the services action := &Action{actions.Action{AppConfig: a.AppConfig, Services: a.Services}} // V1 Requests - router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/transaction", router.Request(requireBasic.Wrap(action.get))) - router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/transaction/search", router.Request(requireBasic.Wrap(action.search))) - router.HTTPRouter.PATCH("/"+config.CurrentMajorVersion+"/transaction", router.Request(requireBasic.Wrap(action.update))) - router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/transaction", router.Request(require.Wrap(action.newTransaction))) - router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/transaction/record", router.Request(require.Wrap(action.record))) - router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/transaction/search", router.Request(requireBasic.Wrap(action.search))) + router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/transaction", action.Request(router, requireBasic.Wrap(action.get))) + router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/transaction/search", action.Request(router, requireBasic.Wrap(action.search))) + router.HTTPRouter.PATCH("/"+config.CurrentMajorVersion+"/transaction", action.Request(router, requireBasic.Wrap(action.update))) + router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/transaction", action.Request(router, require.Wrap(action.newTransaction))) + router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/transaction/record", action.Request(router, require.Wrap(action.record))) + router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/transaction/search", action.Request(router, requireBasic.Wrap(action.search))) } diff --git a/actions/utxos/routes.go b/actions/utxos/routes.go index 1bf184852..fba319f1f 100644 --- a/actions/utxos/routes.go +++ b/actions/utxos/routes.go @@ -22,5 +22,5 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi action := &Action{actions.Action{AppConfig: a.AppConfig, Services: a.Services}} // V1 Requests - router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/utxo", router.Request(require.Wrap(action.get))) + router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/utxo", action.Request(router, require.Wrap(action.get))) } diff --git a/actions/xpubs/routes.go b/actions/xpubs/routes.go index b6261252e..5b45e28b9 100644 --- a/actions/xpubs/routes.go +++ b/actions/xpubs/routes.go @@ -19,15 +19,14 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi requireAdmin.Use(a.RequireAdminAuthentication) // Use the authentication middleware wrapper - this will only check for a valid xPub - var requireBasic *apirouter.InternalStack - a, requireBasic = actions.NewStack(appConfig, services) - requireBasic.Use(a.RequireBasicAuthentication) + aBasic, requireBasic := actions.NewStack(appConfig, services) + requireBasic.Use(aBasic.RequireBasicAuthentication) // Load the actions and set the services action := &Action{actions.Action{AppConfig: a.AppConfig, Services: a.Services}} // V1 Requests - router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/xpub", router.Request(requireBasic.Wrap(action.get))) - router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/xpub", router.Request(requireAdmin.Wrap(action.create))) - router.HTTPRouter.PATCH("/"+config.CurrentMajorVersion+"/xpub", router.Request(requireAdmin.Wrap(action.update))) + router.HTTPRouter.GET("/"+config.CurrentMajorVersion+"/xpub", action.Request(router, requireBasic.Wrap(action.get))) + router.HTTPRouter.POST("/"+config.CurrentMajorVersion+"/xpub", action.Request(router, requireAdmin.Wrap(action.create))) + router.HTTPRouter.PATCH("/"+config.CurrentMajorVersion+"/xpub", action.Request(router, requireAdmin.Wrap(action.update))) } diff --git a/config/config.go b/config/config.go index d820f935f..ffef38b41 100644 --- a/config/config.go +++ b/config/config.go @@ -58,6 +58,7 @@ type ( NewRelic *NewRelicConfig `json:"new_relic" mapstructure:"new_relic"` Paymail *PaymailConfig `json:"paymail" mapstructure:"paymail"` Redis *RedisConfig `json:"redis" mapstructure:"redis"` + RequestLogging bool `json:"request_logging" mapstructure:"request_logging"` Server *ServerConfig `json:"server" mapstructure:"server"` SQL *datastore.SQLConfig `json:"sql" mapstructure:"sql"` SQLite *datastore.SQLiteConfig `json:"sqlite" mapstructure:"sqlite"` diff --git a/config/envs/development.json b/config/envs/development.json index bfce0bfe7..e0e760856 100644 --- a/config/envs/development.json +++ b/config/envs/development.json @@ -4,6 +4,7 @@ "disable_itc": true, "environment": "development", "gdpr_compliance": false, + "request_logging": true, "authentication": { "admin_key": "xpub661MyMwAqRbcFrBJbKwBGCB7d3fr2SaAuXGM95BA62X41m6eW2ehRQGW4xLi9wkEXUGnQZYxVVj4PxXnyrLk7jdqvBAs1Qq9gf6ykMvjR7J", "require_signing": false, diff --git a/config/envs/docker-compose.json b/config/envs/docker-compose.json index 89d199920..9a8a8784d 100644 --- a/config/envs/docker-compose.json +++ b/config/envs/docker-compose.json @@ -4,6 +4,7 @@ "disable_itc": false, "environment": "development", "gdpr_compliance": false, + "request_logging": true, "authentication": { "admin_key": "1234567", "require_signing": false, diff --git a/config/envs/production.json b/config/envs/production.json index 75c9aa924..28ff01f81 100644 --- a/config/envs/production.json +++ b/config/envs/production.json @@ -4,6 +4,7 @@ "disable_itc": false, "environment": "production", "gdpr_compliance": false, + "request_logging": true, "authentication": { "admin_key": "1234567", "require_signing": true, diff --git a/config/envs/staging.json b/config/envs/staging.json index 34c69dd32..6a5dd6a64 100644 --- a/config/envs/staging.json +++ b/config/envs/staging.json @@ -4,6 +4,7 @@ "disable_itc": false, "environment": "staging", "gdpr_compliance": false, + "request_logging": true, "authentication": { "admin_key": "1234567", "require_signing": false, diff --git a/config/envs/test.json b/config/envs/test.json index ebaed2d26..205dab8aa 100644 --- a/config/envs/test.json +++ b/config/envs/test.json @@ -4,6 +4,7 @@ "disable_itc": false, "environment": "test", "gdpr_compliance": false, + "request_logging": true, "authentication": { "admin_key": "1234567890123456789012345678901234567890", "require_signing": false,