Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit cc194cd

Browse files
authored
[GH-229] Add Wallet and TLS specific configuration options using CLI. (#232)
1 parent 7d7cafc commit cc194cd

File tree

5 files changed

+258
-78
lines changed

5 files changed

+258
-78
lines changed

src/Cardano/Shell/Configuration/Lib.hs

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,22 @@ import Cardano.Shell.Configuration.Types (BlockchainConfig,
2929
OSConfig, TopologyConfig,
3030
WalletConfig, renderCluster,
3131
renderOS)
32-
import Cardano.Shell.Constants.PartialTypes (PartialBlock (..),
33-
PartialCardanoConfiguration (..),
34-
PartialStaticKeyMaterial (..),
32+
import Cardano.Shell.Constants.PartialTypes (PartialBlock (..), PartialCardanoConfiguration (..),
33+
PartialCertificate (..),
3534
PartialCore (..),
3635
PartialGenesis (..),
37-
PartialNode (..))
36+
PartialNode (..),
37+
PartialStaticKeyMaterial (..),
38+
PartialTLS (..),
39+
PartialThrottle (..),
40+
PartialWallet (..))
3841
import Cardano.Shell.Constants.Types (Block (..),
3942
CardanoConfiguration (..),
40-
Core (..), Genesis (..),
43+
Certificate (..), Core (..),
44+
Genesis (..), Node (..),
4145
StaticKeyMaterial (..),
42-
Node (..))
46+
TLS (..), Throttle (..),
47+
Wallet (..))
4348

4449
-- | Converting a @Last@ to an @Either@
4550
lastToEither :: Text -> Last a -> Either Text a
@@ -70,8 +75,10 @@ finaliseCardanoConfiguration PartialCardanoConfiguration{..} = do
7075
lastToEither "Unspecified ccBlock" pccBlock
7176
ccNode <- join $ finaliseNode <$>
7277
lastToEither "Unspecified ccNode" pccNode
73-
ccTLS <- lastToEither "Unspecified ccTLS" pccTLS
74-
ccWallet <- lastToEither "Unspecified ccWallet" pccWallet
78+
ccTLS <- join $ finaliseTLS <$>
79+
lastToEither "Unspecified ccTLS" pccTLS
80+
ccWallet <- join $ finaliseWallet <$>
81+
lastToEither "Unspecified ccWallet" pccWallet
7582

7683
pure CardanoConfiguration{..}
7784

@@ -141,6 +148,46 @@ finaliseBlock PartialBlock{..} = do
141148

142149
pure Block{..}
143150

151+
-- | Finalize the @PartialCertificate@, convert to @Certificate@.
152+
finaliseCertificate :: PartialCertificate -> Either Text Certificate
153+
finaliseCertificate PartialCertificate{..} = do
154+
155+
certOrganization <- lastToEither "Unspecified certOrganization" pcertOrganization
156+
certCommonName <- lastToEither "Unspecified certCommonName" pcertCommonName
157+
certExpiryDays <- lastToEither "Unspecified certExpiryDays" pcertExpiryDays
158+
certAltDNS <- lastToEither "Unspecified certAltDNS" pcertAltDNS
159+
160+
pure Certificate{..}
161+
162+
-- | Finalize the @PartialTLS@, convert to @TLS@.
163+
finaliseTLS :: PartialTLS -> Either Text TLS
164+
finaliseTLS PartialTLS{..} = do
165+
166+
tlsCA <- join $ finaliseCertificate <$> lastToEither "Unspecified tlsCS" ptlsCA
167+
tlsServer <- join $ finaliseCertificate <$> lastToEither "Unspecified tlsServer" ptlsServer
168+
tlsClients <- join $ finaliseCertificate <$> lastToEither "Unspecified tlsClients" ptlsClients
169+
170+
pure TLS{..}
171+
172+
-- | Finalise the @PartialThrottle@, convert to @Throttle@.
173+
finaliseThrottle :: PartialThrottle -> Either Text Throttle
174+
finaliseThrottle PartialThrottle{..} = do
175+
176+
thEnabled <- lastToEither "Unspecified thEnabled" pthEnabled
177+
thRate <- lastToEither "Unspecified thRate" pthRate
178+
thPeriod <- lastToEither "Unspecified thPeriod" pthPeriod
179+
thBurst <- lastToEither "Unspecified thBurst" pthBurst
180+
181+
pure Throttle {..}
182+
183+
-- | Finalize the @PartialWallet@, convert to @Wallet@.
184+
finaliseWallet :: PartialWallet -> Either Text Wallet
185+
finaliseWallet PartialWallet{..} = do
186+
187+
waThrottle <- join $ finaliseThrottle <$> lastToEither "Unspecified waThrottle" pwaThrottle
188+
189+
pure Wallet{..}
190+
144191

