feat!: replace password environment with Docker secret references
This commit is contained in:
@@ -190,7 +190,7 @@ func TestParsePostgresContainer(t *testing.T) {
|
||||
postgres {
|
||||
image postgres:18
|
||||
volume analytics-data
|
||||
password_env ANALYTICS_POSTGRES_PASSWORD
|
||||
password_secret analytics_password
|
||||
idle_timeout 15m
|
||||
traffic_idle_timeout 1h
|
||||
}
|
||||
@@ -200,7 +200,7 @@ func TestParsePostgresContainer(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
database := cfg.Databases[0]
|
||||
if database.Postgres == nil || database.Postgres.Image != "postgres:18" || database.Postgres.Volume != "analytics-data" || database.Postgres.PasswordEnv != "ANALYTICS_POSTGRES_PASSWORD" || database.Postgres.IdleTimeout != 15*time.Minute || database.Postgres.TrafficIdleTimeout != time.Hour {
|
||||
if database.Postgres == nil || database.Postgres.Image != "postgres:18" || database.Postgres.Volume != "analytics-data" || database.Postgres.PasswordSecret != "analytics_password" || database.Postgres.IdleTimeout != 15*time.Minute || database.Postgres.TrafficIdleTimeout != time.Hour {
|
||||
t.Errorf("Postgres = %#v", database.Postgres)
|
||||
}
|
||||
if err := cfg.Validate(); err != nil {
|
||||
@@ -219,7 +219,7 @@ func TestParseRejectsInvalidPostgresIdleTimeout(t *testing.T) {
|
||||
postgres {
|
||||
image postgres:18
|
||||
volume analytics-data
|
||||
password_env ANALYTICS_POSTGRES_PASSWORD
|
||||
password_secret analytics_password
|
||||
idle_timeout whenever
|
||||
}
|
||||
}
|
||||
@@ -240,7 +240,7 @@ func TestParseRejectsInvalidPostgresTrafficIdleTimeout(t *testing.T) {
|
||||
postgres {
|
||||
image postgres:18
|
||||
volume analytics-data
|
||||
password_env ANALYTICS_POSTGRES_PASSWORD
|
||||
password_secret analytics_password
|
||||
traffic_idle_timeout whenever
|
||||
}
|
||||
}
|
||||
@@ -257,7 +257,7 @@ func TestValidateAllowsSupportedPostgresImages(t *testing.T) {
|
||||
TLS: TLSConfig{CertFile: "cert.pem", KeyFile: "key.pem"},
|
||||
Databases: []DatabaseConfig{{
|
||||
Name: "analytics",
|
||||
Postgres: &PostgresConfig{Image: image, Volume: "analytics-data", PasswordEnv: "ANALYTICS_POSTGRES_PASSWORD"},
|
||||
Postgres: &PostgresConfig{Image: image, Volume: "analytics-data", PasswordSecret: "analytics_password"},
|
||||
}},
|
||||
}
|
||||
if err := cfg.Validate(); err != nil {
|
||||
@@ -272,7 +272,7 @@ func TestValidateRejectsUnsupportedPostgresImage(t *testing.T) {
|
||||
TLS: TLSConfig{CertFile: "cert.pem", KeyFile: "key.pem"},
|
||||
Databases: []DatabaseConfig{{
|
||||
Name: "analytics",
|
||||
Postgres: &PostgresConfig{Image: "postgres:15", Volume: "analytics-data", PasswordEnv: "ANALYTICS_POSTGRES_PASSWORD"},
|
||||
Postgres: &PostgresConfig{Image: "postgres:15", Volume: "analytics-data", PasswordSecret: "analytics_password"},
|
||||
}},
|
||||
}
|
||||
err := cfg.Validate()
|
||||
@@ -281,6 +281,32 @@ func TestValidateRejectsUnsupportedPostgresImage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRejectsInvalidSecretReference(t *testing.T) {
|
||||
for _, reference := range []string{"", "UPPERCASE", "../secret", "has-hyphen", strings.Repeat("a", 55)} {
|
||||
cfg := Config{
|
||||
Listen: ":5432",
|
||||
Databases: []DatabaseConfig{{
|
||||
Name: "analytics",
|
||||
Postgres: &PostgresConfig{
|
||||
Image: "postgres:18",
|
||||
Volume: "analytics-data",
|
||||
PasswordSecret: reference,
|
||||
},
|
||||
}},
|
||||
}
|
||||
err := cfg.Validate()
|
||||
if err == nil || !strings.Contains(err.Error(), "password_secret") {
|
||||
t.Errorf("Validate() reference %q error = %v, want password_secret error", reference, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDockerSecretNamePrefixesShortReference(t *testing.T) {
|
||||
if got := DockerSecretName("analytics_password"); got != "barkstack_analytics_password" {
|
||||
t.Fatalf("DockerSecretName() = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseMalformedBlocksReportLine(t *testing.T) {
|
||||
_, err := Parse([]byte("pawsql {\n tls {\n cert cert.pem\n"))
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user