Skip to content

Commit 4eb544b

Browse files
committed
Add IDs to common objects
fixes [sc-12241]
1 parent 4441009 commit 4eb544b

File tree

9 files changed

+55
-16
lines changed

9 files changed

+55
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ subprocess = "0.1"
7979
tempfile = "3.2.0"
8080
termcolor = "1.1"
8181
urlencoding = "2.1.0"
82+
url = "2.2.2"
8283
version-compare = "0.1.0"
8384
webbrowser = "0.8.3"
8485
is-terminal = "0.4.9"

src/database/parameter_details.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct ParameterDetails {
3737
impl ParameterDetails {
3838
pub fn get_property(&self, property_name: &str) -> String {
3939
match property_name {
40+
"id" => self.id.clone(),
4041
"name" => self.key.clone(),
4142
"value" => self.value.clone(),
4243
"type" => self.param_type.clone(),

src/database/user_details.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct UserDetails {
2727
impl UserDetails {
2828
pub fn get_property(&self, property_name: &str) -> String {
2929
match property_name {
30+
"id" => self.id.clone(),
3031
"name" => self.name.clone(),
3132
"type" => self.account_type.clone(),
3233
"email" => match self.account_type.as_str() {

src/environments.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ fn proc_env_list(
6161
println!("{}", list.join("\n"));
6262
} else {
6363
let mut table = Table::new("environment");
64-
let mut hdr = vec!["Name", "Parent", "Description"];
64+
let mut hdr = vec!["ID", "Name", "Parent", "Description"];
6565
if show_times {
6666
hdr.push("Created At");
6767
hdr.push("Modified At");
6868
}
6969
table.set_header(&hdr);
7070
for entry in details {
71-
let mut row = vec![entry.name, entry.parent_name, entry.description];
71+
let mut row = vec![entry.id, entry.name, entry.parent_name, entry.description];
7272
if show_times {
7373
row.push(entry.created_at);
7474
row.push(entry.modified_at);
@@ -219,7 +219,14 @@ fn proc_env_tag_list(
219219
println!("{}", list.join("\n"))
220220
} else {
221221
let mut table = Table::new("environment-tags");
222-
let hdr = vec!["Name", "Timestamp", "Description", "Immutable"];
222+
let hdr = vec![
223+
"ID",
224+
"Name",
225+
"Timestamp",
226+
"Description",
227+
"Immutable",
228+
"Environment_ID",
229+
];
223230
// if show_usage {
224231
// hdr.push("Last User");
225232
// hdr.push("Last Time");
@@ -228,10 +235,12 @@ fn proc_env_tag_list(
228235
table.set_header(&hdr);
229236
for entry in tags {
230237
let row = vec![
238+
entry.id,
231239
entry.name,
232240
entry.timestamp,
233241
entry.description,
234242
entry.immutable.map(|i| i.to_string()).unwrap_or_default(),
243+
env_id.clone(),
235244
];
236245
// if show_usage {
237246
// row.push(entry.last_use_user);

src/parameters.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ fn proc_param_list(
655655
} else if show_rules {
656656
// NOTE: do NOT worry about errors, since we're only concerned with params (not values)
657657
let mut table = Table::new("parameter");
658-
let mut hdr = vec!["Name", "Param Type", "Rule Type", "Constraint"];
658+
let mut hdr = vec!["ID", "Name", "Param Type", "Rule Type", "Constraint"];
659659
if show_times {
660660
hdr.push("Created At");
661661
hdr.push("Modified At");
@@ -685,16 +685,17 @@ fn proc_param_list(
685685

686686
// setup the table headers and properties
687687
if show_external {
688-
hdr = vec!["Name", "FQN", "JMES"];
689-
properties = vec!["name", "fqn", "jmes-path"];
688+
hdr = vec!["ID", "Name", "FQN", "JMES"];
689+
properties = vec!["id", "name", "fqn", "jmes-path"];
690690
} else if show_evaluated {
691-
hdr = vec!["Name", "Value", "Raw"];
692-
properties = vec!["name", "value", "raw"];
691+
hdr = vec!["ID", "Name", "Value", "Raw"];
692+
properties = vec!["id", "name", "value", "raw"];
693693
} else if show_parents || show_children {
694-
hdr = vec!["Name", "Value", "Project"];
695-
properties = vec!["name", "value", "project-name"];
694+
hdr = vec!["ID", "Name", "Value", "Project"];
695+
properties = vec!["id", "name", "value", "project-name"];
696696
} else {
697697
hdr = vec![
698+
"ID",
698699
"Name",
699700
"Value",
700701
"Source",
@@ -705,6 +706,7 @@ fn proc_param_list(
705706
"Description",
706707
];
707708
properties = vec![
709+
"id",
708710
"name",
709711
"value",
710712
"environment",

src/projects.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::cli::{
66
use crate::database::{OpenApiConfig, ProjectDetails, Projects};
77
use crate::table::Table;
88
use crate::utils::{
9-
error_message, parse_key_value_pairs, user_confirm, warn_missing_subcommand, warning_message,
10-
DEL_CONFIRM,
9+
error_message, get_uuid_from_url, parse_key_value_pairs, user_confirm, warn_missing_subcommand,
10+
warning_message, DEL_CONFIRM,
1111
};
1212
use clap::ArgMatches;
1313
use color_eyre::eyre::Result;
@@ -60,14 +60,20 @@ fn proc_proj_list(
6060
println!("{}", list.join("\n"));
6161
} else {
6262
let mut table = Table::new("project");
63-
let mut hdr = vec!["Name", "Parent", "Description"];
63+
let mut hdr = vec!["ID", "Name", "Parent", "Parent_ID", "Description"];
6464
if show_times {
6565
hdr.push("Created At");
6666
hdr.push("Modified At");
6767
}
6868
table.set_header(&hdr);
6969
for entry in details {
70-
let mut row = vec![entry.name, entry.parent_name, entry.description];
70+
let mut row = vec![
71+
entry.id,
72+
entry.name,
73+
entry.parent_name,
74+
get_uuid_from_url(&entry.parent_url.clone()),
75+
entry.description,
76+
];
7177
if show_times {
7278
row.push(entry.created_at);
7379
row.push(entry.modified_at);

src/users.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ fn proc_users_list(
108108
.collect::<Vec<String>>();
109109
println!("{}", list.join("\n"))
110110
} else {
111-
let mut hdr = vec!["Name", "Type", "Role", "Email", "Description"];
112-
let mut properties = vec!["name", "type", "role", "email", "description"];
111+
let mut hdr = vec!["ID", "Name", "Type", "Role", "Email", "Description"];
112+
let mut properties = vec!["id", "name", "type", "role", "email", "description"];
113113
if show_times {
114114
hdr.push("Created At");
115115
hdr.push("Modified At");

src/utils.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::fmt::Formatter;
88
use std::io::{stdin, stdout, Write};
99
use std::str;
1010
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
11+
use url::Url;
1112

1213
// The `DEL_CONFIRM` is the default value for delete confirmation across different types
1314
pub const DEL_CONFIRM: Option<bool> = Some(false);
@@ -214,6 +215,23 @@ pub fn parse_tag(input: Option<&str>) -> Option<String> {
214215
}
215216
}
216217

218+
pub fn get_uuid_from_url(url: &str) -> String {
219+
if let Ok(url) = Url::parse(url) {
220+
let path_segments: Vec<_> = url.path_segments().unwrap().collect();
221+
if let Some(uuid_segment) = path_segments.get(3) {
222+
if uuid_segment.len() == 36 {
223+
uuid_segment.to_string()
224+
} else {
225+
"".to_string()
226+
}
227+
} else {
228+
"".to_string()
229+
}
230+
} else {
231+
"".to_string()
232+
}
233+
}
234+
217235
/// Return the default value of a type according to the `Default` trait.
218236
///
219237
/// The type to return is inferred from context; this is equivalent to

0 commit comments

Comments
 (0)