From cf68c04a1cc89156b3f367d707e4c80ecd11a234 Mon Sep 17 00:00:00 2001 From: Michael Bishop Date: Fri, 19 Oct 2018 00:51:39 -0300 Subject: [PATCH] [DEVOPS-1099] make the wallet documentation optional, and default it to off --- lib/src/Pos/Client/CLI/Options.hs | 4 ++-- wallet-new/src/Cardano/Wallet/Action.hs | 9 ++++----- wallet-new/src/Cardano/Wallet/Server/CLI.hs | 6 +++--- .../src/Cardano/Wallet/Server/LegacyPlugins.hs | 6 +++--- wallet-new/src/Cardano/Wallet/Server/Plugins.hs | 12 +++++++----- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/src/Pos/Client/CLI/Options.hs b/lib/src/Pos/Client/CLI/Options.hs index 0fbe45b32e3..e39d2d8a3d5 100644 --- a/lib/src/Pos/Client/CLI/Options.hs +++ b/lib/src/Pos/Client/CLI/Options.hs @@ -172,9 +172,9 @@ walletAddressOption na = where helpMsg = "IP and port for backend wallet API." -docAddressOption :: Maybe NetworkAddress -> Opt.Parser NetworkAddress +docAddressOption :: Maybe NetworkAddress -> Opt.Parser (Maybe NetworkAddress) docAddressOption na = - Opt.option (fromParsec addrParser) $ + Opt.optional $ Opt.option (fromParsec addrParser) $ Opt.long "wallet-doc-address" <> Opt.metavar "IP:PORT" <> Opt.help helpMsg diff --git a/wallet-new/src/Cardano/Wallet/Action.hs b/wallet-new/src/Cardano/Wallet/Action.hs index 17236532daf..177dd902998 100644 --- a/wallet-new/src/Cardano/Wallet/Action.hs +++ b/wallet-new/src/Cardano/Wallet/Action.hs @@ -91,17 +91,16 @@ actionWithWallet params genesisConfig walletConfig txpConfig ntpConfig nodeParam , unsupportedMimeTypeMiddleware ]) - -- The corresponding wallet documention, served as a different - -- server which doesn't require client x509 certificates to - -- connect, but still serves the doc through TLS - , ("doc worker", Plugins.docServer params) - -- Periodically compact & snapshot the acid-state database. , ("acid state cleanup", Plugins.acidStateSnapshots (view Kernel.Internal.wallets (snd w)) params dbMode) -- A @Plugin@ to watch and store incoming update proposals , ("update watcher", Plugins.updateWatcher) ] + -- The corresponding wallet documention, served as a different + -- server which doesn't require client x509 certificates to + -- connect, but still serves the doc through TLS + , maybe [] (pure . ("doc server",)) (Plugins.docServer params) -- The monitoring API for the Core node. , Plugins.monitoringServer params ] diff --git a/wallet-new/src/Cardano/Wallet/Server/CLI.hs b/wallet-new/src/Cardano/Wallet/Server/CLI.hs index ef5f8bbad03..d4f2529e064 100644 --- a/wallet-new/src/Cardano/Wallet/Server/CLI.hs +++ b/wallet-new/src/Cardano/Wallet/Server/CLI.hs @@ -57,7 +57,7 @@ data WalletBackendParams = WalletBackendParams -- ^ The TLS parameters. , walletAddress :: !NetworkAddress -- ^ The wallet address. - , walletDocAddress :: !NetworkAddress + , walletDocAddress :: !(Maybe NetworkAddress) -- ^ The wallet documentation address. , walletRunMode :: !RunMode -- ^ The mode this node is running in. @@ -157,8 +157,8 @@ walletBackendParamsParser = WalletBackendParams <$> enableMonitoringApiParser addressParser :: Parser NetworkAddress addressParser = CLI.walletAddressOption $ Just (localhost, 8090) - docAddressParser :: Parser NetworkAddress - docAddressParser = CLI.docAddressOption $ Just (localhost, 8091) + docAddressParser :: Parser (Maybe NetworkAddress) + docAddressParser = CLI.docAddressOption Nothing runModeParser :: Parser RunMode runModeParser = (\debugMode -> if debugMode then DebugMode else ProductionMode) <$> diff --git a/wallet-new/src/Cardano/Wallet/Server/LegacyPlugins.hs b/wallet-new/src/Cardano/Wallet/Server/LegacyPlugins.hs index 3ee0367a038..4ab76e1ad66 100644 --- a/wallet-new/src/Cardano/Wallet/Server/LegacyPlugins.hs +++ b/wallet-new/src/Cardano/Wallet/Server/LegacyPlugins.hs @@ -91,11 +91,11 @@ walletDocumentation :: (HasConfigurations, HasCompileInfo) => WalletBackendParams -> Plugin WalletWebMode -walletDocumentation WalletBackendParams {..} = pure ("wallet doc worker", const worker) +walletDocumentation WalletBackendParams {..} = maybe [] (\addr -> [ ("wallet doc worker", const $ worker addr) ]) walletDocAddress where - worker = walletDocumentationImpl + worker addr = walletDocumentationImpl application - walletDocAddress + addr tls (Just defaultSettings) Nothing diff --git a/wallet-new/src/Cardano/Wallet/Server/Plugins.hs b/wallet-new/src/Cardano/Wallet/Server/Plugins.hs index e9d8a128e3f..fbbc2c77459 100644 --- a/wallet-new/src/Cardano/Wallet/Server/Plugins.hs +++ b/wallet-new/src/Cardano/Wallet/Server/Plugins.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE NamedFieldPuns #-} + {- | A collection of plugins used by this edge node. A @Plugin@ is essentially a set of actions which will be run in a particular monad, at some point in time. @@ -124,17 +126,17 @@ apiServer (NewWalletBackendParams WalletBackendParams{..}) (passiveLayer, passiv docServer :: (HasConfigurations, HasCompileInfo) => NewWalletBackendParams - -> Plugin Kernel.WalletMode -docServer (NewWalletBackendParams WalletBackendParams{..}) = const $ - serveDocImpl + -> Maybe (Plugin Kernel.WalletMode) +docServer (NewWalletBackendParams WalletBackendParams{walletDocAddress = Nothing}) = Nothing +docServer (NewWalletBackendParams WalletBackendParams{walletDocAddress = Just (ip, port), walletRunMode, walletTLSParams}) = Just (const $ makeWalletServer) + where + makeWalletServer = serveDocImpl application (BS8.unpack ip) port (if isDebugMode walletRunMode then Nothing else walletTLSParams) (Just defaultSettings) Nothing - where - (ip, port) = walletDocAddress application :: Kernel.WalletMode Application application =