diff --git a/tembo-cli/src/cli/context.rs b/tembo-cli/src/cli/context.rs index 78c2e9107..611e4bec7 100644 --- a/tembo-cli/src/cli/context.rs +++ b/tembo-cli/src/cli/context.rs @@ -88,12 +88,6 @@ pub fn tembo_credentials_file_path() -> String { tembo_home_dir() + "/credentials" } -pub const DOT_TEMBO_FOLDER: &str = ".tembo"; - -pub fn tembo_state_file_path() -> String { - DOT_TEMBO_FOLDER.to_string() + "/tembo.state" -} - pub fn list_context() -> Result { let filename = tembo_context_file_path(); diff --git a/tembo-cli/src/cmd/apply.rs b/tembo-cli/src/cmd/apply.rs index 5c46d12ce..f62c7d438 100644 --- a/tembo-cli/src/cmd/apply.rs +++ b/tembo-cli/src/cmd/apply.rs @@ -1,6 +1,6 @@ use crate::{ cli::{ - context::{get_current_context, tembo_state_file_path, Environment, Target}, + context::{get_current_context, Environment, Target}, tembo_config, }, Result, @@ -8,16 +8,15 @@ use crate::{ use clap::{ArgMatches, Command}; use controller::stacks::get_stack; use controller::stacks::types::StackType as ControllerStackType; -use std::io::Write; use std::{ collections::HashMap, - fs::{self, OpenOptions}, + fs::{self}, str::FromStr, }; use temboclient::{ apis::{ configuration::Configuration, - instance_api::{create_instance, put_instance}, + instance_api::{create_instance, get_all, put_instance}, }, models::{ Cpu, CreateInstance, Extension, ExtensionInstallLocation, Memory, PgConfig, StackType, @@ -99,7 +98,7 @@ pub fn execute_tembo_cloud(env: Environment) -> Result<()> { }; for (_key, value) in instance_settings.iter() { - let instance_id = get_instance_id_from_state(value.instance_name.clone())?; + let instance_id = get_instance_id(value.instance_name.clone(), &config, env.clone())?; if let Some(env_instance_id) = instance_id { update_existing_instance(env_instance_id, value, &config, env.clone()); } else { @@ -110,18 +109,26 @@ pub fn execute_tembo_cloud(env: Environment) -> Result<()> { Ok(()) } -pub fn get_instance_id_from_state(instance_name: String) -> Result> { - let contents = fs::read_to_string(tembo_state_file_path())?; - - let tembo_state_map: HashMap = toml::from_str(&contents)?; +pub fn get_instance_id( + instance_name: String, + config: &Configuration, + env: Environment, +) -> Result> { + let v = Runtime::new() + .unwrap() + .block_on(get_all(config, env.org_id.clone().unwrap().as_str())); - let tembo_state = tembo_state_map.get(&instance_name); - if tembo_state.is_none() { - Ok(None) - } else { - let instance_id = tembo_state.unwrap().clone(); - Ok(Some(instance_id)) - } + match v { + Ok(result) => { + for instance in result.iter() { + if instance.instance_name == instance_name { + return Ok(Some(instance.clone().instance_id)); + } + } + } + Err(error) => eprintln!("Error getting instance: {}", error), + }; + Ok(None) } fn update_existing_instance( @@ -165,17 +172,6 @@ fn create_new_instance(value: &InstanceSettings, config: &Configuration, env: En "Instance creation started for instance_name: {} with instance_id: {}", result.instance_name, result.instance_id ); - - let mut state_file = OpenOptions::new() - .append(true) - .open(tembo_state_file_path()) - .expect("cannot open file"); - - let state = format!("{} = \"{}\"\n", result.instance_name, result.instance_id); - - state_file - .write_all(state.as_bytes()) - .expect("write failed"); } Err(error) => eprintln!("Error creating instance: {}", error), }; diff --git a/tembo-cli/src/cmd/delete.rs b/tembo-cli/src/cmd/delete.rs index 4cb6d853a..c38e0f75f 100644 --- a/tembo-cli/src/cmd/delete.rs +++ b/tembo-cli/src/cmd/delete.rs @@ -13,7 +13,7 @@ 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}; +use super::apply::{get_instance_id, get_instance_settings}; // Create init subcommand arguments pub fn make_subcommand() -> Command { @@ -43,11 +43,11 @@ fn execute_tembo_cloud(env: Environment) -> Result<()> { }; for (_key, value) in instance_settings.iter() { - let instance_id = get_instance_id_from_state(value.instance_name.clone())?; + let instance_id = get_instance_id(value.instance_name.clone(), &config, env.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.clone().org_id.unwrap().as_str(), &env_instance_id, )); diff --git a/tembo-cli/src/cmd/init.rs b/tembo-cli/src/cmd/init.rs index 5a160a18e..707d5e2d6 100644 --- a/tembo-cli/src/cmd/init.rs +++ b/tembo-cli/src/cmd/init.rs @@ -1,7 +1,4 @@ -use crate::{ - cli::context::{tembo_state_file_path, DOT_TEMBO_FOLDER}, - Result, -}; +use crate::Result; use clap::{ArgMatches, Command}; use crate::cli::{ @@ -69,24 +66,5 @@ pub fn execute(_args: &ArgMatches) -> Result<()> { } } - match FileUtils::create_dir(".tembo directory".to_string(), DOT_TEMBO_FOLDER.to_string()) { - Ok(t) => t, - Err(e) => { - return Err(e); - } - } - - match FileUtils::create_file( - tembo_state_file_path(), - tembo_state_file_path(), - "".to_string(), - false, - ) { - Ok(t) => t, - Err(e) => { - return Err(e); - } - } - Ok(()) } diff --git a/tembo-cli/temboclient/.openapi-generator/FILES b/tembo-cli/temboclient/.openapi-generator/FILES index 8bff6328c..fc2e8d300 100644 --- a/tembo-cli/temboclient/.openapi-generator/FILES +++ b/tembo-cli/temboclient/.openapi-generator/FILES @@ -1,5 +1,4 @@ .gitignore -.openapi-generator-ignore .travis.yml Cargo.toml README.md @@ -25,6 +24,7 @@ docs/ExtensionStatus.md docs/HeaderConfig.md docs/Infrastructure.md docs/Ingress.md +docs/IngressType.md docs/Instance.md docs/InstanceApi.md docs/InstanceEvent.md @@ -89,6 +89,7 @@ src/models/extension_status.rs src/models/header_config.rs src/models/infrastructure.rs src/models/ingress.rs +src/models/ingress_type.rs src/models/instance.rs src/models/instance_event.rs src/models/int_or_string.rs diff --git a/tembo-cli/temboclient/README.md b/tembo-cli/temboclient/README.md index ed908232c..8c8f7eebf 100644 --- a/tembo-cli/temboclient/README.md +++ b/tembo-cli/temboclient/README.md @@ -70,6 +70,7 @@ Class | Method | HTTP request | Description - [HeaderConfig](docs/HeaderConfig.md) - [Infrastructure](docs/Infrastructure.md) - [Ingress](docs/Ingress.md) + - [IngressType](docs/IngressType.md) - [Instance](docs/Instance.md) - [InstanceEvent](docs/InstanceEvent.md) - [IntOrString](docs/IntOrString.md) diff --git a/tembo-cli/temboclient/docs/IngressType.md b/tembo-cli/temboclient/docs/IngressType.md new file mode 100644 index 000000000..46e0ae6ca --- /dev/null +++ b/tembo-cli/temboclient/docs/IngressType.md @@ -0,0 +1,10 @@ +# IngressType + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/tembo-cli/temboclient/docs/Routing.md b/tembo-cli/temboclient/docs/Routing.md index 51adbf4a4..bd4ed357e 100644 --- a/tembo-cli/temboclient/docs/Routing.md +++ b/tembo-cli/temboclient/docs/Routing.md @@ -4,7 +4,9 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**entry_points** | Option<**Vec**> | | [optional] **ingress_path** | Option<**String**> | | [optional] +**ingress_type** | Option<[**crate::models::IngressType**](IngressType.md)> | | [optional] **middlewares** | Option<**Vec**> | | [optional] **port** | **i32** | | diff --git a/tembo-cli/temboclient/src/apis/instance_api.rs b/tembo-cli/temboclient/src/apis/instance_api.rs index e80bf8846..006bb767d 100644 --- a/tembo-cli/temboclient/src/apis/instance_api.rs +++ b/tembo-cli/temboclient/src/apis/instance_api.rs @@ -11,8 +11,9 @@ use reqwest; -use crate::{apis::ResponseContent, models::InstanceEvent}; +use crate::apis::ResponseContent; use super::{Error, configuration}; +use crate::models::InstanceEvent; /// struct for typed errors of method [`create_instance`] diff --git a/tembo-cli/temboclient/src/apis/stack_api.rs b/tembo-cli/temboclient/src/apis/stack_api.rs index a083a00cc..48d54db1c 100644 --- a/tembo-cli/temboclient/src/apis/stack_api.rs +++ b/tembo-cli/temboclient/src/apis/stack_api.rs @@ -15,6 +15,7 @@ use crate::apis::ResponseContent; use super::{Error, configuration}; use crate::models::StackType; + /// struct for typed errors of method [`get_all_entities`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] diff --git a/tembo-cli/temboclient/src/models/cpu.rs b/tembo-cli/temboclient/src/models/cpu.rs index c95c3f386..c3f3f2497 100644 --- a/tembo-cli/temboclient/src/models/cpu.rs +++ b/tembo-cli/temboclient/src/models/cpu.rs @@ -12,14 +12,22 @@ /// #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub enum Cpu { + #[serde(rename = "0.25")] + Variant0Period25, + #[serde(rename = "0.5")] + Variant0Period5, #[serde(rename = "1")] Variant1, #[serde(rename = "2")] Variant2, #[serde(rename = "4")] Variant4, + #[serde(rename = "6")] + Variant6, #[serde(rename = "8")] Variant8, + #[serde(rename = "12")] + Variant12, #[serde(rename = "16")] Variant16, #[serde(rename = "32")] @@ -30,10 +38,14 @@ pub enum Cpu { impl ToString for Cpu { fn to_string(&self) -> String { match self { + Self::Variant0Period25 => String::from("0.25"), + Self::Variant0Period5 => String::from("0.5"), Self::Variant1 => String::from("1"), Self::Variant2 => String::from("2"), Self::Variant4 => String::from("4"), + Self::Variant6 => String::from("6"), Self::Variant8 => String::from("8"), + Self::Variant12 => String::from("12"), Self::Variant16 => String::from("16"), Self::Variant32 => String::from("32"), } @@ -42,6 +54,10 @@ impl ToString for Cpu { impl Default for Cpu { fn default() -> Cpu { - Self::Variant1 + Self::Variant0Period25 } } + + + + diff --git a/tembo-cli/temboclient/src/models/ingress_type.rs b/tembo-cli/temboclient/src/models/ingress_type.rs new file mode 100644 index 000000000..e9055eefa --- /dev/null +++ b/tembo-cli/temboclient/src/models/ingress_type.rs @@ -0,0 +1,39 @@ +/* + * Tembo Cloud + * + * Platform API for Tembo Cloud

To find a Tembo Data API, please find it here:

[AWS US East 1](https://api.data-1.use1.tembo.io/swagger-ui/) + * + * The version of the OpenAPI document: v1.0.0 + * + * Generated by: https://openapi-generator.tech + */ + + +/// +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] +pub enum IngressType { + #[serde(rename = "http")] + Http, + #[serde(rename = "tcp")] + Tcp, + +} + +impl ToString for IngressType { + fn to_string(&self) -> String { + match self { + Self::Http => String::from("http"), + Self::Tcp => String::from("tcp"), + } + } +} + +impl Default for IngressType { + fn default() -> IngressType { + Self::Http + } +} + + + + diff --git a/tembo-cli/temboclient/src/models/instance.rs b/tembo-cli/temboclient/src/models/instance.rs index 37bc4d056..c9efceaec 100644 --- a/tembo-cli/temboclient/src/models/instance.rs +++ b/tembo-cli/temboclient/src/models/instance.rs @@ -13,8 +13,8 @@ #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Instance { - #[serde(rename = "app_services", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] - pub app_services: Option>>, + //#[serde(rename = "app_services", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] + //pub app_services: Option>>, #[serde(rename = "connection_info", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] pub connection_info: Option>>, #[serde(rename = "connection_pooler", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] @@ -64,7 +64,7 @@ pub struct Instance { impl Instance { pub fn new(cpu: crate::models::Cpu, environment: crate::models::Environment, instance_id: String, instance_name: String, memory: crate::models::Memory, organization_id: String, organization_name: String, replicas: i32, stack_type: crate::models::StackType, state: crate::models::State, storage: crate::models::Storage) -> Instance { Instance { - app_services: None, + //app_services: None, connection_info: None, connection_pooler: None, cpu, diff --git a/tembo-cli/temboclient/src/models/mod.rs b/tembo-cli/temboclient/src/models/mod.rs index 60b407a9e..e6f89eecc 100644 --- a/tembo-cli/temboclient/src/models/mod.rs +++ b/tembo-cli/temboclient/src/models/mod.rs @@ -40,6 +40,8 @@ pub mod infrastructure; pub use self::infrastructure::Infrastructure; pub mod ingress; pub use self::ingress::Ingress; +pub mod ingress_type; +pub use self::ingress_type::IngressType; pub mod instance; pub use self::instance::Instance; pub mod instance_event; diff --git a/tembo-cli/temboclient/src/models/routing.rs b/tembo-cli/temboclient/src/models/routing.rs index 84d90dcd7..71dd0ab76 100644 --- a/tembo-cli/temboclient/src/models/routing.rs +++ b/tembo-cli/temboclient/src/models/routing.rs @@ -13,8 +13,12 @@ #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Routing { + #[serde(rename = "entryPoints", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] + pub entry_points: Option>>, #[serde(rename = "ingressPath", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] pub ingress_path: Option>, + #[serde(rename = "ingressType", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] + pub ingress_type: Option>, #[serde(rename = "middlewares", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] pub middlewares: Option>>, #[serde(rename = "port")] @@ -24,7 +28,9 @@ pub struct Routing { impl Routing { pub fn new(port: i32) -> Routing { Routing { + entry_points: None, ingress_path: None, + ingress_type: None, middlewares: None, port, } diff --git a/tembo-cli/temboclient/src/models/stack_type.rs b/tembo-cli/temboclient/src/models/stack_type.rs index ed4f2303a..8b1c55713 100644 --- a/tembo-cli/temboclient/src/models/stack_type.rs +++ b/tembo-cli/temboclient/src/models/stack_type.rs @@ -26,9 +26,26 @@ pub enum StackType { VectorDb, #[serde(rename = "DataWarehouse")] DataWarehouse, + #[serde(rename = "Geospatial")] + Geospatial, } +impl ToString for StackType { + fn to_string(&self) -> String { + match self { + Self::Standard => String::from("Standard"), + Self::MessageQueue => String::from("MessageQueue"), + Self::MachineLearning => String::from("MachineLearning"), + Self::Olap => String::from("OLAP"), + Self::Oltp => String::from("OLTP"), + Self::VectorDb => String::from("VectorDB"), + Self::DataWarehouse => String::from("DataWarehouse"), + Self::Geospatial => String::from("Geospatial"), + } + } +} + impl Default for StackType { fn default() -> StackType { Self::Standard