Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bikeshed private endpoint UI #2451

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/http/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ pub struct HttpTriggerConfig {
#[serde(untagged)]
pub enum HttpTriggerRouteConfig {
Route(String),
IsRoutable(bool),
Private(HttpPrivateEndpoint),
}

/// Indicates that a trigger is a private endpoint (not routable).
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct HttpPrivateEndpoint {
/// Whether the private endpoint is private. This must be true.
pub private: bool,
}

impl Default for HttpTriggerRouteConfig {
Expand Down
19 changes: 15 additions & 4 deletions crates/http/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ impl Router {
HttpTriggerRouteConfig::Route(r) => {
Some(Ok((RoutePattern::from(base, r), component_id.to_string())))
}
HttpTriggerRouteConfig::IsRoutable(false) => None,
HttpTriggerRouteConfig::IsRoutable(true) => Some(Err(anyhow!("route must be a string pattern or 'false': component '{component_id}' has route = 'true'"))),
HttpTriggerRouteConfig::Private(endpoint) => if endpoint.private {
None
} else {
Some(Err(anyhow!("route must be a string pattern or '{{ private = true }}': component '{component_id}' has {{ private = false }}")))
}
}
})
.collect::<Result<Vec<_>>>()?;
Expand Down Expand Up @@ -217,6 +220,8 @@ impl fmt::Display for RoutePattern {
mod route_tests {
use spin_testing::init_tracing;

use crate::config::HttpPrivateEndpoint;

use super::*;

#[test]
Expand Down Expand Up @@ -502,7 +507,10 @@ mod route_tests {
vec![
("/", &"/".into()),
("/foo", &"/foo".into()),
("private", &HttpTriggerRouteConfig::IsRoutable(false)),
(
"private",
&HttpTriggerRouteConfig::Private(HttpPrivateEndpoint { private: true }),
),
("/whee/...", &"/whee/...".into()),
],
)
Expand All @@ -519,7 +527,10 @@ mod route_tests {
vec![
("/", &"/".into()),
("/foo", &"/foo".into()),
("bad component", &HttpTriggerRouteConfig::IsRoutable(true)),
(
"bad component",
&HttpTriggerRouteConfig::Private(HttpPrivateEndpoint { private: false }),
),
("/whee/...", &"/whee/...".into()),
],
)
Expand Down
2 changes: 1 addition & 1 deletion crates/trigger-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl HttpTrigger {

let raw_route = match &trigger.route {
HttpTriggerRouteConfig::Route(r) => r.as_str(),
HttpTriggerRouteConfig::IsRoutable(_) => "/...",
HttpTriggerRouteConfig::Private(_) => "/...",
};

let res = match executor {
Expand Down
2 changes: 1 addition & 1 deletion tests/runtime-tests/tests/internal-http/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ source = "%{source=internal-http-front}"
allowed_outbound_hosts = ["http://middle.spin.internal"]

[[trigger.http]]
route = false
route = { private = true }
component = "middle"

[component.middle]
Expand Down
Loading