configureClientCertificates sets up client certificates for mutual TLS authentication
(ds *storepb.DataSource, cfg *tls.Config)
| 191 | |
| 192 | // configureClientCertificates sets up client certificates for mutual TLS authentication |
| 193 | func configureClientCertificates(ds *storepb.DataSource, cfg *tls.Config) error { |
| 194 | // Validate that both cert and key are provided together |
| 195 | if (ds.GetSslCert() == "" && ds.GetSslKey() != "") || (ds.GetSslCert() != "" && ds.GetSslKey() == "") { |
| 196 | return errors.Errorf("ssl-cert and ssl-key must be both set or unset") |
| 197 | } |
| 198 | |
| 199 | // Configure client certificate if both cert and key are provided |
| 200 | if ds.GetSslCert() != "" && ds.GetSslKey() != "" { |
| 201 | certs, err := tls.X509KeyPair([]byte(ds.GetSslCert()), []byte(ds.GetSslKey())) |
| 202 | if err != nil { |
| 203 | return err |
| 204 | } |
| 205 | cfg.Certificates = []tls.Certificate{certs} |
| 206 | } |
| 207 | |
| 208 | return nil |
| 209 | } |
| 210 | |
| 211 | // SSLMode is the PGSSLMode type. |
| 212 | // https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLMODE |
no test coverage detected