Skip to content

Commit

Permalink
tembo-cli: fix clippy + update tembo-stacks and controller crates (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuckHend authored Sep 25, 2024
1 parent 4638bb3 commit 4ea4227
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 37 deletions.
11 changes: 6 additions & 5 deletions tembo-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tembo-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ tokio = { version = "1.26.0", features = [
tungstenite ="0.21.0"
futures-util = "0.3.30"
dirs = "5.0.1"
controller = "0.47.0"
controller = "0.50.0"
sqlx = { version = "0.8.2", features = ["runtime-tokio-native-tls", "postgres", "chrono", "json"] }
base64 = "0.21.5"
colorful = "0.2.2"
Expand All @@ -75,7 +75,7 @@ tiny-gradient = "0.1.0"
urlencoding = "2.1.3"
spinoff = "0.8.0"
k8s-openapi = { version = "0.18.0", features = ["v1_25", "schemars"], default-features = false }
tembo-stacks = "0.7.0"
tembo-stacks = "0.16.2"
itertools = "0.12.1"
random-string = "1.1.0"
test-case = "=2.0.0-rc2"
Expand Down
36 changes: 25 additions & 11 deletions tembo-cli/src/cmd/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub fn execute(

fn validate_overlay(merge_path: &str) -> Result<(), anyhow::Error> {
let mut file_path = PathBuf::from(FileUtils::get_current_working_dir());
file_path.push(format!("{}", merge_path));
file_path.push(merge_path);

let contents = fs::read_to_string(&file_path)?;
let config: Result<HashMap<String, InstanceSettings>, toml::de::Error> =
Expand Down Expand Up @@ -262,22 +262,21 @@ fn docker_apply_instance(
instance_setting.instance_name.clone(),
instance_setting.instance_name.clone(),
)?;
let stack: Stack;

if instance_setting.stack_file.is_some() {
let stack: Stack = if instance_setting.stack_file.is_some() {
let mut file_path = PathBuf::from(FileUtils::get_current_working_dir());
let stack_file = instance_setting.stack_file.clone().unwrap();
let cleaned_stack_file = stack_file.trim_matches('"');
file_path.push(format!("{}", cleaned_stack_file));
file_path.push(cleaned_stack_file);

let config_data = fs::read_to_string(&file_path).expect("File not found in the directory");
stack = serde_yaml::from_str(&config_data).expect("Invalid YAML File");
serde_yaml::from_str(&config_data).expect("Invalid YAML File")
} else {
let stack_type =
ControllerStackType::from_str(&instance_setting.stack_type.clone().unwrap())
.unwrap_or(ControllerStackType::Standard);
stack = get_stack(stack_type);
}
get_stack(stack_type)
};

let extensions = merge_options(
stack.extensions.clone(),
Expand Down Expand Up @@ -685,7 +684,7 @@ fn get_create_instance(
)
.unwrap(),
instance_name: instance_settings.instance_name.clone(),
stack_type: StackType::from_str(&instance_settings.stack_type.as_ref().unwrap()).unwrap(),
stack_type: StackType::from_str(instance_settings.stack_type.as_ref().unwrap()).unwrap(),
storage: Storage::from_str(instance_settings.storage.as_str()).unwrap(),
replicas: Some(instance_settings.replicas),
app_services: get_app_services(instance_settings.app_services.clone())?,
Expand All @@ -712,6 +711,16 @@ fn get_app_services(
if let Some(app_services) = maybe_app_services {
for app_type in app_services.iter() {
match app_type {
tembo_stacks::apps::types::AppType::AIProxy(maybe_app_config) => vec_app_types
.push(temboclient::models::AppType::new(
get_final_app_config(maybe_app_config)?,
None,
None,
None,
None,
None,
None,
)),
tembo_stacks::apps::types::AppType::RestAPI(maybe_app_config) => vec_app_types
.push(temboclient::models::AppType::new(
get_final_app_config(maybe_app_config)?,
Expand All @@ -720,9 +729,11 @@ fn get_app_services(
None,
None,
None,
None,
)),
tembo_stacks::apps::types::AppType::HTTP(maybe_app_config) => {
vec_app_types.push(temboclient::models::AppType::new(
None,
None,
get_final_app_config(maybe_app_config)?,
None,
Expand All @@ -733,6 +744,7 @@ fn get_app_services(
}
tembo_stacks::apps::types::AppType::MQ(maybe_app_config) => {
vec_app_types.push(temboclient::models::AppType::new(
None,
None,
None,
get_final_app_config(maybe_app_config)?,
Expand All @@ -746,6 +758,7 @@ fn get_app_services(
None,
None,
None,
None,
get_final_app_config(maybe_app_config)?,
None,
None,
Expand All @@ -756,11 +769,12 @@ fn get_app_services(
None,
None,
None,
None,
get_final_app_config(maybe_app_config)?,
None,
)),
tembo_stacks::apps::types::AppType::Custom(_) => vec_app_types.push(
temboclient::models::AppType::new(None, None, None, None, None, None),
temboclient::models::AppType::new(None, None, None, None, None, None, None),
),
}
}
Expand Down Expand Up @@ -944,7 +958,7 @@ fn get_extensions(
vec![ExtensionInstallLocation {
database: Some("postgres".to_string()),
schema: None,
version: version,
version,
enabled: extension.enabled.unwrap_or(false),
}];

Expand Down Expand Up @@ -1002,7 +1016,7 @@ fn get_trunk_installs(
if extension.trunk_project.is_some() {
vec_trunk_installs.push(TrunkInstall {
name: extension.trunk_project.unwrap(),
version: version,
version,
});
}
}
Expand Down
9 changes: 3 additions & 6 deletions tembo-cli/src/cmd/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct TokenRequest {
pub fn execute(login_cmd: LoginCommand) -> Result<(), anyhow::Error> {
let _ = list_context();
let context_file_path = tembo_context_file_path();
let contents = fs::read_to_string(&context_file_path)?;
let contents = fs::read_to_string(context_file_path)?;
let data: Context = toml::from_str(&contents)?;

match (&login_cmd.organization_id, &login_cmd.profile) {
Expand Down Expand Up @@ -110,7 +110,7 @@ async fn handle_tokio(login_url: String, cmd: &LoginCommand) -> Result<(), anyho

let result = time::timeout(Duration::from_secs(30), notify.notified()).await;
if let Some(token) = shared_state_clone.token.lock().unwrap().as_ref() {
let _ = execute_command(&cmd, token);
let _ = execute_command(cmd, token);
} else {
println!("No token was received.");
}
Expand Down Expand Up @@ -274,10 +274,7 @@ pub fn update_profile(
}

fn append_to_file(file_path: &str, content: String) -> io::Result<()> {
let mut file = OpenOptions::new()
.write(true)
.append(true)
.open(file_path)?;
let mut file = OpenOptions::new().append(true).open(file_path)?;
writeln!(file, "{}", content)?;
Ok(())
}
Expand Down
9 changes: 3 additions & 6 deletions tembo-cli/src/cmd/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async fn fetch_logs_websocket(
);
let mut key = [0u8; 16];
rand::thread_rng().fill(&mut key);
let sec_websocket_key = general_purpose::STANDARD.encode(&key);
let sec_websocket_key = general_purpose::STANDARD.encode(key);

let url = Url::parse(&ws_url)?;
let host = url
Expand Down Expand Up @@ -317,10 +317,7 @@ fn beautify_logs(json_data: &str, app_name: Option<String>) -> Result<()> {
&value[1]
),
};
entries
.entry(date_time)
.or_insert_with(Vec::new)
.push(log_detail);
entries.entry(date_time).or_default().push(log_detail);
}
_ => eprintln!("Invalid or ambiguous timestamp: {}", unix_timestamp),
}
Expand All @@ -331,7 +328,7 @@ fn beautify_logs(json_data: &str, app_name: Option<String>) -> Result<()> {
}
}

for (_date_time, logs) in &entries {
for logs in entries.values() {
for log in logs {
println!("{}", log);
}
Expand Down
12 changes: 5 additions & 7 deletions tembo-cli/src/cmd/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ pub fn execute(verbose: bool) -> Result<(), anyhow::Error> {
tembo_credentials_file_path()
);
has_error = true
} else {
if get_current_context()?.target == Target::TemboCloud.to_string() {
list_credential_profiles()?;
}
} else if get_current_context()?.target == Target::TemboCloud.to_string() {
list_credential_profiles()?;
}
if verbose {
info("Credentials file exists");
Expand Down Expand Up @@ -135,9 +133,9 @@ fn validate_stack_in_toml(config: &HashMap<String, InstanceSettings>) -> Result<
if (settings.stack_file.is_some() && settings.stack_type.is_some())
|| (settings.stack_file.is_none() && settings.stack_type.is_none())
{
return Err(Error::msg(format!(
"You can only have either a stack_file or stack_type in tembo.toml file"
)));
return Err(Error::msg(
"You can only have either a stack_file or stack_type in tembo.toml file",
));
}
}

Expand Down
9 changes: 9 additions & 0 deletions tembo-cli/temboclient/src/models/app_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct AppType {
#[serde(rename = "ai_proxy", deserialize_with = "Option::deserialize")]
#[serde(skip_serializing_if = "Option::is_none")]
pub ai_proxy: Option<Box<crate::models::AppConfig>>,
#[serde(rename = "restapi", deserialize_with = "Option::deserialize")]
#[serde(skip_serializing_if = "Option::is_none")]
pub restapi: Option<Box<crate::models::AppConfig>>,
Expand All @@ -32,6 +35,7 @@ pub struct AppType {

impl AppType {
pub fn new(
ai_proxy: Option<crate::models::AppConfig>,
restapi: Option<crate::models::AppConfig>,
http: Option<crate::models::AppConfig>,
mq_api: Option<crate::models::AppConfig>,
Expand All @@ -40,6 +44,11 @@ impl AppType {
custom: Option<crate::models::AppService>,
) -> AppType {
AppType {
ai_proxy: if let Some(x) = ai_proxy {
Some(Box::new(x))
} else {
None
},
restapi: if let Some(x) = restapi {
Some(Box::new(x))
} else {
Expand Down

0 comments on commit 4ea4227

Please sign in to comment.