Skip to content

Commit

Permalink
basic auth is now optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Virv12 committed Oct 9, 2024
1 parent 433370a commit a5e4125
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pixie-server/example.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ hosts:
broadcast_speed: 52428800
http:
listen_on: 0.0.0.0:8080
password: secret
#password: secret
groups:
- [room0, 0]
- [room1, 1]
Expand Down
23 changes: 13 additions & 10 deletions pixie-server/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ async fn status(extract::State(state): extract::State<Arc<State>>) -> impl IntoR
));
let lines = messages.map(|msg| serde_json::to_string(&msg).map(|x| x + "\n"));

let mut res = Response::new(Body::from_stream(lines));
res.headers_mut()
.insert("Content-Type", "application/json".parse().unwrap());
res
Response::builder()
.header("Content-Type", "application/json")
.header("Cache-Control", "no-cache")
.header("X-Accel-Buffering", "no")
.body(Body::from_stream(lines))
.unwrap()
}

pub async fn main(state: Arc<State>) -> Result<()> {
Expand All @@ -190,7 +192,7 @@ pub async fn main(state: Arc<State>) -> Result<()> {

let admin_path = state.storage_dir.join("admin");

let router = Router::new()
let mut router = Router::new()
.route("/admin/status", get(status))
.route("/admin/gc", get(gc))
.route("/admin/action/:unit/:action", get(action))
Expand All @@ -199,13 +201,14 @@ pub async fn main(state: Arc<State>) -> Result<()> {
.nest_service(
"/",
ServeDir::new(&admin_path).append_index_html_on_directories(true),
)
.layer(ValidateRequestHeaderLayer::basic("admin", password))
.layer(TraceLayer::new_for_http())
.with_state(state);
);
if let Some(password) = password {
router = router.layer(ValidateRequestHeaderLayer::basic("admin", password));
}
router = router.layer(TraceLayer::new_for_http());

let listener = TcpListener::bind(listen_on).await?;
axum::serve(listener, router).await?;
axum::serve(listener, router.with_state(state)).await?;

Ok(())
}
2 changes: 1 addition & 1 deletion pixie-shared/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct HostsConfig {
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct HttpConfig {
pub listen_on: SocketAddrV4,
pub password: String,
pub password: Option<String>,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
Expand Down

0 comments on commit a5e4125

Please sign in to comment.