diff --git a/endpoints/src/backend.rs b/endpoints/src/backend.rs index b229fc19..683e80f4 100644 --- a/endpoints/src/backend.rs +++ b/endpoints/src/backend.rs @@ -6,6 +6,7 @@ pub const ORB_BACKEND_ENV_VAR_NAME: &str = "ORB_BACKEND"; pub enum Backend { Prod, Staging, + Analysis, } impl Backend { @@ -50,6 +51,9 @@ impl Backend { if b == Backend::Prod && IS_STAGE_BUILD { panic!("tried to talk to prod backend but this is a staging build!"); } + if b == Backend::Analysis && IS_STAGE_BUILD { + panic!("tried to talk to analysis backend but this is a staging build!"); + } b } } @@ -61,6 +65,7 @@ impl FromStr for Backend { match s.trim().to_lowercase().as_str() { "prod" | "production" => Ok(Self::Prod), "stage" | "staging" | "dev" | "development" => Ok(Self::Staging), + "analysis" | "analysis.ml" | "analysis-ml" => Ok(Self::Analysis), _ => Err(BackendParseErr), } } @@ -126,6 +131,7 @@ mod test { assert_eq!(Backend::from_str("stage").unwrap(), Backend::Staging); assert_eq!(Backend::from_str("staGe").unwrap(), Backend::Staging); assert_eq!(Backend::from_str("dev").unwrap(), Backend::Staging); + assert_eq!(Backend::from_str("analysis").unwrap(), Backend::Analysis); assert_eq!(Backend::from_str("foobar"), Err(BackendParseErr)); } } diff --git a/endpoints/src/endpoints.rs b/endpoints/src/endpoints.rs index aaa1ed34..2575bade 100644 --- a/endpoints/src/endpoints.rs +++ b/endpoints/src/endpoints.rs @@ -18,9 +18,10 @@ impl Endpoints { /// # Errors /// Errors if the `orb_id` would result in an invalid URL. pub fn new(backend: Backend, orb_id: &OrbId) -> Self { - let maybe_stage = match backend { - Backend::Prod => "", - Backend::Staging => "stage.", + let subdomain = match backend { + Backend::Prod => "orb", + Backend::Staging => "stage.orb", + Backend::Analysis => "analysis.ml", }; /// Safer way to assemble URLs involving `OrbId` @@ -33,20 +34,16 @@ impl Endpoints { Self { ai_volume: concat_urls( - &format!( - "https://management.{maybe_stage}orb.worldcoin.org/api/v1/orbs/" - ), + &format!("https://management.{subdomain}.worldcoin.org/api/v1/orbs/"), orb_id, "keys/aivolume", ), auth: Url::parse(&format!( - "https://auth.{maybe_stage}orb.worldcoin.org/api/v1/" + "https://auth.{subdomain}.worldcoin.org/api/v1/" )) .expect("urls with validated orb ids should always parse"), ping: concat_urls( - &format!( - "https://management.{maybe_stage}orb.worldcoin.org/api/v1/orbs/" - ), + &format!("https://management.{subdomain}.worldcoin.org/api/v1/orbs/"), orb_id, "", ), @@ -62,6 +59,7 @@ mod test { fn test_config() { let stage = Endpoints::new(Backend::Staging, &"ea2ea744".parse().unwrap()); let prod = Endpoints::new(Backend::Prod, &"ea2ea744".parse().unwrap()); + let analysis = Endpoints::new(Backend::Analysis, &"ea2ea744".parse().unwrap()); assert_eq!( stage.ai_volume.as_str(), @@ -71,12 +69,20 @@ mod test { prod.ai_volume.as_str(), "https://management.orb.worldcoin.org/api/v1/orbs/ea2ea744/keys/aivolume" ); + assert_eq!( + analysis.ai_volume.as_str(), + "https://management.analysis.ml.worldcoin.org/api/v1/orbs/ea2ea744/keys/aivolume" + ); assert_eq!( stage.auth.as_str(), "https://auth.stage.orb.worldcoin.org/api/v1/" ); assert_eq!(prod.auth.as_str(), "https://auth.orb.worldcoin.org/api/v1/"); + assert_eq!( + analysis.auth.as_str(), + "https://auth.analysis.ml.worldcoin.org/api/v1/" + ); assert_eq!( stage.ping.as_str(), @@ -86,5 +92,9 @@ mod test { prod.ping.as_str(), "https://management.orb.worldcoin.org/api/v1/orbs/ea2ea744/" ); + assert_eq!( + analysis.ping.as_str(), + "https://management.analysis.ml.worldcoin.org/api/v1/orbs/ea2ea744/" + ); } }