Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

Commit

Permalink
Add jdbcUrl to postgres binding (#698)
Browse files Browse the repository at this point in the history
* Add jdbcUrl to postgres binding

* query escape password in connection strings

* run through gofmt
  • Loading branch information
olevett authored and zhongyi-zhang committed May 9, 2019
1 parent 52d35ce commit ac1bd72
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 4 additions & 2 deletions docs/modules/postgresql.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ Binding returns the following connection details and credentials:
| `database` | `string` | The name of the database. |
| `username` | `string` | The name of the database user (in the form username@host). |
| `password` | `string` | The password for the database user. |
| `sslRequired` | `boolean` | Flag indicating if SSL is required to connect the MySQL DBMS. |
| `sslRequired` | `boolean` | Flag indicating if SSL is required to connect the PostgreSQL DBMS. |
| `uri` | `string` | A URI string containing all necessary connection information. |
| `jdbcUrl` | `string` | A fully formed JDBC url. |
| `tags` | `string[]` | A list of tags consumers can use to identify the credential. |

##### Unbind
Expand Down Expand Up @@ -465,8 +466,9 @@ Binding returns the following connection details and credentials:
| `database` | `string` | The name of the database. |
| `username` | `string` | The name of the database user (in the form username@host). |
| `password` | `string` | The password for the database user. |
| `sslRequired` | `boolean` | Flag indicating if SSL is required to connect the MySQL DBMS. |
| `sslRequired` | `boolean` | Flag indicating if SSL is required to connect the PostgreSQL DBMS. |
| `uri` | `string` | A URI string containing all necessary connection information. |
| `jdbcUrl` | `string` | A fully formed JDBC url. |
| `tags` | `string[]` | A list of tags consumers can use to identify the credential. |

##### Unbind
Expand Down
21 changes: 20 additions & 1 deletion pkg/services/postgresql/common_bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,29 @@ func createCredential(
connectionString := fmt.Sprintf(
connectionTemplate,
url.QueryEscape(username),
string(bindDetails.Password),
url.QueryEscape(string(bindDetails.Password)),
fqdn,
port,
databaseName,
)

var jdbcTemplate string
if sslRequired {
jdbcTemplate =
"jdbc:postgresql://%s:%d/%s?user=%s&password=%s&sslmode=require"
} else {
jdbcTemplate = "jdbc:postgresql://%s:%d/%s?user=%s&password=%s"
}

jdbc := fmt.Sprintf(
jdbcTemplate,
fqdn,
port,
databaseName,
url.QueryEscape(username),
url.QueryEscape(string(bindDetails.Password)),
)

return credentials{
Host: fqdn,
Port: port,
Expand All @@ -118,6 +136,7 @@ func createCredential(
Password: string(bindDetails.Password),
SSLRequired: sslRequired,
URI: connectionString,
JDBC: jdbc,
Tags: []string{"postgresql"},
}
}
1 change: 1 addition & 0 deletions pkg/services/postgresql/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type credentials struct {
Username string `json:"username"`
Password string `json:"password"`
URI string `json:"uri"`
JDBC string `json:"jdbcUrl"`
SSLRequired bool `json:"sslRequired"`
Tags []string `json:"tags"`
}

0 comments on commit ac1bd72

Please sign in to comment.