Skip to content

Commit 904703b

Browse files
committed
feat(services): publish authoritative application origins
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
1 parent bf9f55c commit 904703b

29 files changed

Lines changed: 1096 additions & 197 deletions

File tree

‎crates/openshell-cli/src/run.rs‎

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
47144723
fn 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!(

‎crates/openshell-cli/tests/provider_commands_integration.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ impl OpenShell for TestOpenShell {
363363
let name = request.name;
364364
// Return a minimal sandbox with metadata for CAS operations
365365
Ok(Response::new(SandboxResponse {
366+
application_service_urls: HashMap::new(),
367+
gateway_service_urls: HashMap::new(),
366368
sandbox: Some(Sandbox {
367369
metadata: Some(openshell_core::proto::datamodel::v1::ObjectMeta {
368370
id: format!("sb-{name}"),

‎crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ impl OpenShell for TestOpenShell {
223223
},
224224
);
225225
Ok(Response::new(SandboxResponse {
226+
application_service_urls: HashMap::new(),
227+
gateway_service_urls: HashMap::new(),
226228
sandbox: Some(sandbox),
227229
service_urls,
228230
}))
@@ -287,6 +289,8 @@ impl OpenShell for TestOpenShell {
287289
};
288290
sandbox.set_phase(SandboxPhase::Ready as i32);
289291
Ok(Response::new(SandboxResponse {
292+
application_service_urls: HashMap::new(),
293+
gateway_service_urls: HashMap::new(),
290294
sandbox: Some(sandbox),
291295
service_urls: HashMap::new(),
292296
}))
@@ -523,6 +527,8 @@ impl OpenShell for TestOpenShell {
523527
.push(request.into_inner());
524528
Ok(Response::new(
525529
openshell_core::proto::ServiceEndpointResponse {
530+
application_url: String::new(),
531+
gateway_url: String::new(),
526532
url: "https://default--sandbox.openshell.localhost:17670/".to_string(),
527533
..Default::default()
528534
},
@@ -535,6 +541,8 @@ impl OpenShell for TestOpenShell {
535541
) -> Result<Response<openshell_core::proto::ServiceEndpointResponse>, Status> {
536542
Ok(Response::new(
537543
openshell_core::proto::ServiceEndpointResponse {
544+
application_url: String::new(),
545+
gateway_url: String::new(),
538546
url: "https://default--sandbox.openshell.localhost:17670/".to_string(),
539547
..Default::default()
540548
},

‎crates/openshell-cli/tests/sandbox_exec_streaming_integration.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ macro_rules! mock_gateway {
182182
async fn get_sandbox(&self, _: Request<proto::GetSandboxRequest>) -> Result<Response<proto::SandboxResponse>, Status> {
183183
self.calls.lock().unwrap().lookups += 1;
184184
Ok(Response::new(proto::SandboxResponse {
185+
application_service_urls: std::collections::HashMap::new(),
186+
gateway_service_urls: std::collections::HashMap::new(),
185187
sandbox: Some(proto::Sandbox {
186188
metadata: Some(proto::datamodel::v1::ObjectMeta {
187189
id: "test-id".to_string(),

‎crates/openshell-cli/tests/sandbox_name_fallback_integration.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ impl OpenShell for TestOpenShell {
172172
let name = request.name.clone();
173173
*self.state.last_get_name.lock().await = Some(name.clone());
174174
Ok(Response::new(SandboxResponse {
175+
application_service_urls: std::collections::HashMap::new(),
176+
gateway_service_urls: std::collections::HashMap::new(),
175177
sandbox: Some(Sandbox {
176178
metadata: Some(openshell_core::proto::datamodel::v1::ObjectMeta {
177179
id: "test-id".to_string(),

0 commit comments

Comments
 (0)