Skip to content

Commit

Permalink
Add config option for KMD
Browse files Browse the repository at this point in the history
  • Loading branch information
nullun committed Jul 31, 2024
1 parent 7f7301c commit d26fc33
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
6 changes: 4 additions & 2 deletions daemon/kmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ func SwaggerHandler(w http.ResponseWriter, r *http.Request) {

// Handler returns the root mux router for the kmd API. It sets up handlers on
// subrouters specific to each API version.
func Handler(sm *session.Manager, log logging.Logger, allowedOrigins []string, apiToken string, reqCB func()) *mux.Router {
func Handler(sm *session.Manager, log logging.Logger, allowedOrigins []string, apiToken string, pnaHeader bool, reqCB func()) *mux.Router {
rootRouter := mux.NewRouter()

// Send the appropriate CORS headers
rootRouter.Use(AllowPNA())
if pnaHeader {
rootRouter.Use(AllowPNA())
}
rootRouter.Use(corsMiddleware(allowedOrigins))

// Handle OPTIONS requests
Expand Down
11 changes: 6 additions & 5 deletions daemon/kmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ const (

// KMDConfig contains global configuration information for kmd
type KMDConfig struct {
DataDir string `json:"-"`
DriverConfig DriverConfig `json:"drivers"`
SessionLifetimeSecs uint64 `json:"session_lifetime_secs"`
Address string `json:"address"`
AllowedOrigins []string `json:"allowed_origins"`
DataDir string `json:"-"`
DriverConfig DriverConfig `json:"drivers"`
SessionLifetimeSecs uint64 `json:"session_lifetime_secs"`
Address string `json:"address"`
AllowedOrigins []string `json:"allowed_origins"`
EnablePrivateNetworkAccessHeader bool `json:"enable_private_network_access_header"`
}

// DriverConfig contains config info specific to each wallet driver
Expand Down
15 changes: 8 additions & 7 deletions daemon/kmd/kmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ func Start(startConfig StartConfig) (died chan error, sock string, err error) {

// Configure the wallet API server
serverCfg := server.WalletServerConfig{
APIToken: apiToken,
DataDir: startConfig.DataDir,
Address: kmdCfg.Address,
AllowedOrigins: kmdCfg.AllowedOrigins,
SessionManager: session.MakeManager(kmdCfg),
Log: startConfig.Log,
Timeout: startConfig.Timeout,
APIToken: apiToken,
DataDir: startConfig.DataDir,
Address: kmdCfg.Address,
AllowedOrigins: kmdCfg.AllowedOrigins,
EnablePrivateNetworkAccessHeader: kmdCfg.EnablePrivateNetworkAccessHeader,
SessionManager: session.MakeManager(kmdCfg),
Log: startConfig.Log,
Timeout: startConfig.Timeout,
}

// Instantiate the wallet API server
Expand Down
17 changes: 9 additions & 8 deletions daemon/kmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ const (

// WalletServerConfig is the configuration passed to MakeWalletServer
type WalletServerConfig struct {
APIToken string
DataDir string
Address string
AllowedOrigins []string
SessionManager *session.Manager
Log logging.Logger
Timeout *time.Duration
APIToken string
DataDir string
Address string
AllowedOrigins []string
EnablePrivateNetworkAccessHeader bool
SessionManager *session.Manager
Log logging.Logger
Timeout *time.Duration
}

// WalletServer deals with serving API requests
Expand Down Expand Up @@ -211,7 +212,7 @@ func (ws *WalletServer) start(kill chan os.Signal) (died chan error, sock string
// Initialize HTTP server
watchdogCB := ws.makeWatchdogCallback(kill)
srv := http.Server{
Handler: api.Handler(ws.SessionManager, ws.Log, ws.AllowedOrigins, ws.APIToken, watchdogCB),
Handler: api.Handler(ws.SessionManager, ws.Log, ws.AllowedOrigins, ws.APIToken, ws.EnablePrivateNetworkAccessHeader, watchdogCB),
}

// Read the kill channel and shut down the server gracefully
Expand Down

0 comments on commit d26fc33

Please sign in to comment.