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

Separate routes into /ctrl and /pub #488

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
37 changes: 21 additions & 16 deletions plane2/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl PlaneClient {
}

pub async fn status(&self) -> Result<(), PlaneClientError> {
let url = self.base_url.join("/status")?;
let url = self.base_url.join("/ctrl/status")?;

let response = self.client.get(url).send().await?;
get_response::<Value>(response).await?;
Expand All @@ -77,7 +77,7 @@ impl PlaneClient {
pub fn drone_connection(&self, cluster: &ClusterId) -> TypedSocketConnector<MessageFromDrone> {
let mut url = self
.base_url
.join(&format!("/c/{}/drone-socket", cluster))
.join(&format!("/ctrl/c/{}/drone-socket", cluster))
.expect("url is always valid");
http_to_ws_url(&mut url);
TypedSocketConnector::new(url)
Expand All @@ -86,7 +86,7 @@ impl PlaneClient {
pub fn proxy_connection(&self, cluster: &ClusterId) -> TypedSocketConnector<MessageFromProxy> {
let mut url = self
.base_url
.join(&format!("/c/{}/proxy-socket", cluster))
.join(&format!("/ctrl/c/{}/proxy-socket", cluster))
.expect("url is always valid");
http_to_ws_url(&mut url);
TypedSocketConnector::new(url)
Expand All @@ -95,7 +95,7 @@ impl PlaneClient {
pub fn dns_connection(&self) -> TypedSocketConnector<MessageFromDns> {
let mut url = self
.base_url
.join("/dns-socket")
.join("/ctrl/dns-socket")
.expect("url is always valid");
http_to_ws_url(&mut url);
TypedSocketConnector::new(url)
Expand All @@ -106,7 +106,9 @@ impl PlaneClient {
cluster: &ClusterId,
connect_request: &ConnectRequest,
) -> Result<ConnectResponse, PlaneClientError> {
let url = self.base_url.join(&format!("/c/{}/connect", cluster))?;
let url = self
.base_url
.join(&format!("/ctrl/c/{}/connect", cluster))?;

let respose = self.client.post(url).json(connect_request).send().await?;
let connect_response: ConnectResponse = get_response(respose).await?;
Expand All @@ -120,7 +122,7 @@ impl PlaneClient {
) -> Result<(), PlaneClientError> {
let url = self
.base_url
.join(&format!("/c/{}/d/{}/drain", cluster, drone))?;
.join(&format!("/ctrl/c/{}/d/{}/drain", cluster, drone))?;

let response = self.client.post(url).send().await?;
get_response::<Value>(response).await?;
Expand All @@ -132,9 +134,10 @@ impl PlaneClient {
cluster: &ClusterId,
backend_id: &BackendName,
) -> Result<(), PlaneClientError> {
let url = self
.base_url
.join(&format!("/c/{}/b/{}/soft-terminate", cluster, backend_id))?;
let url = self.base_url.join(&format!(
"/ctrl/c/{}/b/{}/soft-terminate",
cluster, backend_id
))?;

let response = self.client.post(url).send().await?;
get_response::<Value>(response).await?;
Expand All @@ -146,9 +149,10 @@ impl PlaneClient {
cluster: &ClusterId,
backend_id: &BackendName,
) -> Result<(), PlaneClientError> {
let url = self
.base_url
.join(&format!("/c/{}/b/{}/hard-terminate", cluster, backend_id))?;
let url = self.base_url.join(&format!(
"/ctrl/c/{}/b/{}/hard-terminate",
cluster, backend_id
))?;

let response = self.client.post(url).send().await?;
get_response::<Value>(response).await?;
Expand All @@ -162,7 +166,7 @@ impl PlaneClient {
) -> Result<TimestampedBackendStatus, PlaneClientError> {
let url = self
.base_url
.join(&format!("/c/{}/b/{}/status", cluster, backend_id))?;
.join(&format!("/pub/c/{}/b/{}/status", cluster, backend_id))?;

let response = self.client.get(url).send().await?;
let status: TimestampedBackendStatus = get_response(response).await?;
Expand All @@ -174,9 +178,10 @@ impl PlaneClient {
cluster: &ClusterId,
backend_id: &BackendName,
) -> Result<sse::SseStream<TimestampedBackendStatus>, PlaneClientError> {
let url = self
.base_url
.join(&format!("/c/{}/b/{}/status-stream", cluster, backend_id))?;
let url = self.base_url.join(&format!(
"/pub/c/{}/b/{}/status-stream",
cluster, backend_id
))?;

let stream = sse::sse_request(url, self.client.clone()).await?;
Ok(stream)
Expand Down
28 changes: 21 additions & 7 deletions plane2/src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ impl ControllerServer {

let heartbeat_handle = HeartbeatSender::start(db.clone(), id.clone()).await?;

let app = Router::new()
// Routes that relate to controlling the system (spawning and terminating drones)
// or that otherwise expose non-public system information.
//
// These routes should not be exposed on the open internet without an authorization
// barrier (such as a reverse proxy) in front.
let control_routes = Router::new()
.route("/status", get(status))
.route("/c/:cluster/drone-socket", get(handle_drone_socket))
.route("/c/:cluster/proxy-socket", get(handle_proxy_socket))
.route("/dns-socket", get(handle_dns_socket))
.route("/c/:cluster/connect", post(handle_connect))
.route("/c/:cluster/b/:backend/status", get(handle_backend_status))
.route(
"/c/:cluster/b/:backend/status-stream",
get(handle_backend_status_stream),
)
.route("/c/:cluster/d/:drone/drain", post(handle_drain))
.route(
"/c/:cluster/b/:backend/soft-terminate",
Expand All @@ -144,7 +144,21 @@ impl ControllerServer {
.route(
"/c/:cluster/b/:backend/hard-terminate",
post(terminate::handle_hard_terminate),
)
);

// Routes that are may be accessed directly from end-user code. These are placed
// under the /pub/ top-level route to make it easier to expose only these routes,
// using a reverse proxy configuration.
let public_routes = Router::new()
.route("/c/:cluster/b/:backend/status", get(handle_backend_status))
.route(
"/c/:cluster/b/:backend/status-stream",
get(handle_backend_status_stream),
);

let app = Router::new()
.nest("/pub", public_routes)
.nest("/ctrl", control_routes)
.layer(trace_layer)
.with_state(controller);

Expand Down
Loading