Skip to content

Commit

Permalink
Add validation of configuration values from the tembo.toml file (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhudson authored Jan 7, 2024
1 parent 9493c52 commit 5a2196a
Show file tree
Hide file tree
Showing 6 changed files with 356 additions and 70 deletions.
61 changes: 60 additions & 1 deletion tembo-cli/Cargo.lock

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

3 changes: 2 additions & 1 deletion tembo-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
workspace = { members = ["temboclient", "tembodataclient"] }
[package]
name = "tembo-cli"
version = "0.13.4"
version = "0.13.5"
edition = "2021"
authors = ["Tembo.io"]
description = "The CLI for Tembo"
Expand Down Expand Up @@ -72,3 +72,4 @@ openssl = { version = "0.10", features = ["vendored"] }
[dev-dependencies]
assert_cmd = "2.0.8"
predicates = "2.1.5"
rstest = "0.18"
133 changes: 69 additions & 64 deletions tembo-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,85 +105,90 @@ openapi-generator generate -i https://api.tembo.io/api-docs/openapi.json -g rus
**TODO:** Find a better way to do this.

```
use std::str::FromStr;
use super::{Cpu, Storage, StackType, Memory, Environment};
use super::{Cpu, Environment, Memory, StackType, Storage};
impl FromStr for Cpu {
type Err = ();
fn from_str(input: &str) -> core::result::Result<Cpu, Self::Err> {
match input {
"1" => Ok(Cpu::Variant1),
"2" => Ok(Cpu::Variant2),
"4" => Ok(Cpu::Variant4),
"8" => Ok(Cpu::Variant8),
"16" => Ok(Cpu::Variant16),
"32" => Ok(Cpu::Variant32),
_ => Err(()),
}
}
type Err = ();
fn from_str(input: &str) -> core::result::Result<Cpu, Self::Err> {
match input {
"0.25" => Ok(Cpu::Variant0Period25),
"0.5" => Ok(Cpu::Variant0Period5),
"1" => Ok(Cpu::Variant1),
"2" => Ok(Cpu::Variant2),
"4" => Ok(Cpu::Variant4),
"8" => Ok(Cpu::Variant8),
"16" => Ok(Cpu::Variant16),
"32" => Ok(Cpu::Variant32),
_ => Err(()),
}
}
}
impl FromStr for Memory {
type Err = ();
fn from_str(input: &str) -> core::result::Result<Memory, Self::Err> {
match input {
"1Gi" => Ok(Memory::Variant1Gi),
"2Gi" => Ok(Memory::Variant2Gi),
"4Gi" => Ok(Memory::Variant4Gi),
"8Gi" => Ok(Memory::Variant8Gi),
"16Gi" => Ok(Memory::Variant16Gi),
"32Gi" => Ok(Memory::Variant32Gi),
_ => Err(()),
}
}
type Err = ();
fn from_str(input: &str) -> core::result::Result<Memory, Self::Err> {
match input {
"1Gi" => Ok(Memory::Variant1Gi),
"2Gi" => Ok(Memory::Variant2Gi),
"4Gi" => Ok(Memory::Variant4Gi),
"8Gi" => Ok(Memory::Variant8Gi),
"16Gi" => Ok(Memory::Variant16Gi),
"32Gi" => Ok(Memory::Variant32Gi),
_ => Err(()),
}
}
}
impl FromStr for Environment {
type Err = ();
fn from_str(input: &str) -> core::result::Result<Environment, Self::Err> {
match input {
"dev" => Ok(Environment::Dev),
"test" => Ok(Environment::Test),
"prod" => Ok(Environment::Prod),
_ => Err(()),
}
}
type Err = ();
fn from_str(input: &str) -> core::result::Result<Environment, Self::Err> {
match input {
"dev" => Ok(Environment::Dev),
"test" => Ok(Environment::Test),
"prod" => Ok(Environment::Prod),
_ => Err(()),
}
}
}
impl FromStr for Storage {
type Err = ();
fn from_str(input: &str) -> core::result::Result<Storage, Self::Err> {
match input {
"10Gi" => Ok(Storage::Variant10Gi),
"50Gi" => Ok(Storage::Variant50Gi),
"100Gi" => Ok(Storage::Variant100Gi),
"200Gi" => Ok(Storage::Variant200Gi),
"300Gi" => Ok(Storage::Variant300Gi),
"400Gi" => Ok(Storage::Variant400Gi),
"500Gi" => Ok(Self::Variant500Gi),
_ => Err(()),
}
}
type Err = ();
fn from_str(input: &str) -> core::result::Result<Storage, Self::Err> {
match input {
"10Gi" => Ok(Storage::Variant10Gi),
"50Gi" => Ok(Storage::Variant50Gi),
"100Gi" => Ok(Storage::Variant100Gi),
"200Gi" => Ok(Storage::Variant200Gi),
"300Gi" => Ok(Storage::Variant300Gi),
"400Gi" => Ok(Storage::Variant400Gi),
"500Gi" => Ok(Self::Variant500Gi),
_ => Err(()),
}
}
}
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"),
}
}
impl FromStr for StackType {
type Err = ();
fn from_str(input: &str) -> core::result::Result<StackType, Self::Err> {
match input {
"Standard" => Ok(StackType::Standard),
"MessageQueue" => Ok(StackType::MessageQueue),
"MachineLearning" => Ok(StackType::MachineLearning),
"OLAP" => Ok(StackType::Olap),
"VectorDB" => Ok(StackType::VectorDb),
"OLTP" => Ok(StackType::Oltp),
"DataWarehouse" => Ok(StackType::DataWarehouse),
"Geospatial" => Ok(StackType::Geospatial),
_ => Err(()),
}
}
}
```

Expand Down
4 changes: 2 additions & 2 deletions tembo-cli/src/cli/tembo_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ fn default_cpu() -> String {
}

fn default_memory() -> String {
"1GiB".to_string()
"1Gi".to_string()
}

fn default_storage() -> String {
"10GiB".to_string()
"10Gi".to_string()
}

fn default_replicas() -> i32 {
Expand Down
Loading

0 comments on commit 5a2196a

Please sign in to comment.