Support port number in postgres connection (#20662)
* Support port number in postgres connection * Addressed a few comments from Trent
This commit is contained in:
		| @@ -39,6 +39,7 @@ pub struct AccountsDbPluginPostgresConfig { | |||||||
|     pub host: String, |     pub host: String, | ||||||
|     pub user: String, |     pub user: String, | ||||||
|     pub threads: Option<usize>, |     pub threads: Option<usize>, | ||||||
|  |     pub port: Option<u16>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Error, Debug)] | #[derive(Error, Debug)] | ||||||
|   | |||||||
| @@ -25,6 +25,7 @@ use { | |||||||
| /// The maximum asynchronous requests allowed in the channel to avoid excessive | /// The maximum asynchronous requests allowed in the channel to avoid excessive | ||||||
| /// memory usage. The downside -- calls after this threshold is reached can get blocked. | /// memory usage. The downside -- calls after this threshold is reached can get blocked. | ||||||
| const MAX_ASYNC_REQUESTS: usize = 10240; | const MAX_ASYNC_REQUESTS: usize = 10240; | ||||||
|  | const DEFAULT_POSTGRES_PORT: u16 = 5432; | ||||||
|  |  | ||||||
| struct PostgresSqlClientWrapper { | struct PostgresSqlClientWrapper { | ||||||
|     client: Client, |     client: Client, | ||||||
| @@ -147,7 +148,10 @@ pub trait PostgresClient { | |||||||
|  |  | ||||||
| impl SimplePostgresClient { | impl SimplePostgresClient { | ||||||
|     pub fn new(config: &AccountsDbPluginPostgresConfig) -> Result<Self, AccountsDbPluginError> { |     pub fn new(config: &AccountsDbPluginPostgresConfig) -> Result<Self, AccountsDbPluginError> { | ||||||
|         let connection_str = format!("host={} user={}", config.host, config.user); |         let port = config.port.unwrap_or(DEFAULT_POSTGRES_PORT); | ||||||
|  |  | ||||||
|  |         let connection_str = format!("host={} user={} port={}", config.host, config.user, port); | ||||||
|  |  | ||||||
|         match Client::connect(&connection_str, NoTls) { |         match Client::connect(&connection_str, NoTls) { | ||||||
|             Err(err) => { |             Err(err) => { | ||||||
|                 return Err(AccountsDbPluginError::Custom(Box::new(AccountsDbPluginPostgresError::DataStoreConnectionError { |                 return Err(AccountsDbPluginError::Custom(Box::new(AccountsDbPluginPostgresError::DataStoreConnectionError { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user