Skip to content

Commit 03259db

Browse files
committed
Fix suggestions
1 parent f32b60c commit 03259db

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func init() {
8989
rootCmd.PersistentFlags().String("storage-orchestrator-postgres-username", "", "PostgreSQL username for orchestrator storage")
9090
rootCmd.PersistentFlags().String("storage-orchestrator-postgres-password", "", "PostgreSQL password for orchestrator storage")
9191
rootCmd.PersistentFlags().String("storage-orchestrator-postgres-database", "", "PostgreSQL database for orchestrator storage")
92-
rootCmd.PersistentFlags().String("storage-orchestrator-postgres-sslMode", "disable", "PostgreSQL SSL mode for orchestrator storage (disable, require, verify-ca, verify-full)")
92+
rootCmd.PersistentFlags().String("storage-orchestrator-postgres-sslMode", "require", "PostgreSQL SSL mode for orchestrator storage (disable, require, verify-ca, verify-full)")
9393
rootCmd.PersistentFlags().Int("storage-orchestrator-postgres-maxOpenConns", 50, "PostgreSQL max open connections for orchestrator storage")
9494
rootCmd.PersistentFlags().Int("storage-orchestrator-postgres-maxIdleConns", 25, "PostgreSQL max idle connections for orchestrator storage")
9595
rootCmd.PersistentFlags().Int("storage-orchestrator-postgres-maxConnLifetime", 300, "PostgreSQL max connection lifetime in seconds for orchestrator storage")
@@ -119,7 +119,7 @@ func init() {
119119
rootCmd.PersistentFlags().String("storage-staging-postgres-username", "", "PostgreSQL username for staging storage")
120120
rootCmd.PersistentFlags().String("storage-staging-postgres-password", "", "PostgreSQL password for staging storage")
121121
rootCmd.PersistentFlags().String("storage-staging-postgres-database", "", "PostgreSQL database for staging storage")
122-
rootCmd.PersistentFlags().String("storage-staging-postgres-sslMode", "disable", "PostgreSQL SSL mode for staging storage (disable, require, verify-ca, verify-full)")
122+
rootCmd.PersistentFlags().String("storage-staging-postgres-sslMode", "require", "PostgreSQL SSL mode for staging storage (disable, require, verify-ca, verify-full)")
123123
rootCmd.PersistentFlags().Int("storage-staging-postgres-maxOpenConns", 50, "PostgreSQL max open connections for staging storage")
124124
rootCmd.PersistentFlags().Int("storage-staging-postgres-maxIdleConns", 25, "PostgreSQL max idle connections for staging storage")
125125
rootCmd.PersistentFlags().Int("storage-staging-postgres-maxConnLifetime", 300, "PostgreSQL max connection lifetime in seconds for staging storage")

internal/storage/postgres.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
_ "github.com/lib/pq"
12+
"github.com/rs/zerolog/log"
1213
config "github.com/thirdweb-dev/indexer/configs"
1314
"github.com/thirdweb-dev/indexer/internal/common"
1415
)
@@ -22,11 +23,13 @@ func NewPostgresConnector(cfg *config.PostgresConfig) (*PostgresConnector, error
2223
connStr := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s",
2324
cfg.Host, cfg.Port, cfg.Username, cfg.Password, cfg.Database)
2425

25-
if cfg.SSLMode != "" {
26-
connStr += fmt.Sprintf(" sslmode=%s", cfg.SSLMode)
27-
} else {
28-
connStr += " sslmode=disable"
26+
// Default to "require" for security if SSL mode not specified
27+
sslMode := cfg.SSLMode
28+
if sslMode == "" {
29+
sslMode = "require"
30+
log.Info().Msg("No SSL mode specified, defaulting to 'require' for secure connection")
2931
}
32+
connStr += fmt.Sprintf(" sslmode=%s", sslMode)
3033

3134
if cfg.ConnectTimeout > 0 {
3235
connStr += fmt.Sprintf(" connect_timeout=%d", cfg.ConnectTimeout)
@@ -103,7 +106,11 @@ func (p *PostgresConnector) GetBlockFailures(qf QueryFilter) ([]common.BlockFail
103106
if err != nil {
104107
return nil, err
105108
}
106-
defer rows.Close()
109+
defer func() {
110+
if err := rows.Close(); err != nil {
111+
log.Error().Err(err).Msg("Failed to close rows in GetBlockFailures")
112+
}
113+
}()
107114

108115
var failures []common.BlockFailure
109116
for rows.Next() {
@@ -119,8 +126,17 @@ func (p *PostgresConnector) GetBlockFailures(qf QueryFilter) ([]common.BlockFail
119126
}
120127

121128
// Convert NUMERIC string to big.Int
122-
failure.ChainId, _ = new(big.Int).SetString(chainIdStr, 10)
123-
failure.BlockNumber, _ = new(big.Int).SetString(blockNumberStr, 10)
129+
var ok bool
130+
failure.ChainId, ok = new(big.Int).SetString(chainIdStr, 10)
131+
if !ok {
132+
return nil, fmt.Errorf("failed to parse chain_id '%s' as big.Int", chainIdStr)
133+
}
134+
135+
failure.BlockNumber, ok = new(big.Int).SetString(blockNumberStr, 10)
136+
if !ok {
137+
return nil, fmt.Errorf("failed to parse block_number '%s' as big.Int", blockNumberStr)
138+
}
139+
124140
failure.FailureTime = time.Unix(timestamp, 0)
125141
failure.FailureCount = count
126142

@@ -312,7 +328,11 @@ func (p *PostgresConnector) GetStagingData(qf QueryFilter) ([]common.BlockData,
312328
if err != nil {
313329
return nil, err
314330
}
315-
defer rows.Close()
331+
defer func() {
332+
if err := rows.Close(); err != nil {
333+
log.Error().Err(err).Msg("Failed to close rows in GetStagingData")
334+
}
335+
}()
316336

317337
// Initialize as empty slice to match ClickHouse behavior
318338
blockDataList := make([]common.BlockData, 0)

0 commit comments

Comments
 (0)