145192
-- | Generate 'TopologyConfig' with given 'Cluster'
146193
mkTopology :: Cluster -> IO TopologyConfig

src/Cardano/Shell/Constants/CLI.hs

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ module Cardano.Shell.Constants.CLI
99
, configNodeCLIParser
1010
-- * Block
1111
, configBlockCLIParser
12+
-- * TLS
13+
, configTLSCLIParser
14+
, configCertificateCLIParser
15+
-- * Wallet
16+
, configWalletCLIParser
17+
, configThrottleCLIParser
1218
) where
1319

1420
import Cardano.Prelude hiding (option)
@@ -94,8 +100,6 @@ configDBVersionCLIParser =
94100
<> help "The version of the DB."
95101
)
96102

97-
98-
99103
--------------------------------------------------------------------------------
100104
-- Node
101105
--------------------------------------------------------------------------------
@@ -194,3 +198,76 @@ configBlockCLIParser =
194198
<> metavar "FIXED-TIME-CQ"
195199
<> help "Chain quality will be also calculated for this amount of seconds."
196200
)
201+
202+
--------------------------------------------------------------------------------
203+
-- Certificates
204+
--------------------------------------------------------------------------------
205+
206+
-- | TLS CLI Parser.
207+
configTLSCLIParser :: Parser PartialTLS
208+
configTLSCLIParser =
209+
PartialTLS
210+
<$> lastOption configCertificateCLIParser
211+
<*> lastOption configCertificateCLIParser
212+
<*> lastOption configCertificateCLIParser
213+
214+
-- | Certificate CLI parser.
215+
configCertificateCLIParser :: Parser PartialCertificate
216+
configCertificateCLIParser =
217+
PartialCertificate
218+
<$> option auto
219+
( long "cert-organization-name"
220+
<> metavar "CERT-ORGANIZATION-NAME"
221+
<> help "Certificate organization."
222+
)
223+
<*> option auto
224+
( long "cert-common-name"
225+
<> metavar "CERT-COMMON-NAME"
226+
<> help "Certificate common name."
227+
)
228+
<*> option auto
229+
( long "cert-expiry-days"
230+
<> metavar "CERT-EXPIRY-DAYS"
231+
<> help "Certificate days of expiration."
232+
)
233+
<*> option auto
234+
( long "cert-alternative-dns"
235+
<> metavar "CERT-ALTERNATIVE-DNS"
236+
<> help "Certificate alternative DNS."
237+
)
238+
239+
--------------------------------------------------------------------------------
240+
-- Wallet
241+
--------------------------------------------------------------------------------
242+
243+
-- | Certificate CLI parser.
244+
configWalletCLIParser :: Parser PartialWallet
245+
configWalletCLIParser =
246+
PartialWallet
247+
<$> lastOption configThrottleCLIParser
248+
249+
-- | Certificate CLI parser.
250+
configThrottleCLIParser :: Parser PartialThrottle
251+
configThrottleCLIParser =
252+
PartialThrottle
253+
<$> option auto
254+
( long "th-enabled"
255+
<> metavar "TH-ENABLED"
256+
<> help "Throttle enabled/disabled."
257+
)
258+
<*> option auto
259+
( long "th-rate"
260+
<> metavar "TH-RATE"
261+
<> help "Throttle rate."
262+
)
263+
<*> option auto
264+
( long "th-period"
265+
<> metavar "TH-PERIOD"
266+
<> help "Throttle period."
267+
)
268+
<*> option auto
269+
( long "th-burst"
270+
<> metavar "TH-BURST"
271+
<> help "Throttle burst."
272+
)
273+

