-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adds support for updating & deleting instance on tembo-cloud #411
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9d3a055
adds support for updating instance
shahadarsh 5470907
Merge branch 'main' into update-instance
shahadarsh 417692b
adds support for deleting instance
shahadarsh 3879d2f
using ? instead of match
shahadarsh 8413ff0
uses const instead of function for DOT_TEMBO_FOLDER
shahadarsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,67 @@ | ||
use crate::{cli::docker::Docker, Result}; | ||
use std::collections::HashMap; | ||
|
||
use crate::{ | ||
cli::{ | ||
context::{get_current_context, Environment, Target}, | ||
docker::Docker, | ||
tembo_config::InstanceSettings, | ||
}, | ||
Result, | ||
}; | ||
use clap::{ArgMatches, Command}; | ||
use core::result::Result::Ok; | ||
use temboclient::apis::{configuration::Configuration, instance_api::delete_instance}; | ||
use tokio::runtime::Runtime; | ||
|
||
use super::apply::{get_instance_id_from_state, get_instance_settings}; | ||
|
||
// Create init subcommand arguments | ||
pub fn make_subcommand() -> Command { | ||
Command::new("delete").about("Deletes database instance locally & on tembo cloud") | ||
} | ||
|
||
pub fn execute(_args: &ArgMatches) -> Result<()> { | ||
Docker::stop_remove("tembo-pg")?; | ||
let env = get_current_context()?; | ||
|
||
if env.target == Target::Docker.to_string() { | ||
Docker::stop_remove("tembo-pg")?; | ||
} else if env.target == Target::TemboCloud.to_string() { | ||
return execute_tembo_cloud(env); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn execute_tembo_cloud(env: Environment) -> Result<()> { | ||
let instance_settings: HashMap<String, InstanceSettings> = get_instance_settings()?; | ||
|
||
let profile = env.clone().selected_profile.unwrap(); | ||
let config = Configuration { | ||
base_path: profile.tembo_host, | ||
bearer_access_token: Some(profile.tembo_access_token), | ||
..Default::default() | ||
}; | ||
|
||
for (_key, value) in instance_settings.iter() { | ||
let instance_id = get_instance_id_from_state(value.instance_name.clone())?; | ||
if let Some(env_instance_id) = instance_id { | ||
let v = Runtime::new().unwrap().block_on(delete_instance( | ||
&config, | ||
env.org_id.clone().unwrap().as_str(), | ||
&env_instance_id, | ||
)); | ||
|
||
match v { | ||
Ok(result) => { | ||
println!( | ||
"Instance delete started for Instance Id: {}", | ||
result.instance_id | ||
) | ||
} | ||
Err(error) => eprintln!("Error deleting instance: {}", error), | ||
}; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cant these just be something like
const DOT_TEMBO_FOLDER: String = String::from(".tembo.io")
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, good catch. Changed it.