@@ -726,10 +726,17 @@ pub async fn sandbox_create(
726726 Err ( status) => return Err ( miette:: miette!( status. to_string( ) ) ) ,
727727 } ;
728728 let response = response. into_inner ( ) ;
729+ let application_service_urls = response. application_service_urls ;
729730 let service_urls = response
730731 . service_urls
731732 . into_iter ( )
732- . map ( |( service, url) | ( service, service_url_for_gateway ( & url, & effective_server) ) )
733+ . map ( |( service, url) | {
734+ let url = application_service_urls
735+ . get ( & service)
736+ . cloned ( )
737+ . unwrap_or_else ( || service_url_for_gateway ( & url, & effective_server) ) ;
738+ ( service, url)
739+ } )
733740 . collect :: < HashMap < _ , _ > > ( ) ;
734741 let sandbox = response
735742 . sandbox
@@ -1122,10 +1129,7 @@ pub async fn sandbox_create(
11221129 "\u{2713} " . green( ) . bold( ) ,
11231130 ) ;
11241131 if let Some ( url) = service_urls. get ( "" ) . filter ( |url| !url. is_empty ( ) ) {
1125- eprintln ! (
1126- " Access at: {}" ,
1127- service_url_for_gateway( url, & effective_server)
1128- ) ;
1132+ eprintln ! ( " Access at: {url}" ) ;
11291133 }
11301134 }
11311135
@@ -4376,7 +4380,7 @@ pub async fn service_expose(
43764380 ) ;
43774381 }
43784382 if !response. url . is_empty ( ) {
4379- let url = service_url_for_gateway ( & response. url , server) ;
4383+ let url = preferred_service_url ( & response, server) ;
43804384 println ! ( " URL: {}" , url. cyan( ) ) ;
43814385 }
43824386 Ok ( ( ) )
@@ -4589,7 +4593,7 @@ fn print_service_endpoint_table(
45894593 let url = if response. url . is_empty ( ) {
45904594 String :: new ( )
45914595 } else {
4592- service_url_for_gateway ( & response. url , gateway_endpoint)
4596+ preferred_service_url ( response, gateway_endpoint)
45934597 } ;
45944598 Some ( (
45954599 workspace. to_string ( ) ,
@@ -4680,7 +4684,7 @@ fn service_endpoint_to_json(
46804684 let url = if response. url . is_empty ( ) {
46814685 String :: new ( )
46824686 } else {
4683- service_url_for_gateway ( & response. url , gateway_endpoint)
4687+ preferred_service_url ( response, gateway_endpoint)
46844688 } ;
46854689
46864690 Some ( serde_json:: json!( {
@@ -4690,6 +4694,8 @@ fn service_endpoint_to_json(
46904694 "target_port" : endpoint. target_port,
46914695 "authorization_mode" : service_authorization_mode_name( endpoint. authorization_mode) ,
46924696 "url" : url,
4697+ "application_url" : response. application_url,
4698+ "gateway_url" : service_url_for_gateway( & response. gateway_url, gateway_endpoint) ,
46934699 } ) )
46944700}
46954701
@@ -4704,13 +4710,16 @@ fn service_authorization_mode_name(mode: i32) -> &'static str {
47044710 }
47054711}
47064712
4707- /// Read gcloud Application Default Credentials from disk.
4708- ///
4709- /// Returns `(client_id, client_secret, refresh_token)`.
4710- ///
4711- /// Checks `GOOGLE_APPLICATION_CREDENTIALS` first; falls back to
4712- /// `$CLOUDSDK_CONFIG/application_default_credentials.json` when set, then to
4713- /// `~/.config/gcloud/application_default_credentials.json`.
4713+ /// Application origins are independent of the gateway transport. Only legacy
4714+ /// gateway URLs inherit a caller's external gateway port.
4715+ fn preferred_service_url ( response : & ServiceEndpointResponse , gateway : & str ) -> String {
4716+ if response. application_url . is_empty ( ) {
4717+ service_url_for_gateway ( & response. url , gateway)
4718+ } else {
4719+ response. application_url . clone ( )
4720+ }
4721+ }
4722+
47144723fn service_url_for_gateway ( service_url : & str , gateway_endpoint : & str ) -> String {
47154724 let ( Ok ( mut service_url) , Ok ( gateway_endpoint) ) = (
47164725 url:: Url :: parse ( service_url) ,
@@ -7348,6 +7357,8 @@ mod tests {
73487357 #[ test]
73497358 fn service_endpoint_json_has_raw_fields_and_normalized_url ( ) {
73507359 let response = ServiceEndpointResponse {
7360+ application_url : String :: new ( ) ,
7361+ gateway_url : String :: new ( ) ,
73517362 endpoint : Some ( ServiceEndpoint {
73527363 metadata : Some ( ObjectMeta {
73537364 workspace : "team-a" . to_string ( ) ,
@@ -7373,6 +7384,8 @@ mod tests {
73737384 "target_port" : 8080 ,
73747385 "authorization_mode" : "bearer_passthrough" ,
73757386 "url" : "https://api.openshell.localhost:17670/" ,
7387+ "application_url" : "" ,
7388+ "gateway_url" : "" ,
73767389 } )
73777390 ) ;
73787391 assert ! ( service_endpoint_to_json( & ServiceEndpointResponse :: default ( ) , "unused" ) . is_none( ) ) ;
@@ -8132,6 +8145,20 @@ mod tests {
81328145 assert ! ( rootfs_tar_sources_supported_for_gateway( None ) ) ;
81338146 }
81348147
8148+ #[ test]
8149+ fn application_origin_is_preserved_when_gateway_uses_a_port_forward ( ) {
8150+ let response = ServiceEndpointResponse {
8151+ application_url : "https://default--demo--web.services.example.com:10443/" . into ( ) ,
8152+ gateway_url : "https://default--demo--web.api.example.com:8080/" . into ( ) ,
8153+ url : "https://default--demo--web.services.example.com:10443/" . into ( ) ,
8154+ ..Default :: default ( )
8155+ } ;
8156+ assert_eq ! (
8157+ super :: preferred_service_url( & response, "https://localhost:29092" ) ,
8158+ response. application_url
8159+ ) ;
8160+ }
8161+
81358162 #[ test]
81368163 fn service_url_for_gateway_uses_external_gateway_port ( ) {
81378164 assert_eq ! (
0 commit comments