src/Cardano/Shell/Constants/PartialTypes.hs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ module Cardano.Shell.Constants.PartialTypes
99
, PartialStaticKeyMaterial (..)
1010
, PartialNode (..)
1111
, PartialBlock (..)
12+
, PartialTLS (..)
13+
, PartialCertificate (..)
14+
, PartialWallet (..)
15+
, PartialThrottle (..)
1216
-- * re-exports
1317
, RequireNetworkMagic (..)
1418
) where
@@ -33,8 +37,8 @@ data PartialCardanoConfiguration = PartialCardanoConfiguration
3337
, pccDLG :: !(Last DLG)
3438
, pccBlock :: !(Last PartialBlock)
3539
, pccNode :: !(Last PartialNode)
36-
, pccTLS :: !(Last TLS)
37-
, pccWallet :: !(Last Wallet)
40+
, pccTLS :: !(Last PartialTLS)
41+
, pccWallet :: !(Last PartialWallet)
3842
} deriving (Eq, Show, Generic)
3943

4044
-- | Partial @Core@ configuration.
@@ -107,3 +111,51 @@ data PartialBlock = PartialBlock
107111
deriving Semigroup via GenericSemigroup PartialBlock
108112
deriving Monoid via GenericMonoid PartialBlock
109113

114+
-- | Partial @TLS@ configuration.
115+
data PartialTLS = PartialTLS
116+
{ ptlsCA :: !(Last PartialCertificate)
117+
-- ^ Certificate Authoritiy certificate.
118+
, ptlsServer :: !(Last PartialCertificate)
119+
-- ^ Server certificate.
120+
, ptlsClients :: !(Last PartialCertificate)
121+
-- ^ Client certificate.
122+
} deriving (Eq, Show, Generic)
123+
deriving Semigroup via GenericSemigroup PartialTLS
124+
deriving Monoid via GenericMonoid PartialTLS
125+
126+
-- | Partial @Certificate@ configuration.
127+
data PartialCertificate = PartialCertificate
128+
{ pcertOrganization :: !(Last Text)
129+
-- ^ Certificate organization.
130+
, pcertCommonName :: !(Last Text)
131+
-- ^ Certificate common name.
132+
, pcertExpiryDays :: !(Last Int)
133+
-- ^ Certificate days of expiration.
134+
, pcertAltDNS :: !(Last [Text])
135+
-- ^ Certificate alternative DNS.
136+
} deriving (Eq, Show, Generic)
137+
deriving Semigroup via GenericSemigroup PartialCertificate
138+
deriving Monoid via GenericMonoid PartialCertificate
139+
140+
-- | Partial @Wallet@ configuration.
141+
data PartialWallet = PartialWallet
142+
{ pwaThrottle :: !(Last PartialThrottle)
143+
-- ^ Wallet throttle configuration.
144+
} deriving (Eq, Show, Generic)
145+
deriving Semigroup via GenericSemigroup PartialWallet
146+
deriving Monoid via GenericMonoid PartialWallet
147+
148+
-- | Partial @Throttle@ configuration.
149+
data PartialThrottle = PartialThrottle
150+
{ pthEnabled :: !(Last Bool)
151+
-- ^ Is throttle enabled?
152+
, pthRate :: !(Last Int)
153+
-- ^ Throttle rate.
154+
, pthPeriod :: !(Last Text)
155+
-- ^ Throttle period.
156+
, pthBurst :: !(Last Int)
157+
-- ^ Throttle burst.
158+
} deriving (Eq, Show, Generic)
159+
deriving Semigroup via GenericSemigroup PartialThrottle
160+
deriving Monoid via GenericMonoid PartialThrottle
161+

src/Cardano/Shell/Constants/Types.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ data Wallet = Wallet
300300
} deriving (Eq, Show)
301301

302302
-- | Rate-limiting/throttling parameters
303-
data Throttle = SetThrottle
303+
data Throttle = Throttle
304304
{ thEnabled :: !Bool
305305
, thRate :: !Int
306306
, thPeriod :: !Text

0 commit comments

Comments
 (0)