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

feat(BUX-641) Shared Config #496

Merged
merged 7 commits into from
Mar 12, 2024
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
1 change: 1 addition & 0 deletions actions/admin/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewHandler(appConfig *config.AppConfig, services *config.AppServices) route
adminGroup.POST("/xpub", action.xpubsCreate)
adminGroup.POST("/xpubs/search", action.xpubsSearch)
adminGroup.POST("/xpubs/count", action.xpubsCount)
adminGroup.GET("/shared-config", action.sharedConfig)
})

return adminEndpoints
Expand Down
31 changes: 31 additions & 0 deletions actions/admin/shared_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package admin

import (
"net/http"
"sync"

"github.com/bitcoin-sv/spv-wallet/models"
"github.com/gin-gonic/gin"
)

// sharedConfig will return the shared configuration
// Get shared config godoc
// @Summary Get shared config
// @Description Get shared config
// @Tags Admin
// @Produce json
// @Success 200
// @Router /v1/admin/shared-config [get]
// @Security x-auth-xpub
func (a *Action) sharedConfig(c *gin.Context) {
makeConfig := sync.OnceValue(func() models.SharedConfig {
return models.SharedConfig{
PaymilDomains: a.AppConfig.Paymail.Domains,
ExperimentalFeatures: map[string]bool{
"pike_enabled": a.AppConfig.ExperimentalFeatures.PikeEnabled,
},
}
})

c.JSON(http.StatusOK, makeConfig())
}
2 changes: 1 addition & 1 deletion actions/base/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (ts *TestSuite) SetupTest() {
// Load the router & register routes
ts.Router = gin.Default()
require.NotNil(ts.T(), ts.Router)
routes := NewHandler(ts.AppConfig, ts.Router)
routes := NewHandler()
routes.RegisterBaseEndpoints(ts.Router.Group(""))
}

Expand Down
12 changes: 1 addition & 11 deletions actions/base/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@ import (
"github.com/bitcoin-sv/spv-wallet/actions"
"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/server/routes"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
)

// Action is an extension of actions.Action for this package
type Action struct {
actions.Action
}

// NewHandler creates the specific package routes
func NewHandler(appConfig *config.AppConfig, engine *gin.Engine) routes.BaseEndpointsFunc {
func NewHandler() routes.BaseEndpointsFunc {
basicEndpoints := routes.BaseEndpointsFunc(func(router *gin.RouterGroup) {
router.GET("/", index)
router.OPTIONS("/", actions.StatusOK)
Expand All @@ -26,9 +20,5 @@ func NewHandler(appConfig *config.AppConfig, engine *gin.Engine) routes.BaseEndp
healthGroup.HEAD("", actions.StatusOK)
})

if appConfig.DebugProfiling {
pprof.Register(engine, "debug/pprof")
}

return basicEndpoints
}
9 changes: 0 additions & 9 deletions actions/base/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ func (ts *TestSuite) TestBaseRegisterRoutes() {
{"GET", "/" + config.HealthRequestPath},
{"OPTIONS", "/" + config.HealthRequestPath},
{"HEAD", "/" + config.HealthRequestPath},
{"GET", "/debug/pprof/"},
{"GET", "/debug/pprof/cmdline"},
{"GET", "/debug/pprof/profile"},
{"POST", "/debug/pprof/symbol"},
{"GET", "/debug/pprof/trace"},
{"GET", "/debug/pprof/goroutine"},
{"GET", "/debug/pprof/heap"},
{"GET", "/debug/pprof/threadcreate"},
{"GET", "/debug/pprof/block"},
}

ts.Router.Routes()
Expand Down
8 changes: 8 additions & 0 deletions models/shared_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package models

// SharedConfig with fields which can ba shared across the application components.
// Please be aware NOT to add ANY SENSITIVE information here.
type SharedConfig struct {
PaymilDomains []string `json:"paymail_domains"`
ExperimentalFeatures map[string]bool `json:"experimental_features"`
}
7 changes: 6 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/bitcoin-sv/spv-wallet/metrics"
"github.com/bitcoin-sv/spv-wallet/server/auth"
router "github.com/bitcoin-sv/spv-wallet/server/routes"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
)
Expand Down Expand Up @@ -115,7 +116,7 @@ func (s *Server) Handlers() *gin.Engine {
// SetupServerRoutes will register endpoints for all models
func SetupServerRoutes(appConfig *config.AppConfig, services *config.AppServices, engine *gin.Engine) {
adminRoutes := admin.NewHandler(appConfig, services)
baseRoutes := base.NewHandler(appConfig, engine)
baseRoutes := base.NewHandler()

accessKeyAPIRoutes := accesskeys.NewHandler(appConfig, services)
destinationBasicRoutes, destinationAPIRoutes := destinations.NewHandler(appConfig, services)
Expand Down Expand Up @@ -186,4 +187,8 @@ func SetupServerRoutes(appConfig *config.AppConfig, services *config.AppServices
if metrics, enabled := metrics.Get(); enabled {
engine.GET("/metrics", gin.WrapH(metrics.HTTPHandler()))
}

if appConfig.DebugProfiling {
pprof.Register(engine, "debug/pprof")
}
}
Loading