diff --git a/README.md b/README.md index b00bfa6..cb35f01 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,8 @@ Event watches flush text or JSON output as messages arrive and reconnect after e `brainpod cluster list` lists active clusters and their supported architectures. +`brainpod storage providers` lists the installation's object storage providers (`KEY NAME REGIONS`; `--json` returns the array). A Bucket resource's `spec.provider` is a provider key and `spec.region` one of that provider's regions; `brainpod describe resource bucket` repeats this in its `notes`. + `brainpod agent` maintains a session console: a page an agent puts in front of the user so a deploy is something they watch rather than sit through. `agent start` writes `console.html` and `session.json` into a directory of their own under `.brainpod/` at the repository root, adds `.brainpod/` to `.gitignore` unless `--no-ignore` is passed, and prints the page to open. The page reads `session.json` and `session.log` from its own directory and needs no server. Where `agent serve` is running it advertises an event stream in the session, and the page upgrades from polling to push; if that stream drops it falls back to polling, so the two paths run the same code. Every write replaces the file through a temporary rename, so the page never reads a partial write. Which of the two ways to open the page works depends on the browser. An agent's embedded browser will only execute a local page from inside the project, so it opens `console.html` directly. A browser outside the agent will display that page but never populate it, because reading a file from the same directory is blocked on `file://`. For those, `agent serve` publishes the console over loopback instead, which puts the page and its session on one origin. It announces the URL on stdout and then blocks, so run it in the background and read the first line; the URL carries a random path because loopback is reachable by anything else on the machine. diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index ae6c968..3682919 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -29,6 +29,8 @@ pub enum Command { Whoami, /// List available clusters Cluster(ClusterArgs), + /// List object storage providers and regions for Bucket resources + Storage(StorageArgs), /// Inspect pods Pod(PodArgs), /// Browse and install blueprints @@ -117,6 +119,18 @@ enum ClusterCommand { List, } +#[derive(Debug, Args)] +pub struct StorageArgs { + #[command(subcommand)] + command: StorageCommand, +} + +#[derive(Debug, Subcommand)] +enum StorageCommand { + /// List storage providers and their regions; a Bucket's spec.provider is a KEY and spec.region one of its REGIONS + Providers, +} + #[derive(Debug, Args)] pub struct PodArgs { #[command(subcommand)] @@ -581,6 +595,7 @@ pub async fn handle(command: Command, context: CommandContext<'_>) -> Result handle_cluster(client_required(client)?, args).await, + Command::Storage(args) => handle_storage(client_required(client)?, args).await, Command::Pod(args) => handle_pod(client_required(client)?, args).await, Command::Tunnel(args) => { crate::tunnel::handle( @@ -670,6 +685,15 @@ async fn handle_cluster(client: &Client, args: ClusterArgs) -> Result Result { + match args.command { + StorageCommand::Providers => Ok(CommandOutput::new( + client.get(&["v1", "storage", "providers"], &[]).await?, + View::StorageProviderList, + )), + } +} + fn handle_config(args: ConfigArgs, config: &mut Config, path: &Path) -> Result { match args.command { ConfigCommand::Show => Ok(CommandOutput::new( diff --git a/src/describe.rs b/src/describe.rs index fd451cd..42a9e60 100644 --- a/src/describe.rs +++ b/src/describe.rs @@ -251,9 +251,14 @@ fn requirements(path: &[&str]) -> (Option, Option) { } ["blueprint"] => (Some(true), None), ["blueprint", "install"] => (Some(true), Some(true)), - ["blueprint", _] | ["whoami"] | ["cluster"] | ["cluster", _] | ["pod"] | ["pod", _] => { - (Some(true), Some(false)) - } + ["blueprint", _] + | ["whoami"] + | ["cluster"] + | ["cluster", _] + | ["storage"] + | ["storage", _] + | ["pod"] + | ["pod", _] => (Some(true), Some(false)), ["s3"] | ["s3", _] => (Some(true), Some(true)), ["image"] | ["image", _] @@ -288,6 +293,7 @@ fn effect(path: &[&str]) -> (&'static str, &'static str) { ), ["whoami"] | ["cluster", "list"] + | ["storage", "providers"] | ["pod", "list"] | ["pod", "get"] | ["blueprint", "list"] @@ -362,6 +368,7 @@ fn next_steps(path: &[&str]) -> Vec<&'static str> { "Inspect the updated draft with `brainpod resource list`.", "Read the references other resources can use with `brainpod resource variables`.", "Discover the variables a kind exports before creating it with `brainpod describe resource `; it needs no pod and no API token.", + "Choose a Bucket's spec.provider and spec.region from `brainpod storage providers`.", "Deploy it with `brainpod deploy` when ready.", ], ["resource", "list"] | ["resource", "get"] => vec![ diff --git a/src/main.rs b/src/main.rs index 86992a0..43908c1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -466,6 +466,14 @@ mod tests { ); } + #[test] + fn parses_storage_providers() { + let opts = Opts::try_parse_from(["brainpod", "storage", "providers"]).unwrap(); + + assert!(matches!(opts.command, Command::Storage(_))); + assert!(super::cmd::needs_client(&opts.command)); + } + #[test] fn parses_cluster_list() { let opts = Opts::try_parse_from(["brainpod", "cluster", "list"]).unwrap(); diff --git a/src/openapi.json b/src/openapi.json index 2d52ba8..06e1ec7 100644 --- a/src/openapi.json +++ b/src/openapi.json @@ -1 +1 @@ -{"openapi":"3.1.0","info":{"title":"Brainpod API","description":"Manage Brainpod pods with API keys. Policy resource `urn:brain:pod:*` matches all current and future pods accessible to the key owner, excluding the public registry namespace. Error responses include a stable code and request ID for automated recovery and support correlation.","version":"1.0.0"},"tags":[{"name":"users","description":"Current API user"},{"name":"pods","description":"Pod discovery and details"},{"name":"blueprints","description":"Installable application stacks"},{"name":"clusters","description":"Available Kubernetes clusters"},{"name":"revisions","description":"Revision history and deployment"},{"name":"resources","description":"Pod resource configuration"},{"name":"events","description":"Pod logs and runtime events"},{"name":"images","description":"Container image discovery and metadata"}],"components":{"schemas":{"ErrorResponse":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"enum":["BAD_REQUEST","VALIDATION_ERROR","UNAUTHORIZED","FORBIDDEN","NOT_FOUND","PRECONDITION_FAILED","RATE_LIMITED","REQUEST_TOO_LARGE","REQUEST_TIMEOUT","SERVICE_UNAVAILABLE","INTERNAL_ERROR"],"type":"string"},"message":{"type":"string"},"requestId":{"type":"string"},"details":{"type":"array","items":{"type":"object","properties":{"path":{"type":"string"},"message":{"type":"string"}},"required":["path","message"]}}},"required":["code","message","requestId"]}},"required":["error"],"$schema":"https://json-schema.org/draft/2020-12/schema"},"User":{"type":"object","properties":{"email":{"anyOf":[{"type":"string"},{"type":"null"}]},"policy":{"anyOf":[{"type":"object","properties":{"version":{"const":"1"},"statements":{"type":"array","items":{"type":"object","properties":{"sid":{"type":"string","minLength":1},"effect":{"enum":["allow","deny"],"type":"string"},"actions":{"type":"array","items":{"type":"string","pattern":"^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*$"},"minItems":1},"resources":{"type":"array","items":{"type":"string"},"minItems":1},"conditions":{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"anyOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]}}},"required":["sid","effect","actions","resources"]},"minItems":1}},"required":["version","statements"]},{"type":"null"}]},"permissions":{"type":"array","items":{"type":"object","properties":{"action":{"type":"string"},"resources":{"type":"array","items":{"type":"string"}},"excludedResources":{"type":"array","items":{"type":"string"}}},"required":["action","resources","excludedResources"]}},"_links":{"type":"object","properties":{"self":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},"pods":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},"blueprints":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},"clusters":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]}},"required":["self","pods","blueprints","clusters"]}},"required":["email","policy","permissions","_links"],"$schema":"https://json-schema.org/draft/2020-12/schema"},"Cluster":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"provider":{"anyOf":[{"type":"string"},{"type":"null"}]},"region":{"anyOf":[{"type":"string"},{"type":"null"}]},"architectures":{"type":"array","items":{"type":"string"}}},"required":["id","provider","region","architectures"],"$schema":"https://json-schema.org/draft/2020-12/schema"},"Revision":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"parent":{"anyOf":[{"type":"string","format":"uuid"},{"type":"null"}]},"version":{"type":"number"},"state":{"enum":["draft","canceled","pending","ready","deployed","failed"],"type":"string"},"summary":{"anyOf":[{"type":"string"},{"type":"null"}]},"error":{"anyOf":[{"type":"string"},{"type":"null"}]},"isLatest":{"type":"boolean"},"isDeployed":{"type":"boolean"},"createdAt":{"type":"string","format":"date-time"},"_links":{"type":"object","properties":{"self":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},"pod":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},"resources":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]}},"required":["self","pod","resources"]}},"required":["id","parent","version","state","summary","error","isLatest","isDeployed","createdAt","_links"],"$schema":"https://json-schema.org/draft/2020-12/schema"},"RevisionList":{"type":"object","properties":{"items":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"parent":{"anyOf":[{"type":"string","format":"uuid"},{"type":"null"}]},"version":{"type":"number"},"state":{"enum":["draft","canceled","pending","ready","deployed","failed"],"type":"string"},"summary":{"anyOf":[{"type":"string"},{"type":"null"}]},"error":{"anyOf":[{"type":"string"},{"type":"null"}]},"isLatest":{"type":"boolean"},"isDeployed":{"type":"boolean"},"createdAt":{"type":"string","format":"date-time"},"_links":{"type":"object","properties":{"self":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},"pod":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},"resources":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]}},"required":["self","pod","resources"]}},"required":["id","parent","version","state","summary","error","isLatest","isDeployed","createdAt","_links"]}},"_links":{"type":"object","properties":{"self":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},"next":{"anyOf":[{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},{"type":"null"}]}},"required":["self","next"]}},"required":["items","_links"],"$schema":"https://json-schema.org/draft/2020-12/schema"},"RevisionDetail":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"parent":{"anyOf":[{"type":"string","format":"uuid"},{"type":"null"}]},"version":{"type":"number"},"state":{"enum":["draft","canceled","pending","ready","deployed","failed"],"type":"string"},"summary":{"anyOf":[{"type":"string"},{"type":"null"}]},"error":{"anyOf":[{"type":"string"},{"type":"null"}]},"isLatest":{"type":"boolean"},"isDeployed":{"type":"boolean"},"createdAt":{"type":"string","format":"date-time"},"_links":{"type":"object","properties":{"self":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},"pod":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},"resources":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]}},"required":["self","pod","resources"]},"checksum":{"anyOf":[{"type":"string"},{"type":"null"}]},"resources":{"type":"array","items":{"type":"object","properties":{"urn":{"type":"string"},"content":{"oneOf":[{"type":"object","properties":{"apiVersion":{"const":"pod.brainpod.io/v1alpha1"},"kind":{"const":"App"},"metadata":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":63},"namespace":{"const":"default"}},"required":["name","namespace"]},"spec":{"type":"object","properties":{"image":{"type":"string","pattern":"^(?:(?=[^:\\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?.host}","secret":false,"description":"Public hostname the route serves on: the first custom domain, otherwise the generated hostname."}]},{"type":"object","properties":{"apiVersion":{"enum":["pod.brainpod.io/v1alpha1","pod.brainpod.io/v1alpha2"],"type":"string"},"kind":{"const":"Postgres"},"metadata":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":63},"namespace":{"const":"default"}},"required":["name","namespace"]},"spec":{"type":"object","properties":{"version":{"type":"string","enum":["16","17","18"]},"instance":{"enum":[".5x","1x","2x","4x","8x"],"type":"string","minLength":1},"diskRef":{"type":"string"}},"required":["version","instance","diskRef"]}},"required":["apiVersion","kind","metadata","spec"],"x-brainpod-variables":[{"name":"user","ref":"${.user}","secret":false,"description":"Database user the instance is provisioned with."},{"name":"database","ref":"${.database}","secret":false,"description":"Name of the database created on the instance."},{"name":"password","ref":"${.password}","secret":true,"description":"Password for the database user. Generated in-cluster and revealed only through an authorized database tunnel."},{"name":"uri","ref":"${.uri}","secret":true,"template":"postgres://${.user}:${.password}@${.host}:5432/brainpod?sslmode=require","description":"Full connection string. Secret: embeds the generated password."},{"name":"host","ref":"${.host}","secret":false,"template":".default.pod.internal","description":"Cluster-internal hostname of the database."},{"name":"port","ref":"${.port}","secret":false,"description":"Port the database listens on."}]},{"type":"object","properties":{"apiVersion":{"enum":["pod.brainpod.io/v1alpha1","pod.brainpod.io/v1alpha2"],"type":"string"},"kind":{"const":"MariaDB"},"metadata":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":63},"namespace":{"const":"default"}},"required":["name","namespace"]},"spec":{"type":"object","properties":{"version":{"type":"string","enum":["11"]},"instance":{"enum":[".5x","1x","2x","4x","8x"],"type":"string","minLength":1},"diskRef":{"type":"string"}},"required":["version","instance","diskRef"]}},"required":["apiVersion","kind","metadata","spec"],"x-brainpod-variables":[{"name":"user","ref":"${.user}","secret":false,"description":"Database user the instance is provisioned with."},{"name":"database","ref":"${.database}","secret":false,"description":"Name of the database created on the instance."},{"name":"password","ref":"${.password}","secret":true,"description":"Password for the database user. Generated in-cluster and revealed only through an authorized database tunnel."},{"name":"uri","ref":"${.uri}","secret":true,"template":"mysql://${.user}:${.password}@${.host}:3306/brainpod","description":"Full connection string. Secret: embeds the generated password."},{"name":"host","ref":"${.host}","secret":false,"template":".default.pod.internal","description":"Cluster-internal hostname of the database."},{"name":"port","ref":"${.port}","secret":false,"description":"Port the database listens on."}]},{"type":"object","properties":{"apiVersion":{"const":"pod.brainpod.io/v1alpha1"},"kind":{"const":"Disk"},"metadata":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":63},"namespace":{"const":"default"}},"required":["name","namespace"]},"spec":{"type":"object","properties":{"size":{"anyOf":[{"type":"string"},{"type":"number"}],"type":"integer","minimum":5,"maximum":500},"volumeHandle":{"type":"string"}},"required":["size"]}},"required":["apiVersion","kind","metadata","spec"],"x-brainpod-variables":[]},{"type":"object","properties":{"apiVersion":{"const":"pod.brainpod.io/v1alpha1"},"kind":{"const":"Bucket"},"metadata":{"type":"object","properties":{"name":{"type":"string","minLength":3,"maxLength":63,"pattern":"^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$"},"namespace":{"const":"default"}},"required":["name","namespace"]},"spec":{"type":"object","properties":{"provider":{"type":"string","minLength":1,"maxLength":63,"pattern":"^[a-z0-9]+(?:-[a-z0-9]+)*$"},"region":{"type":"string","minLength":1,"maxLength":63,"pattern":"^[a-z0-9]+(?:-[a-z0-9]+)*$"}},"required":["provider","region"]}},"required":["apiVersion","kind","metadata","spec"],"x-brainpod-variables":[{"name":"accessKeyId","ref":"${s3..accessKeyId}","secret":true,"description":"Bucket-scoped S3 workload access key"},{"name":"secretAccessKey","ref":"${s3..secretAccessKey}","secret":true,"description":"Bucket-scoped S3 workload signing secret"},{"name":"bucketName","ref":"${s3..bucketName}","secret":true,"description":"Physical provider bucket name"},{"name":"endpoint","ref":"${s3..endpoint}","secret":true,"description":"Direct S3 provider endpoint"},{"name":"region","ref":"${s3..region}","secret":true,"description":"S3 provider region"}]},{"type":"object","properties":{"apiVersion":{"const":"pod.brainpod.io/v1alpha1"},"kind":{"const":"Valkey"},"metadata":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":63},"namespace":{"const":"default"}},"required":["name","namespace"]},"spec":{"type":"object","properties":{"version":{"type":"string","enum":["9"]},"instance":{"enum":[".5x","1x","2x","4x","8x"],"type":"string","minLength":1},"diskRef":{"type":"string"}},"required":["version","instance","diskRef"]}},"required":["apiVersion","kind","metadata","spec"],"x-brainpod-variables":[{"name":"password","ref":"${.password}","secret":true,"description":"Password guarding the instance. Generated in-cluster and revealed only through an authorized database tunnel."},{"name":"uri","ref":"${.uri}","secret":true,"template":"rediss://:${.password}@${.host}:6379","description":"Full connection string. Secret: embeds the generated password."},{"name":"host","ref":"${.host}","secret":false,"template":".default.pod.internal","description":"Cluster-internal hostname of the instance."},{"name":"port","ref":"${.port}","secret":false,"description":"Port the instance listens on."}]},{"type":"object","properties":{"apiVersion":{"const":"pod.brainpod.io/v1alpha1"},"kind":{"const":"MSSQL"},"metadata":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":63},"namespace":{"const":"default"}},"required":["name","namespace"]},"spec":{"type":"object","properties":{"version":{"type":"string","enum":["2022","2025"]},"edition":{"const":"express"},"instance":{"enum":["2x","4x","8x"],"type":"string","minLength":1},"diskRef":{"type":"string"}},"required":["version","edition","instance","diskRef"]}},"required":["apiVersion","kind","metadata","spec"],"x-brainpod-variables":[{"name":"user","ref":"${.user}","secret":false,"description":"Database user the instance is provisioned with."},{"name":"database","ref":"${.database}","secret":false,"description":"Name of the database created on the instance."},{"name":"password","ref":"${.password}","secret":true,"description":"Password for the database user. Generated in-cluster and revealed only through an authorized database tunnel."},{"name":"uri","ref":"${.uri}","secret":true,"template":"sqlserver://${.user}:${.password}@${.host}:1433?database=brainpod&encrypt=true&trustServerCertificate=true","description":"Full connection string. Secret: embeds the generated password."},{"name":"host","ref":"${.host}","secret":false,"template":".default.pod.internal","description":"Cluster-internal hostname of the database."},{"name":"port","ref":"${.port}","secret":false,"description":"Port the database listens on."}]}],"$schema":"https://json-schema.org/draft/2020-12/schema"},"Variable":{"type":"object","properties":{"name":{"type":"string"},"ref":{"type":"string"},"secret":{"type":"boolean"},"resolved":{"type":"boolean"},"value":{"anyOf":[{"type":"string"},{"type":"null"}]},"template":{"type":"string"},"description":{"type":"string"}},"required":["name","ref","secret","resolved","value","description"],"$schema":"https://json-schema.org/draft/2020-12/schema"},"VariableList":{"type":"object","properties":{"items":{"type":"array","items":{"type":"object","properties":{"urn":{"type":"string"},"name":{"type":"string"},"ref":{"type":"string"},"secret":{"type":"boolean"},"resolved":{"type":"boolean"},"value":{"anyOf":[{"type":"string"},{"type":"null"}]},"template":{"type":"string"},"description":{"type":"string"}},"required":["urn","name","ref","secret","resolved","value","description"]}},"_links":{"type":"object","properties":{"self":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},"pod":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]},"resources":{"type":"object","properties":{"href":{"type":"string"}},"required":["href"]}},"required":["self","pod","resources"]}},"required":["items","_links"],"$schema":"https://json-schema.org/draft/2020-12/schema"},"ResourceReplacement":{"oneOf":[{"type":"object","properties":{"apiVersion":{"const":"pod.brainpod.io/v1alpha1"},"kind":{"const":"App"},"metadata":{"type":"object","properties":{"name":{"type":"string","minLength":1,"maxLength":63},"namespace":{"const":"default"}},"required":["name","namespace"]},"spec":{"type":"object","properties":{"image":{"type":"string","pattern":"^(?:(?=[^:\\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?) -> Result "sourceUrl": url, "schema": resource.schema, "variables": resource.variables, + "notes": resource_notes(&resource.kind), })); } @@ -59,6 +60,7 @@ pub async fn describe(path: &[String], endpoint: Option<&str>) -> Result "kind": resource.kind, "schema": resource.schema, "variables": resource.variables, + "notes": resource_notes(&resource.kind), })).collect::>(), })) } @@ -127,6 +129,17 @@ struct ResourceCatalog { variables: Value, } +/// Guidance for fields whose valid values are installation data rather than schema enums. +fn resource_notes(kind: &str) -> Vec<&'static str> { + if kind.eq_ignore_ascii_case("Bucket") { + vec![ + "spec.provider must be a provider `key` and spec.region one of that provider's `regions` from `brainpod storage providers`.", + ] + } else { + Vec::new() + } +} + fn resource_schemas(spec: &Value) -> Result> { let branches = spec .pointer("/components/schemas/ResourceInput/oneOf") @@ -167,7 +180,25 @@ fn resource_schemas(spec: &Value) -> Result> { mod tests { use serde_json::{Value, json}; - use super::{is_resource_path, resource_schemas}; + use super::{EMBEDDED_OPENAPI, is_resource_path, resource_notes, resource_schemas}; + + #[test] + fn embedded_fallback_describes_bucket() { + let spec: Value = serde_json::from_str(EMBEDDED_OPENAPI).unwrap(); + let resources = resource_schemas(&spec).unwrap(); + + assert!(resources.iter().any(|resource| resource.kind == "Bucket")); + } + + #[test] + fn points_bucket_provider_and_region_at_storage_providers() { + assert!( + resource_notes("Bucket") + .iter() + .any(|note| note.contains("brainpod storage providers")) + ); + assert!(resource_notes("App").is_empty()); + } #[test] fn recognizes_resource_schema_paths_without_shadowing_commands() { diff --git a/src/output.rs b/src/output.rs index 30854eb..a10ea2b 100644 --- a/src/output.rs +++ b/src/output.rs @@ -37,6 +37,7 @@ pub enum View { ConfigChange, Whoami, ClusterList, + StorageProviderList, PodList, PodCreated, PodGet, @@ -179,6 +180,7 @@ fn render(value: &Value, view: View, color: bool) -> Vec { View::ConfigChange => render_config_change(value), View::Whoami => render_whoami(value), View::ClusterList => render_cluster_list(value), + View::StorageProviderList => render_storage_provider_list(value), View::PodList => render_pod_list(value), View::PodCreated => { let mut lines = vec!["Pod created".to_owned(), String::new()]; @@ -341,6 +343,15 @@ fn render_resource_schema(value: &Value) -> Vec { render_schema_properties(value.get("schema"), 2, 0, &mut lines); lines.push(String::new()); lines.extend(render_variable_catalog(value.get("variables"))); + if let Some(notes) = value + .get("notes") + .and_then(Value::as_array) + .filter(|notes| !notes.is_empty()) + { + lines.push(String::new()); + lines.push("Notes".to_owned()); + lines.extend(notes.iter().map(|note| format!(" {}", scalar(note)))); + } lines } @@ -680,6 +691,27 @@ fn render_cluster_list(value: &Value) -> Vec { table(&["ID", "PROVIDER", "REGION", "ARCHITECTURES"], rows) } +fn render_storage_provider_list(value: &Value) -> Vec { + let Some(providers) = value.as_array() else { + return vec!["No storage providers returned.".to_owned()]; + }; + if providers.is_empty() { + return vec!["No storage providers.".to_owned()]; + } + + let rows = providers + .iter() + .map(|provider| { + vec![ + field(provider, "key"), + field(provider, "name"), + string_list(provider.get("regions")), + ] + }) + .collect(); + table(&["KEY", "NAME", "REGIONS"], rows) +} + fn render_pod_list(value: &Value) -> Vec { let Some(pods) = value.as_array() else { return vec!["No pods returned.".to_owned()]; @@ -1430,8 +1462,8 @@ mod tests { use super::{ render_cluster_list, render_event, render_image_inspect, render_image_list, - render_resource_schema, render_resource_variables, render_whoami, stream_error, - write_login_json, write_stream_json, + render_resource_schema, render_resource_variables, render_storage_provider_list, + render_whoami, stream_error, write_login_json, write_stream_json, }; #[test] @@ -1497,6 +1529,22 @@ mod tests { assert!(lines.iter().any(|line| line.contains("amd64, arm64"))); } + #[test] + fn renders_storage_provider_list() { + let lines = render_storage_provider_list(&json!([ + {"key": "exoscale", "name": "Exoscale", "regions": ["ch-gva-2", "de-fra-1"]} + ])); + + assert!(lines[0].contains("KEY") && lines[0].contains("REGIONS")); + assert!(lines.iter().any(|line: &String| line.contains("exoscale") + && line.contains("Exoscale") + && line.contains("ch-gva-2, de-fra-1"))); + assert_eq!( + render_storage_provider_list(&json!([])), + vec!["No storage providers.".to_owned()] + ); + } + #[test] fn renders_platform_event() { let event = json!({