From e30242b0b406cb7d2eaf0f6fee15890aac784dfc Mon Sep 17 00:00:00 2001 From: Evan Richard Date: Tue, 2 Jul 2019 11:28:18 -0400 Subject: [PATCH 1/4] Add kmd_config.json.example to the installer dir, which is just the default kmd config. --- installer/kmd_config.json.example | 1 + 1 file changed, 1 insertion(+) create mode 100644 installer/kmd_config.json.example diff --git a/installer/kmd_config.json.example b/installer/kmd_config.json.example new file mode 100644 index 0000000000..bb86fd1e7b --- /dev/null +++ b/installer/kmd_config.json.example @@ -0,0 +1 @@ +{"drivers":{"sqlite":{"wallets_dir":"","allow_unsafe_scrypt":false,"scrypt":{"scrypt_n":65536,"scrypt_r":1,"scrypt_p":32}}},"session_lifetime_secs":60,"address":"","allowed_origins":null} \ No newline at end of file From 70bcb110506f12fbbfc97db817dc0cfa04b33211 Mon Sep 17 00:00:00 2001 From: Evan Richard Date: Tue, 2 Jul 2019 13:58:15 -0400 Subject: [PATCH 2/4] Reformat example kmd_config.json --- installer/kmd_config.json.example | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/installer/kmd_config.json.example b/installer/kmd_config.json.example index bb86fd1e7b..3a84023b2b 100644 --- a/installer/kmd_config.json.example +++ b/installer/kmd_config.json.example @@ -1 +1,18 @@ -{"drivers":{"sqlite":{"wallets_dir":"","allow_unsafe_scrypt":false,"scrypt":{"scrypt_n":65536,"scrypt_r":1,"scrypt_p":32}}},"session_lifetime_secs":60,"address":"","allowed_origins":null} \ No newline at end of file +{"drivers": + { + "sqlite": + { + "wallets_dir":"", + "allow_unsafe_scrypt":false, + "scrypt": + { + "scrypt_n":65536, + "scrypt_r":1, + "scrypt_p":32 + } + } + }, + "session_lifetime_secs":60, + "address":"", + "allowed_origins":null +} \ No newline at end of file From c76874017e18b00f2f42e089511c71b3d75e19c4 Mon Sep 17 00:00:00 2001 From: Evan Richard Date: Wed, 3 Jul 2019 10:51:50 -0400 Subject: [PATCH 3/4] Address review comments. --- daemon/kmd/config/config.go | 10 +++++++++- installer/kmd_config.json.example | 18 ------------------ 2 files changed, 9 insertions(+), 19 deletions(-) delete mode 100644 installer/kmd_config.json.example diff --git a/daemon/kmd/config/config.go b/daemon/kmd/config/config.go index 7e91549400..8246d50352 100644 --- a/daemon/kmd/config/config.go +++ b/daemon/kmd/config/config.go @@ -24,6 +24,7 @@ import ( const ( kmdConfigFilename = "kmd_config.json" + kmdConfigExampleFilename = kmdConfigFilename + ".example" defaultSessionLifetimeSecs = 60 defaultScryptN = 65536 defaultScryptR = 1 @@ -95,8 +96,15 @@ func LoadKMDConfig(dataDir string) (cfg KMDConfig, err error) { cfg = defaultConfig(dataDir) configFilename := filepath.Join(dataDir, kmdConfigFilename) dat, err := ioutil.ReadFile(configFilename) - // Return the default configuration if the file doesn't exist + // If there is no config file, then return the default configuration, and dump the default config to disk if err != nil { + exampleFilename := filepath.Join(dataDir, kmdConfigExampleFilename) + cfgBytes, jsonErr := json.Marshal(cfg) + if jsonErr == nil { + // writefile may return an unhandled error because + // there is nothing to do if an error occurs + ioutil.WriteFile(exampleFilename, cfgBytes, 0640) + } return cfg, nil } // Fill in the non-default values diff --git a/installer/kmd_config.json.example b/installer/kmd_config.json.example deleted file mode 100644 index 3a84023b2b..0000000000 --- a/installer/kmd_config.json.example +++ /dev/null @@ -1,18 +0,0 @@ -{"drivers": - { - "sqlite": - { - "wallets_dir":"", - "allow_unsafe_scrypt":false, - "scrypt": - { - "scrypt_n":65536, - "scrypt_r":1, - "scrypt_p":32 - } - } - }, - "session_lifetime_secs":60, - "address":"", - "allowed_origins":null -} \ No newline at end of file From d00e64399f6110835db49e723a0c6b3968a5f400 Mon Sep 17 00:00:00 2001 From: Evan Richard Date: Wed, 3 Jul 2019 11:22:09 -0400 Subject: [PATCH 4/4] use codecs.SaveObjectToFile --- daemon/kmd/config/config.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/daemon/kmd/config/config.go b/daemon/kmd/config/config.go index 8246d50352..5e2318fd05 100644 --- a/daemon/kmd/config/config.go +++ b/daemon/kmd/config/config.go @@ -20,6 +20,8 @@ import ( "encoding/json" "io/ioutil" "path/filepath" + + "github.com/algorand/go-algorand/util/codecs" ) const ( @@ -99,12 +101,9 @@ func LoadKMDConfig(dataDir string) (cfg KMDConfig, err error) { // If there is no config file, then return the default configuration, and dump the default config to disk if err != nil { exampleFilename := filepath.Join(dataDir, kmdConfigExampleFilename) - cfgBytes, jsonErr := json.Marshal(cfg) - if jsonErr == nil { - // writefile may return an unhandled error because - // there is nothing to do if an error occurs - ioutil.WriteFile(exampleFilename, cfgBytes, 0640) - } + // SaveObjectToFile may return an unhandled error because + // there is nothing to do if an error occurs + codecs.SaveObjectToFile(exampleFilename, cfg, true) return cfg, nil } // Fill in the non-default values