diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index cdcd0db00b..50501513cf 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -1055,7 +1055,14 @@ impl Shuttle { client.get_service_resources(self.ctx.project_name()).await } .map_err(suggestions::resources::get_service_resources_failure)?; - let table = get_resource_tables(&resources, self.ctx.project_name(), raw, show_secrets); + + let table = get_resource_tables( + &resources, + self.ctx.project_name(), + raw, + show_secrets, + self.beta, + ); println!("{table}"); @@ -1261,7 +1268,7 @@ impl Shuttle { println!( "{}", - get_resource_tables(&mocked_responses, service_name.as_str(), false, false) + get_resource_tables(&mocked_responses, service_name.as_str(), false, false, beta) ); // @@ -2102,7 +2109,8 @@ impl Shuttle { let resources = client .get_service_resources(self.ctx.project_name()) .await?; - let resources = get_resource_tables(&resources, self.ctx.project_name(), false, false); + let resources = + get_resource_tables(&resources, self.ctx.project_name(), false, false, self.beta); println!("{resources}{service}"); diff --git a/common/src/lib.rs b/common/src/lib.rs index 5cdf5aea18..9355a43ed2 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -94,7 +94,6 @@ pub struct DbInput { pub enum DatabaseResource { ConnectionString(String), Info(DatabaseInfo), - Beta(DatabaseInfoBeta), } /// Holds the data for building a database connection string. diff --git a/common/src/models/resource.rs b/common/src/models/resource.rs index 7e503fa64a..738f125300 100644 --- a/common/src/models/resource.rs +++ b/common/src/models/resource.rs @@ -18,6 +18,7 @@ pub fn get_resource_tables( service_name: &str, raw: bool, show_secrets: bool, + beta: bool, ) -> String { if resources.is_empty() { if raw { @@ -44,12 +45,21 @@ pub fn get_resource_tables( let mut output = Vec::new(); if let Some(databases) = resource_groups.get("Databases") { - output.push(get_databases_table( - databases, - service_name, - raw, - show_secrets, - )); + if beta { + output.push(get_databases_table_beta( + databases, + service_name, + raw, + show_secrets, + )); + } else { + output.push(get_databases_table( + databases, + service_name, + raw, + show_secrets, + )); + } }; if let Some(secrets) = resource_groups.get("Secrets") { @@ -124,7 +134,6 @@ fn get_databases_table( info.connection_string_public(show_secrets) } } - DatabaseResource::Beta(info) => info.connection_string(show_secrets), }; table.add_row(vec![database.r#type.to_string(), conn_string]); } @@ -138,6 +147,64 @@ fn get_databases_table( format!("These databases are linked to {service_name}\n{table}\n{show_secret_hint}") } +fn get_databases_table_beta( + databases: &Vec<&Response>, + service_name: &str, + raw: bool, + show_secrets: bool, +) -> String { + let mut table = Table::new(); + + if raw { + table + .load_preset(NOTHING) + .set_content_arrangement(ContentArrangement::Disabled) + .set_header(vec![ + Cell::new("Type").set_alignment(CellAlignment::Left), + Cell::new("Connection string").set_alignment(CellAlignment::Left), + ]); + } else { + table + .load_preset(UTF8_FULL) + .apply_modifier(UTF8_ROUND_CORNERS) + .set_content_arrangement(ContentArrangement::DynamicFullWidth) + .set_header(vec![ + Cell::new("Type") + .set_alignment(CellAlignment::Center) + .add_attribute(Attribute::Bold), + Cell::new("Connection string") + .add_attribute(Attribute::Bold) + .set_alignment(CellAlignment::Center), + ]); + } + + // TODO: add beta version that tries to parse databaseinfobeta? + for database in databases { + let connection_string = serde_json::from_value::(database.data.clone()) + .expect("resource data to be a valid database"); + + let conn_string = if let Ok(mut url) = connection_string.parse::() { + if url.password().is_some() && !show_secrets { + // ignore edge cases (if any) + let _ = url.set_password(Some("********")); + } + url.to_string() + } else { + connection_string + }; + + table.add_row(vec![database.r#type.to_string(), conn_string]); + } + + let show_secret_hint = if databases.is_empty() || show_secrets { + "" + } else { + "Hint: you can show the secrets of these resources using `cargo shuttle resource list --show-secrets`\n" + }; + + format!("These databases are linked to {service_name}\n{table}\n{show_secret_hint}") +} + fn get_secrets_table(secrets: &[&Response], service_name: &str, raw: bool) -> String { let mut table = Table::new(); diff --git a/resources/aws-rds/src/lib.rs b/resources/aws-rds/src/lib.rs index 2d064801a7..a00c1d38bf 100644 --- a/resources/aws-rds/src/lib.rs +++ b/resources/aws-rds/src/lib.rs @@ -71,7 +71,6 @@ impl IntoResource for OutputWrapper { Ok(match self.0.output { DatabaseResource::ConnectionString(s) => s.clone(), DatabaseResource::Info(info) => info.connection_string_shuttle(), - DatabaseResource::Beta(info) => info.connection_string(true), }) } } diff --git a/resources/shared-db/src/mongo.rs b/resources/shared-db/src/mongo.rs index 0f8ef7db36..0fecebca87 100644 --- a/resources/shared-db/src/mongo.rs +++ b/resources/shared-db/src/mongo.rs @@ -43,7 +43,6 @@ impl IntoResource for OutputWrapper { Ok(match self.0.output { DatabaseResource::ConnectionString(s) => s.clone(), DatabaseResource::Info(info) => info.connection_string_shuttle(), - DatabaseResource::Beta(info) => info.connection_string(true), }) } } diff --git a/resources/shared-db/src/postgres.rs b/resources/shared-db/src/postgres.rs index 50f5fc4506..e13ccbe6e3 100644 --- a/resources/shared-db/src/postgres.rs +++ b/resources/shared-db/src/postgres.rs @@ -57,7 +57,6 @@ impl IntoResource for OutputWrapper { Ok(match self.0.output { DatabaseResource::ConnectionString(s) => s.clone(), DatabaseResource::Info(info) => info.connection_string_shuttle(), - DatabaseResource::Beta(info) => info.connection_string(true), }) } }