Split up the prefixes for frontend and servers so we can separate auth easier

main
_ 2020-11-02 17:44:04 +00:00
parent b352f459c7
commit 16984ddcd3
4 changed files with 9 additions and 11 deletions

View File

@ -130,12 +130,12 @@ mod tests {
.timeout (std::time::Duration::from_secs (2))
.build ().unwrap ();
let resp = client.get (&format! ("{}/relay_up_check", relay_url))
let resp = client.get (&format! ("{}/frontend/relay_up_check", relay_url))
.send ().await.unwrap ().bytes ().await.unwrap ();
assert_eq! (resp, "Relay is up\n");
let resp = client.get (&format! ("{}/servers/{}/files/COPYING", relay_url, server_name))
let resp = client.get (&format! ("{}/frontend/servers/{}/files/COPYING", relay_url, server_name))
.send ().await.unwrap ().bytes ().await.unwrap ();
if blake3::hash (&resp) != blake3::Hash::from ([
@ -155,7 +155,7 @@ mod tests {
// Requesting a file from a server that isn't registered
// will error out
let resp = client.get (&format! ("{}/servers/obviously_this_server_does_not_exist/files/COPYING", relay_url))
let resp = client.get (&format! ("{}/frontend/servers/obviously_this_server_does_not_exist/files/COPYING", relay_url))
.send ().await.unwrap ();
assert_eq! (resp.status (), reqwest::StatusCode::NOT_FOUND);

View File

@ -308,7 +308,7 @@ async fn handle_all (req: Request <Body>, state: Arc <RelayState>)
// This is stuff the server can use. Clients can't
// POST right now
return Ok (if let Some (request_code) = prefix_match (path, "/7ZSFUKGV_http_response/") {
return Ok (if let Some (request_code) = prefix_match (path, "/7ZSFUKGV/http_response/") {
let request_code = request_code.into ();
handle_http_response (req, state, request_code).await
}
@ -317,14 +317,14 @@ async fn handle_all (req: Request <Body>, state: Arc <RelayState>)
});
}
Ok (if let Some (listen_code) = prefix_match (path, "/7ZSFUKGV_http_listen/") {
Ok (if let Some (listen_code) = prefix_match (path, "/7ZSFUKGV/http_listen/") {
let api_key = match api_key {
None => return Ok (status_reply (StatusCode::UNAUTHORIZED, "Can't register as server without an API key")),
Some (x) => x,
};
handle_http_listen (state, listen_code.into (), api_key.as_bytes ()).await
}
else if let Some (rest) = prefix_match (path, "/servers/") {
else if let Some (rest) = prefix_match (path, "/frontend/servers/") {
if rest == "" {
#[derive (Serialize)]
struct ServerEntry <'a> {
@ -364,7 +364,7 @@ async fn handle_all (req: Request <Body>, state: Arc <RelayState>)
status_reply (StatusCode::BAD_REQUEST, "Bad URI format")
}
}
else if path == "/relay_up_check" {
else if path == "/frontend/relay_up_check" {
status_reply (StatusCode::OK, "Relay is up\n")
}
else {

View File

@ -80,7 +80,7 @@ async fn handle_req_resp <'a> (
};
let mut resp_req = state.client
.post (&format! ("{}/7ZSFUKGV_http_response/{}", state.config.relay_url, req_id))
.post (&format! ("{}/7ZSFUKGV/http_response/{}", state.config.relay_url, req_id))
.header (crate::PTTH_MAGIC_HEADER, base64::encode (rmp_serde::to_vec (&response.parts).unwrap ()));
if let Some (body) = response.body {
@ -152,7 +152,7 @@ pub async fn main (config_file: ConfigFile, opt: Opt)
delay_for (Duration::from_millis (backoff_delay)).await;
}
let req_req = state.client.get (&format! ("{}/7ZSFUKGV_http_listen/{}", state.config.relay_url, config_file.name));
let req_req = state.client.get (&format! ("{}/7ZSFUKGV/http_listen/{}", state.config.relay_url, config_file.name));
let err_backoff_delay = std::cmp::min (30_000, backoff_delay * 2 + 500);

View File

@ -1,5 +1,3 @@
- Rebase my personal email out of the repo
- Add separate prefixes for clients and servers so separated auth is easier
- ETag cache
- Server-side hash?
- Log / audit log?