@@ -145,7 +145,8 @@ async fn main() -> std::io::Result<()> {
145145 let secret = app_config. keycloak_secret . clone ( ) ;
146146 let superposition_token = app_config. superposition_token . clone ( ) . unwrap_or_default ( ) ;
147147
148- let cac_url = app_config. superposition_url . clone ( ) ;
148+ let dashboard_superposition_url = app_config. superposition_url . clone ( ) ;
149+ let rc_superposition_url = app_config. superposition_rc_url . clone ( ) ;
149150 let superposition_org_id_env = app_config. superposition_org_id . clone ( ) ;
150151
151152 let env = types:: Environment {
@@ -202,44 +203,73 @@ async fn main() -> std::io::Result<()> {
202203 hub = Some ( Sheets :: new ( client, gcp_auth) ) ;
203204 }
204205
205- let superposition_client = if app_config. enable_authenticated_superposition {
206- let superposition_user_token = app_config. superposition_user_token . clone ( ) . expect (
207- "SUPERPOSITION_USER_TOKEN must be set when ENABLE_AUTHENTICATED_SUPERPOSITION=true" ,
208- ) ;
209- let superposition_org_token = app_config. superposition_org_token . clone ( ) . expect (
210- "SUPERPOSITION_ORG_TOKEN must be set when ENABLE_AUTHENTICATED_SUPERPOSITION=true" ,
211- ) ;
212-
213- // Inject Auth cookie for Superposition SDK calls
214- let cookie_interceptor = CookieIntercept :: new ( format ! (
215- "user={}; org_{}={}" ,
216- superposition_user_token, superposition_org_id_env, superposition_org_token,
217- ) ) ;
218-
219- superposition_sdk:: Client :: from_conf (
220- SrsConfig :: builder ( )
221- . endpoint_url ( cac_url. clone ( ) )
222- . behavior_version_latest ( )
223- . bearer_token ( superposition_token. into ( ) )
224- . interceptor ( cookie_interceptor)
225- . build ( ) ,
226- )
227- } else {
228- superposition_sdk:: Client :: from_conf (
229- SrsConfig :: builder ( )
230- . endpoint_url ( cac_url. clone ( ) )
231- . behavior_version_latest ( )
232- . bearer_token ( superposition_token. into ( ) )
233- . build ( ) ,
234- )
235- } ;
206+ let create_superposition_client =
207+ |endpoint_url : String ,
208+ user_token : Option < String > ,
209+ org_token : Option < String > ,
210+ user_token_env_hint : & str ,
211+ org_token_env_hint : & str | {
212+ if app_config. enable_authenticated_superposition {
213+ let superposition_user_token = user_token. unwrap_or_else ( || {
214+ panic ! (
215+ "{} must be set when ENABLE_AUTHENTICATED_SUPERPOSITION=true" ,
216+ user_token_env_hint
217+ )
218+ } ) ;
219+ let superposition_org_token = org_token. unwrap_or_else ( || {
220+ panic ! (
221+ "{} must be set when ENABLE_AUTHENTICATED_SUPERPOSITION=true" ,
222+ org_token_env_hint
223+ )
224+ } ) ;
225+
226+ // Inject Auth cookie for Superposition SDK calls
227+ let cookie_interceptor = CookieIntercept :: new ( format ! (
228+ "user={}; org_{}={}" ,
229+ superposition_user_token, superposition_org_id_env, superposition_org_token,
230+ ) ) ;
231+
232+ superposition_sdk:: Client :: from_conf (
233+ SrsConfig :: builder ( )
234+ . endpoint_url ( endpoint_url)
235+ . behavior_version_latest ( )
236+ . bearer_token ( superposition_token. clone ( ) . into ( ) )
237+ . interceptor ( cookie_interceptor)
238+ . build ( ) ,
239+ )
240+ } else {
241+ superposition_sdk:: Client :: from_conf (
242+ SrsConfig :: builder ( )
243+ . endpoint_url ( endpoint_url)
244+ . behavior_version_latest ( )
245+ . bearer_token ( superposition_token. clone ( ) . into ( ) )
246+ . build ( ) ,
247+ )
248+ }
249+ } ;
250+
251+ let superposition_client = create_superposition_client (
252+ dashboard_superposition_url,
253+ app_config. superposition_user_token . clone ( ) ,
254+ app_config. superposition_org_token . clone ( ) ,
255+ "SUPERPOSITION_USER_TOKEN" ,
256+ "SUPERPOSITION_ORG_TOKEN" ,
257+ ) ;
258+ let rc_superposition_client = create_superposition_client (
259+ rc_superposition_url,
260+ app_config. superposition_rc_user_token . clone ( ) ,
261+ app_config. superposition_rc_org_token . clone ( ) ,
262+ "SUPERPOSITION_RC_USER_TOKEN or SUPERPOSITION_USER_TOKEN" ,
263+ "SUPERPOSITION_RC_ORG_TOKEN or SUPERPOSITION_ORG_TOKEN" ,
264+ ) ;
236265
237266 let app_state = Arc :: new ( types:: AppState {
238267 env : env. clone ( ) ,
239268 db_pool : pool,
240269 s3_client : aws_s3_client,
241270 cf_client : aws_cloudfront_client,
242271 superposition_client,
272+ rc_superposition_client,
243273 sheets_hub : hub,
244274 } ) ;
245275
0 commit comments