feat: Add SSL mode

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2023-01-14 15:52:03 +01:00
parent 8709ee542b
commit 572a87a736
No known key found for this signature in database
GPG key ID: A2EB1F2CA8E3F677
2 changed files with 5 additions and 0 deletions

View file

@ -24,6 +24,7 @@ type Config struct {
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
SSLMode string `yaml:"sslmode"`
Interval float64 `yaml:"interval"`
ConnectTimeout int `yaml:"connect-timeout"`
IdleTimeout float64 `yaml:"idle-timeout"`
@ -117,6 +118,9 @@ func (c *Config) Dsn() string {
if c.ConnectTimeout != 0 {
parameters = append(parameters, fmt.Sprintf("connect_timeout=%d", c.ConnectTimeout))
}
if c.SSLMode != "" {
parameters = append(parameters, fmt.Sprintf("sslmode=%s", c.SSLMode))
}
if AppName != "" {
parameters = append(parameters, fmt.Sprintf("application_name=%s", AppName))
}

View file

@ -43,6 +43,7 @@ func main() {
flag.StringVar(&config.User, "user", "", "Instance username")
flag.StringVar(&config.Password, "password", "", "Instance password")
flag.StringVar(&config.Database, "database", "", "Instance database")
flag.StringVar(&config.SSLMode, "sslmode", "", "SSL mode (see https://www.postgresql.org/docs/current/libpq-ssl.html)")
prompt := flag.Bool("prompt-password", false, "Prompt for password")
flag.Float64Var(&config.Interval, "interval", 1, "Time to sleep between iterations in seconds")
flag.IntVar(&config.ConnectTimeout, "connect-timeout", 3, "Connection timeout in seconds")