irongit

Git hosting and a container registry in one Rust binary (axum + Astro)

Remove unused code and the blanket dead_code allowance

huncholanehuncholaneauthored
parent fa99a77commit 5886a21a51fded310ee2c29c6092ddf7f1f4b077Browse files

9 files changed, +8 -67

+2-16backend/src/auth.rs
@@ -66,6 +66,8 @@ pub struct Viewer {
6666 pub is_admin: bool,
6767 pub avatar_key: Option<String>,
6868 pub scopes: Scopes,
69+ /// How the request authenticated; shows up in Debug output and logs.
70+ #[allow(dead_code)]
6971 pub via: AuthVia,
7072 }
7173
@@ -380,22 +382,6 @@ impl OptionalFromRequestParts<AppState> for ApiViewer {
380382 }
381383 }
382384
383-/// The site admin panel. 404s for everyone else so it is not discoverable.
384-pub struct AdminViewer(pub Viewer);
385-
386-impl FromRequestParts<AppState> for AdminViewer {
387- type Rejection = Response;
388-
389- async fn from_request_parts(parts: &mut Parts, state: &AppState) -> Result<Self, Self::Rejection> {
390- let RequireViewer(viewer) = RequireViewer::from_request_parts(parts, state).await?;
391- if viewer.site_admin() {
392- Ok(AdminViewer(viewer))
393- } else {
394- Err(AppError::NotFound.into_response())
395- }
396- }
397-}
398-
399385 /// Client IP as seen through a reverse proxy, for logs and the audit trail.
400386 pub fn client_ip(headers: &HeaderMap) -> Option<String> {
401387 for name in ["cf-connecting-ip", "x-real-ip"] {
+1-3backend/src/error.rs
@@ -17,7 +17,6 @@ pub enum AppError {
1717 Forbidden(String),
1818 BadRequest(String),
1919 Conflict(String),
20- TooLarge(String),
2120 Internal(anyhow::Error),
2221 }
2322
@@ -43,7 +42,6 @@ impl AppError {
4342 Self::Forbidden(_) => StatusCode::FORBIDDEN,
4443 Self::BadRequest(_) => StatusCode::BAD_REQUEST,
4544 Self::Conflict(_) => StatusCode::CONFLICT,
46- Self::TooLarge(_) => StatusCode::PAYLOAD_TOO_LARGE,
4745 Self::Internal(_) => StatusCode::INTERNAL_SERVER_ERROR,
4846 }
4947 }
@@ -53,7 +51,7 @@ impl AppError {
5351 match self {
5452 Self::NotFound => "Not found".into(),
5553 Self::Unauthorized => "Sign in required".into(),
56- Self::Forbidden(m) | Self::BadRequest(m) | Self::Conflict(m) | Self::TooLarge(m) => m.clone(),
54+ Self::Forbidden(m) | Self::BadRequest(m) | Self::Conflict(m) => m.clone(),
5755 Self::Internal(_) => "Something went wrong on our side. It has been logged.".into(),
5856 }
5957 }
+1-2backend/src/git.rs
@@ -42,7 +42,6 @@ pub struct Git {
4242 pub struct RefInfo {
4343 /// Full name, e.g. "refs/heads/main".
4444 pub name: String,
45- pub sha: String,
4645 /// Peeled commit for annotated tags, otherwise the same as `sha`.
4746 pub commit: String,
4847 pub committed_at: Option<DateTime<Utc>>,
@@ -232,7 +231,7 @@ impl Git {
232231 let commit = if peeled.is_empty() { sha.clone() } else { peeled };
233232 let date = if date.is_empty() { peeled_date } else { date };
234233 let committed_at = date.parse::<i64>().ok().and_then(|t| Utc.timestamp_opt(t, 0).single());
235- Some(RefInfo { name, sha, commit, committed_at, subject })
234+ Some(RefInfo { name, commit, committed_at, subject })
236235 })
237236 .collect())
238237 }
+0-2backend/src/main.rs
@@ -5,8 +5,6 @@
55 //! The same binary is also the git hook (`irongit hook pre-receive`) and the
66 //! admin tool (`irongit admin ...`).
77
8-// Scaffolding is wired up before every caller exists; revisit before release.
9-#![allow(dead_code)]
108
119 mod analytics;
1210 mod api;
+1-15backend/src/registry/mod.rs
@@ -261,19 +261,6 @@ impl Actions {
261261 }
262262 }
263263
264- pub fn list(&self) -> Vec<String> {
265- let mut out = Vec::new();
266- if self.pull {
267- out.push("pull".to_string());
268- }
269- if self.push {
270- out.push("push".to_string());
271- }
272- if self.delete {
273- out.push("delete".to_string());
274- }
275- out
276- }
277264 }
278265
279266 /// The caller of a /v2 request.
@@ -355,7 +342,6 @@ pub struct Target {
355342 pub owner: Account,
356343 pub image: String,
357344 pub package: Option<Package>,
358- pub actions: Actions,
359345 }
360346
361347 impl Target {
@@ -380,7 +366,7 @@ pub async fn authorize(state: &AppState, caller: &Caller, name: &str, action: &s
380366 Caller::Anonymous => actions_for(state, None, &owner, package.as_ref()).await?,
381367 };
382368 if actions.allows(action) {
383- return Ok(Target { name: name.to_string(), owner, image, package, actions });
369+ return Ok(Target { name: name.to_string(), owner, image, package });
384370 }
385371 if caller.is_anonymous() {
386372 return Err(RegError::unauthorized(Some(scope)));
+0-5backend/src/storage.rs
@@ -63,11 +63,6 @@ impl Storage {
6363 action.sign(ttl)
6464 }
6565
66- /// A URL anyone can PUT a body to for `ttl`.
67- pub fn presign_put(&self, key: &str, ttl: Duration) -> Url {
68- self.bucket.put_object(Some(&self.credentials), key).sign(ttl)
69- }
70-
7166 /// A presigned PUT that only succeeds when the body's SHA-256 matches.
7267 /// The client must send `x-amz-checksum-sha256: <sha256_base64>` and each
7368 /// `x-amz-meta-<name>: <value>` in `metadata` exactly; R2 rejects any other
+0-1backend/src/web/admin/audit.rs
@@ -39,7 +39,6 @@ fn with_page(base: &str, page: i64) -> String {
3939
4040 #[derive(sqlx::FromRow)]
4141 pub struct AuditRow {
42- pub id: i64,
4342 pub action: String,
4443 pub target: String,
4544 pub meta: serde_json::Value,
+2-13backend/src/web/heatmap.rs
@@ -3,7 +3,7 @@
33
44 use std::collections::HashMap;
55
6-use chrono::{Datelike, Duration, NaiveDate, Weekday};
6+use chrono::{Datelike, Duration, NaiveDate};
77 use maud::{Markup, html};
88
99 const CELL: i64 = 11;
@@ -139,21 +139,10 @@ fn tooltip(count: i64, day: NaiveDate) -> String {
139139 }
140140 }
141141
142-pub fn weekday_name(day: Weekday) -> &'static str {
143- match day {
144- Weekday::Mon => "Monday",
145- Weekday::Tue => "Tuesday",
146- Weekday::Wed => "Wednesday",
147- Weekday::Thu => "Thursday",
148- Weekday::Fri => "Friday",
149- Weekday::Sat => "Saturday",
150- Weekday::Sun => "Sunday",
151- }
152-}
153-
154142 #[cfg(test)]
155143 mod tests {
156144 use super::*;
145+ use chrono::Weekday;
157146
158147 #[test]
159148 fn grid_starts_on_sunday_and_streaks_count() {
+1-10backend/src/web/layout.rs
@@ -9,7 +9,7 @@ use axum::{
99 http::{StatusCode, header, request::Parts},
1010 response::{Html, IntoResponse, Response},
1111 };
12-use maud::{DOCTYPE, Markup, PreEscaped, html};
12+use maud::{DOCTYPE, Markup, html};
1313
1414 use crate::{
1515 auth::{MaybeViewer, Viewer},
@@ -68,11 +68,6 @@ impl Page {
6868 self
6969 }
7070
71- pub fn status(mut self, status: StatusCode) -> Self {
72- self.status = status;
73- self
74- }
75-
7671 /// Keep settings, forms and private pages out of search engines.
7772 pub fn noindex(mut self) -> Self {
7873 self.noindex = true;
@@ -228,7 +223,3 @@ pub fn fragment(markup: Markup) -> Response {
228223 response.headers_mut().insert(header::CACHE_CONTROL, header::HeaderValue::from_static("no-store"));
229224 response
230225 }
231-
232-pub fn raw_html(s: &str) -> PreEscaped<String> {
233- PreEscaped(s.to_string())
234-}