forked from input-output-hk/daedalus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigMutator.hs
47 lines (43 loc) · 1.69 KB
/
ConfigMutator.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Pos.Launcher.Configuration (Configuration, ccUpdate_L)
import System.Environment (getArgs)
import qualified Data.Yaml as Y
import qualified Data.Map as Map
import qualified Data.HashMap.Strict as HM
import Control.Lens
import Pos.Chain.Update (ccApplicationVersion_L)
import Pos.Util.Config (parseYamlConfig)
import qualified Data.Text as T
import qualified Data.ByteString as BS
import System.Exit (exitWith, ExitCode(ExitFailure))
import qualified Data.Aeson
import Cardano.X509.Configuration
import Data.Monoid ((<>))
parseToValue :: String -> IO (Either Y.ParseException Data.Aeson.Value)
parseToValue = Y.decodeFileEither
main :: IO ()
main = do
args <- getArgs
case args of
[ filepath, key, appVer ] -> do
tlscfg <- decodeConfigFile (ConfigurationKey key) filepath
cfg <- parseYamlConfig filepath (T.pack key)
let
newcfg :: Configuration
newcfg = cfg & ccUpdate_L . ccApplicationVersion_L .~ (read appVer)
newmap = Map.singleton key newcfg
partialcfg = Data.Aeson.toJSON newcfg
yaml = Y.encode newmap
-- this mess exists because `Configuration` lacks the `tls` field
let
tlsvalue = Data.Aeson.toJSON tlscfg
deobj (Data.Aeson.Object hm) = hm
wrappedtls :: HM.HashMap T.Text Data.Aeson.Value
wrappedtls = HM.singleton "tls" tlsvalue
both = Data.Aeson.Object (wrappedtls <> (deobj partialcfg))
finalCfg = Data.Aeson.Object (HM.singleton (T.pack key) both)
BS.putStr $ Y.encode finalCfg
_ -> do
putStrLn "usage: config-mutator lib/configuration.yaml mainnet_dryrun_wallet_win64 42"
exitWith $ ExitFailure 1