Skip to content

Commit

Permalink
Bikeshed private endpoint UI
Browse files Browse the repository at this point in the history
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
  • Loading branch information
itowlson committed Apr 15, 2024
1 parent adc1329 commit 95a548b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
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

0 comments on commit 95a548b

Please sign in to comment.