Skip to content

Commit

Permalink
Drop password from ConnectionInfo (#683)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Stanton <ian@tembo.io>
Co-authored-by: Joshua Jerin <joshuaxjerin@gmail.com>
Co-authored-by: Vinícius R. Miguel <lemao.vrm07@hotmail.com>
  • Loading branch information
3 people committed Mar 28, 2024
1 parent f9cf820 commit 873b413
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
14 changes: 7 additions & 7 deletions tembo-cli/src/cmd/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ pub fn tembo_cloud_apply_instance(
is_instance_up(instance_id.as_ref().unwrap().clone(), &config, env)?;

if connection_info.is_some() {
let conn_info = get_conn_info_with_creds(
let (conn_info, password) = get_conn_info_with_creds(
profile.clone(),
instance_id,
connection_info,
Expand All @@ -366,7 +366,7 @@ pub fn tembo_cloud_apply_instance(
"Instance is up!".bold()
));
clean_console();
let connection_string = construct_connection_string(conn_info);
let connection_string = construct_connection_string(conn_info, password);
instance_started(&connection_string, &instance_settings.stack_type, "cloud");

break;
Expand All @@ -381,7 +381,7 @@ fn get_conn_info_with_creds(
instance_id: Option<String>,
connection_info: Option<Box<ConnectionInfo>>,
env: Environment,
) -> Result<ConnectionInfo, anyhow::Error> {
) -> Result<(ConnectionInfo, String), anyhow::Error> {
let dataplane_config = tembodataclient::apis::configuration::Configuration {
base_path: profile.get_tembo_data_host(),
bearer_access_token: Some(profile.tembo_access_token),
Expand All @@ -405,9 +405,9 @@ fn get_conn_info_with_creds(
let map = result.as_ref().unwrap();

conn_info.user = map.get("username").unwrap().to_string();
conn_info.password = map.get("password").unwrap().to_string();
let password = map.get("password").unwrap().to_string();

Ok(conn_info)
Ok((conn_info, password))
}

pub fn get_maybe_instance(
Expand Down Expand Up @@ -1240,11 +1240,11 @@ pub fn get_rendered_dockercompose(
Ok(rendered_dockercompose)
}

fn construct_connection_string(info: ConnectionInfo) -> String {
fn construct_connection_string(info: ConnectionInfo, password: String) -> String {
format!(
"postgresql://{}:{}@{}:{}/{}",
info.user,
urlencoding::encode(&info.password),
urlencoding::encode(&password),
info.host,
info.port,
"postgres"
Expand Down
5 changes: 1 addition & 4 deletions tembo-cli/temboclient/src/models/connection_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
pub struct ConnectionInfo {
#[serde(rename = "host")]
pub host: String,
#[serde(rename = "password")]
pub password: String,
#[serde(
rename = "pooler_host",
default,
Expand All @@ -28,10 +26,9 @@ pub struct ConnectionInfo {
}

impl ConnectionInfo {
pub fn new(host: String, password: String, port: i32, user: String) -> ConnectionInfo {
pub fn new(host: String, port: i32, user: String) -> ConnectionInfo {
ConnectionInfo {
host,
password,
pooler_host: None,
port,
user,
Expand Down

0 comments on commit 873b413

Please sign in to comment.