-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: postgresql user password rotation
- Loading branch information
Showing
11 changed files
with
103 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
postgres: | ||
jdbc_url: 'jdbc:postgres://localhost:5432/demo' | ||
host: 'localhost' | ||
port: 5432 | ||
database: 'demo' | ||
vault: | ||
address: 'http://localhost:8200' | ||
path: 'path/to/my/secret' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CREATE USER user1 WITH PASSWORD 'initialpw'; | ||
CREATE USER user2 WITH PASSWORD 'initialpw'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use postgres::{Client, NoTls}; | ||
|
||
use crate::config::{Config, PostgresConfig}; | ||
|
||
pub struct PostgresClient { | ||
postgres_config: PostgresConfig, | ||
} | ||
|
||
impl PostgresClient { | ||
pub(crate) fn init(config: &Config) -> PostgresClient { | ||
PostgresClient { | ||
postgres_config: config.postgres.clone(), | ||
} | ||
} | ||
|
||
pub(crate) fn connect_for_user(&self, username: String, password: String) -> Client { | ||
let host = self.postgres_config.host.as_str(); | ||
let port = self.postgres_config.port; | ||
let database = self.postgres_config.database.as_str(); | ||
|
||
Client::connect( | ||
format!( | ||
"host={host} port={port} dbname={database} user={username} password={password}" | ||
) | ||
.as_str(), | ||
NoTls, | ||
) | ||
.expect("Failed to build PostgreSQL connection") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters