From 2206a7f1cd8937d8213954d2951cce3e561a2529 Mon Sep 17 00:00:00 2001 From: Francisco Moura Date: Mon, 2 Sep 2024 22:04:13 -0300 Subject: [PATCH] fix(db): Fix Schema postgres ssl mode handling --- build/compose-devnet.yaml | 2 +- docs/config.md | 2 +- internal/node/config/config.go | 4 ++-- internal/node/config/generate/Config.toml | 2 +- internal/node/config/generated.go | 6 +++--- internal/node/startup/startup.go | 2 +- setup_env.sh | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build/compose-devnet.yaml b/build/compose-devnet.yaml index 2be3edc12..a4887869b 100644 --- a/build/compose-devnet.yaml +++ b/build/compose-devnet.yaml @@ -34,4 +34,4 @@ services: CARTESI_FEATURE_MACHINE_HASH_CHECK_ENABLED: "false" CARTESI_AUTH_KIND: "mnemonic" CARTESI_AUTH_MNEMONIC: "test test test test test test test test test test test junk" - CARTESI_POSTGRES_SSLMODE_ENABLED: "false" + CARTESI_POSTGRES_SSL_ENABLED: "false" diff --git a/docs/config.md b/docs/config.md index 67a4653ae..460f264a1 100644 --- a/docs/config.md +++ b/docs/config.md @@ -216,7 +216,7 @@ for more information. * **Type:** `string` * **Default:** `""` -## `CARTESI_POSTGRES_SSLMODE_ENABLED` +## `CARTESI_POSTGRES_SSL_ENABLED` When enabled, will connect to postgres database via SSL. diff --git a/internal/node/config/config.go b/internal/node/config/config.go index a67323e49..91b9993a0 100644 --- a/internal/node/config/config.go +++ b/internal/node/config/config.go @@ -30,7 +30,7 @@ type NodeConfig struct { ContractsInputBoxDeploymentBlockNumber int64 SnapshotDir string PostgresEndpoint Redacted[string] - PostgresSslMode bool + PostgresSslDisabled bool HttpAddress string HttpPort int FeatureClaimerEnabled bool @@ -91,7 +91,7 @@ func FromEnv() NodeConfig { config.ContractsInputBoxDeploymentBlockNumber = getContractsInputBoxDeploymentBlockNumber() config.SnapshotDir = getSnapshotDir() config.PostgresEndpoint = Redacted[string]{getPostgresEndpoint()} - config.PostgresSslMode = getPostgresSslmodeEnabled() + config.PostgresSslDisabled = !getPostgresSslEnabled() config.HttpAddress = getHttpAddress() config.HttpPort = getHttpPort() config.FeatureClaimerEnabled = getFeatureClaimerEnabled() diff --git a/internal/node/config/generate/Config.toml b/internal/node/config/generate/Config.toml index a1b9dfe27..c86fbebc4 100644 --- a/internal/node/config/generate/Config.toml +++ b/internal/node/config/generate/Config.toml @@ -206,7 +206,7 @@ It is also possible to set the endpoint without a password and load it from Post See [this](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-PASSFILE) for more information.""" -[postgres.CARTESI_POSTGRES_SSLMODE_ENABLED] +[postgres.CARTESI_POSTGRES_SSL_ENABLED] default = "true" go-type = "bool" description = """ diff --git a/internal/node/config/generated.go b/internal/node/config/generated.go index 24c899e2e..a3ceb8aff 100644 --- a/internal/node/config/generated.go +++ b/internal/node/config/generated.go @@ -456,14 +456,14 @@ func getPostgresEndpoint() string { return val } -func getPostgresSslmodeEnabled() bool { - s, ok := os.LookupEnv("CARTESI_POSTGRES_SSLMODE_ENABLED") +func getPostgresSslEnabled() bool { + s, ok := os.LookupEnv("CARTESI_POSTGRES_SSL_ENABLED") if !ok { s = "true" } val, err := toBool(s) if err != nil { - panic(fmt.Sprintf("failed to parse CARTESI_POSTGRES_SSLMODE_ENABLED: %v", err)) + panic(fmt.Sprintf("failed to parse CARTESI_POSTGRES_SSL_ENABLED: %v", err)) } return val } diff --git a/internal/node/startup/startup.go b/internal/node/startup/startup.go index 2dbbfdad5..a57a58410 100644 --- a/internal/node/startup/startup.go +++ b/internal/node/startup/startup.go @@ -22,7 +22,7 @@ import ( // Validates the Node Database Schema Version func ValidateSchema(config config.NodeConfig) error { endpoint := config.PostgresEndpoint.Value - if config.PostgresSslMode { + if config.PostgresSslDisabled { endpoint += "?sslmode=disable" } diff --git a/setup_env.sh b/setup_env.sh index 5b3fbf1a6..dda652e44 100644 --- a/setup_env.sh +++ b/setup_env.sh @@ -19,7 +19,7 @@ export CARTESI_AUTH_MNEMONIC="test test test test test test test test test test export CARTESI_POSTGRES_ENDPOINT="postgres://postgres:password@localhost:5432/postgres" export CARTESI_HTTP_ADDRESS="0.0.0.0" export CARTESI_HTTP_PORT="10000" -export CARTESI_POSTGRES_SSLMODE_ENABLED="false" +export CARTESI_POSTGRES_SSL_ENABLED="false" rust_bin_path="$PWD/cmd/authority-claimer/target/debug" # Check if the path is already in $PATH