-
Notifications
You must be signed in to change notification settings - Fork 3
Harmonize configs: refactor database config nesting #88
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,13 @@ | ||
| package api | ||
|
|
||
| // ServerConfig holds the configuration parameters for the server. | ||
| // | ||
| // | ||
| // Fields: | ||
| // - Host: The hostname or IP address where the server will run. | ||
| // - Port: The port number on which the server will listen for incoming requests. | ||
| // - EncryptionSecret: A secret key used for encrypting sensitive data. | ||
| // - Database: Configuration for the database connection, including: | ||
| // - DSN: The Data Source Name (DSN) for connecting to the database. | ||
| type ServerConfig struct { | ||
| Host string `mapstructure:"host" json:"host,omitempty"` | ||
| Port int64 `mapstructure:"port" json:"port,omitempty"` | ||
| EncryptionSecret string `mapstructure:"encryption_secret" json:"encryption_secret,omitempty"` | ||
| Database struct { | ||
| DSN string `mapstructure:"dsn" json:"dsn,omitempty"` | ||
| } `mapstructure:"database" json:"database,omitempty"` | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,7 +12,10 @@ import ( | |||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| type DCAServerConfig struct { | ||||||||||||||||||||||||||||||
| Server api.ServerConfig `mapstructure:"server" json:"server"` | ||||||||||||||||||||||||||||||
| Server api.ServerConfig `mapstructure:"server" json:"server"` | ||||||||||||||||||||||||||||||
| Database struct { | ||||||||||||||||||||||||||||||
| DSN string `mapstructure:"dsn" json:"dsn,omitempty"` | ||||||||||||||||||||||||||||||
| } `mapstructure:"database" json:"database,omitempty"` | ||||||||||||||||||||||||||||||
|
Comment on lines
+15
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Factor
+type DatabaseConfig struct {
+ DSN string `mapstructure:"dsn" json:"dsn,omitempty"`
+}
type DCAServerConfig struct {
Server api.ServerConfig `mapstructure:"server" json:"server"`
- Database struct {
- DSN string `mapstructure:"dsn" json:"dsn,omitempty"`
- } `mapstructure:"database" json:"database,omitempty"`
+ Database DatabaseConfig `mapstructure:"database" json:"database,omitempty"`
…
}Placing 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| BaseConfigPath string `mapstructure:"base_config_path" json:"base_config_path,omitempty"` | ||||||||||||||||||||||||||||||
| Redis storage.RedisConfig `mapstructure:"redis" json:"redis,omitempty"` | ||||||||||||||||||||||||||||||
| BlockStorage vault_config.BlockStorageConfig `mapstructure:"block_storage" json:"block_storage,omitempty"` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,7 +50,7 @@ func main() { | |||||||||||||||||||
| panic(err) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| db, err := postgres.NewPostgresBackend(cfg.Server.Database.DSN, nil) | ||||||||||||||||||||
| db, err := postgres.NewPostgresBackend(cfg.Database.DSN, nil) | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| logger.Fatalf("Failed to connect to database: %v", err) | ||||||||||||||||||||
|
Comment on lines
+53
to
55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid logging raw DSNs – credentials will leak to logs
-db, err := postgres.NewPostgresBackend(cfg.Database.DSN, nil)
+// TODO: strip password before passing to NewPostgresBackend or change the
+// backend constructor to accept a masked string for logging purposes.
+db, err := postgres.NewPostgresBackend(cfg.Database.DSN, nil)Consider:
This is a high-risk credential-exposure vector. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,13 +5,14 @@ server: | |||||||||||
| port: 8081 | ||||||||||||
| verifier_url: "http://localhost:8081" | ||||||||||||
| base_config_path: /etc/vultisig | ||||||||||||
| database: | ||||||||||||
| dsn: postgres://myuser:mypassword@localhost:5432/vultisig-plugin?sslmode=disable | ||||||||||||
| vaults_file_path: /tmp/plugin/vaults | ||||||||||||
| mode: plugin | ||||||||||||
| plugin: | ||||||||||||
| type: dca | ||||||||||||
|
|
||||||||||||
| database: | ||||||||||||
| dsn: postgres://myuser:mypassword@localhost:5432/vultisig-plugin?sslmode=disable | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+13
to
+15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plain-text DB credentials in committed config The Recommended: -dsn: postgres://myuser:mypassword@localhost:5432/vultisig-plugin?sslmode=disable
+dsn: ${PLUGIN_DB_DSN:?set PLUGIN_DB_DSN in env/secret manager}Pair this with a 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Checkov (3.2.334)[MEDIUM] 14-15: Basic Auth Credentials (CKV_SECRET_4) 🤖 Prompt for AI Agents |
||||||||||||
| relay: | ||||||||||||
| server: https://api.vultisig.com/router | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Config key mismatch:
jwt_secretvsencryption_secretapi.ServerConfigexposesEncryptionSecret, but the JSON fixture still usesjwt_secret.This field will be silently dropped by
viper.Unmarshal, so authentication may break at runtime.Change the snippet to:
(or add a mapstructure tag alias if you must retain the old name).
📝 Committable suggestion
🧰 Tools
🪛 Checkov (3.2.334)
[MEDIUM] 58-59: Basic Auth Credentials
(CKV_SECRET_4)
🤖 Prompt for AI Agents