|
4 | 4 | "context"
|
5 | 5 | "errors"
|
6 | 6 | "fmt"
|
| 7 | + "net/url" |
7 | 8 | "strings"
|
8 | 9 |
|
9 | 10 | naisv1 "github.com/nais/liberator/pkg/apis/nais.io/v1"
|
@@ -143,12 +144,18 @@ func (i *DBInfo) dbConnectionMultiDB(ctx context.Context) (*ConnectionInfo, erro
|
143 | 144 | }
|
144 | 145 |
|
145 | 146 | func createConnectionInfo(secret corev1.Secret, instance string) *ConnectionInfo {
|
| 147 | + u, err := url.Parse(getSecretDataValue(secret, "_URL")) |
| 148 | + if err != nil { |
| 149 | + panic(err) |
| 150 | + } |
| 151 | + |
146 | 152 | return &ConnectionInfo{
|
147 | 153 | username: getSecretDataValue(secret, "_USERNAME"),
|
148 | 154 | password: getSecretDataValue(secret, "_PASSWORD"),
|
149 | 155 | dbName: getSecretDataValue(secret, "_DATABASE"),
|
150 | 156 | port: getSecretDataValue(secret, "_PORT"),
|
151 | 157 | host: getSecretDataValue(secret, "_HOST"),
|
| 158 | + url: u, |
152 | 159 | instance: instance,
|
153 | 160 | }
|
154 | 161 | }
|
@@ -271,18 +278,20 @@ type ConnectionInfo struct {
|
271 | 278 | instance string
|
272 | 279 | port string
|
273 | 280 | host string
|
| 281 | + url *url.URL |
274 | 282 | }
|
275 | 283 |
|
276 |
| -func (c *ConnectionInfo) ConnectionString() string { |
| 284 | +func (c *ConnectionInfo) ProxyConnectionString() string { |
277 | 285 | return fmt.Sprintf("host=%v user=%v dbname=%v password=%v sslmode=disable", c.instance, c.username, c.dbName, c.password)
|
278 | 286 | }
|
279 | 287 |
|
280 | 288 | func (c *ConnectionInfo) JDBCURL() string {
|
281 |
| - return fmt.Sprintf("postgres://%v:%v@%v:%v/%v", c.username, c.password, c.host, c.port, c.dbName) |
| 289 | + return c.url.String() |
282 | 290 | }
|
283 | 291 |
|
284 | 292 | func (c *ConnectionInfo) SetPassword(password string) {
|
285 | 293 | c.password = password
|
| 294 | + c.url.User = url.UserPassword(c.username, password) |
286 | 295 | }
|
287 | 296 |
|
288 | 297 | func getSecretDataValue(secret corev1.Secret, suffix string) string {
|
|
0 commit comments