From d26fc33c1c967832557e63a6b03cda8715255def Mon Sep 17 00:00:00 2001 From: nullun Date: Tue, 30 Jul 2024 16:48:40 +0100 Subject: [PATCH] Add config option for KMD --- daemon/kmd/api/api.go | 6 ++++-- daemon/kmd/config/config.go | 11 ++++++----- daemon/kmd/kmd.go | 15 ++++++++------- daemon/kmd/server/server.go | 17 +++++++++-------- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/daemon/kmd/api/api.go b/daemon/kmd/api/api.go index 2a8a0155d2..c33d5aa451 100644 --- a/daemon/kmd/api/api.go +++ b/daemon/kmd/api/api.go @@ -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 diff --git a/daemon/kmd/config/config.go b/daemon/kmd/config/config.go index 5dce6ba660..4eb947634b 100644 --- a/daemon/kmd/config/config.go +++ b/daemon/kmd/config/config.go @@ -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 diff --git a/daemon/kmd/kmd.go b/daemon/kmd/kmd.go index 3d3ce3c92d..9f51eb7053 100644 --- a/daemon/kmd/kmd.go +++ b/daemon/kmd/kmd.go @@ -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 diff --git a/daemon/kmd/server/server.go b/daemon/kmd/server/server.go index 712583d47a..d167e75c98 100644 --- a/daemon/kmd/server/server.go +++ b/daemon/kmd/server/server.go @@ -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 @@ -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