@@ -113,7 +113,9 @@ func runNode(ctx context.Context, c *cli.Command) error {
113113
114114 viper .SetDefault ("backup_enabled" , true )
115115 config .InitViperConfig (configPath )
116- environment := viper .GetString ("environment" )
116+
117+ appConfig := config .LoadConfig ()
118+ environment := appConfig .Environment
117119 logger .Init (environment , debug )
118120
119121 // Handle password file if provided
@@ -127,15 +129,15 @@ func runNode(ctx context.Context, c *cli.Command) error {
127129 promptForSensitiveCredentials ()
128130 } else {
129131 // Validate the config values
130- checkRequiredConfigValues ()
132+ checkRequiredConfigValues (appConfig )
131133 }
132134
133135 consulClient := infra .GetConsulClient (environment )
134136 keyinfoStore := keyinfo .NewStore (consulClient .KV ())
135137 peers := LoadPeersFromConsul (consulClient )
136138 nodeID := GetIDFromName (nodeName , peers )
137139
138- badgerKV := NewBadgerKV (nodeName , nodeID )
140+ badgerKV := NewBadgerKV (nodeName , nodeID , appConfig )
139141 defer badgerKV .Close ()
140142
141143 // Start background backup job
@@ -151,7 +153,7 @@ func runNode(ctx context.Context, c *cli.Command) error {
151153 logger .Fatal ("Failed to create identity store" , err )
152154 }
153155
154- natsConn , err := GetNATSConnection (environment )
156+ natsConn , err := GetNATSConnection (environment , appConfig )
155157 if err != nil {
156158 logger .Fatal ("Failed to connect to NATS" , err )
157159 }
@@ -388,9 +390,9 @@ func maskString(s string) string {
388390}
389391
390392// Check required configuration values are present
391- func checkRequiredConfigValues () {
393+ func checkRequiredConfigValues (appConfig * config. AppConfig ) {
392394 // Show warning if we're using file-based config but no password is set
393- if viper . GetString ( "badger_password" ) == "" {
395+ if appConfig . BadgerPassword == "" {
394396 logger .Fatal ("Badger password is required" , nil )
395397 }
396398
@@ -441,7 +443,7 @@ func GetIDFromName(name string, peers []config.Peer) string {
441443 return nodeID
442444}
443445
444- func NewBadgerKV (nodeName , nodeID string ) * kvstore.BadgerKVStore {
446+ func NewBadgerKV (nodeName , nodeID string , appConfig * config. AppConfig ) * kvstore.BadgerKVStore {
445447 // Badger KV DB
446448 // Use configured db_path or default to current directory + "db"
447449 basePath := viper .GetString ("db_path" )
@@ -459,8 +461,8 @@ func NewBadgerKV(nodeName, nodeID string) *kvstore.BadgerKVStore {
459461 // Create BadgerConfig struct
460462 config := kvstore.BadgerConfig {
461463 NodeID : nodeName ,
462- EncryptionKey : []byte (viper . GetString ( "badger_password" ) ),
463- BackupEncryptionKey : []byte (viper . GetString ( "badger_password" ) ), // Using same key for backup encryption
464+ EncryptionKey : []byte (appConfig . BadgerPassword ),
465+ BackupEncryptionKey : []byte (appConfig . BadgerPassword ), // Using same key for backup encryption
464466 BackupDir : backupDir ,
465467 DBPath : dbPath ,
466468 }
@@ -499,8 +501,8 @@ func StartPeriodicBackup(ctx context.Context, badgerKV *kvstore.BadgerKVStore, p
499501 return backupCancel
500502}
501503
502- func GetNATSConnection (environment string ) (* nats.Conn , error ) {
503- url := viper . GetString ( "nats.url" )
504+ func GetNATSConnection (environment string , appConfig * config. AppConfig ) (* nats.Conn , error ) {
505+ url := appConfig . NATs . URL
504506 opts := []nats.Option {
505507 nats .MaxReconnects (- 1 ), // retry forever
506508 nats .ReconnectWait (2 * time .Second ),
@@ -517,9 +519,12 @@ func GetNATSConnection(environment string) (*nats.Conn, error) {
517519
518520 if environment == constant .EnvProduction {
519521 // Load TLS config from configuration
520- clientCert := viper .GetString ("nats.tls.client_cert" )
521- clientKey := viper .GetString ("nats.tls.client_key" )
522- caCert := viper .GetString ("nats.tls.ca_cert" )
522+ var clientCert , clientKey , caCert string
523+ if appConfig .NATs .TLS != nil {
524+ clientCert = appConfig .NATs .TLS .ClientCert
525+ clientKey = appConfig .NATs .TLS .ClientKey
526+ caCert = appConfig .NATs .TLS .CACert
527+ }
523528
524529 // Fallback to default paths if not configured
525530 if clientCert == "" {
@@ -535,7 +540,7 @@ func GetNATSConnection(environment string) (*nats.Conn, error) {
535540 opts = append (opts ,
536541 nats .ClientCert (clientCert , clientKey ),
537542 nats .RootCAs (caCert ),
538- nats .UserInfo (viper . GetString ( "nats.username" ), viper . GetString ( "nats.password" ) ),
543+ nats .UserInfo (appConfig . NATs . Username , appConfig . NATs . Password ),
539544 )
540545 }
541546
0 commit comments