Validate a GCP region/location value. Accepts the special keywords `global`, `us`, and `eu`, plus standard regional patterns like `us-central1`, `europe-west4`, `us-east4-a`.
(value: &str)
| 340 | /// Accepts the special keywords `global`, `us`, and `eu`, plus standard |
| 341 | /// regional patterns like `us-central1`, `europe-west4`, `us-east4-a`. |
| 342 | fn validate_gcp_region(value: &str) -> Result<(), Status> { |
| 343 | let lower = value.trim().to_ascii_lowercase(); |
| 344 | let valid = matches!(lower.as_str(), "global" | "us" | "eu") |
| 345 | || (lower |
| 346 | .chars() |
| 347 | .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-') |
| 348 | && lower.contains('-') |
| 349 | && !lower.starts_with('-') |
| 350 | && !lower.ends_with('-')); |
| 351 | if valid { |
| 352 | Ok(()) |
| 353 | } else { |
| 354 | Err(Status::invalid_argument(format!( |
| 355 | "VERTEX_AI_REGION has invalid format: {value:?}. \ |
| 356 | Expected a GCP region (e.g. us-central1, europe-west4) \ |
| 357 | or one of: global, us, eu." |
| 358 | ))) |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | /// Resolve the Vertex AI API host and normalized location from a configured region. |
| 363 | fn vertex_location_and_host(region: &str) -> (String, String) { |
no outgoing calls
no test coverage detected