Skip to content

Commit b6eb25f

Browse files
committed
Remove builds.json API endpoint
1 parent 4e91742 commit b6eb25f

File tree

3 files changed

+1
-136
lines changed

3 files changed

+1
-136
lines changed

src/web/builds.rs

Lines changed: 1 addition & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use crate::{
99
use anyhow::Result;
1010
use axum::{
1111
extract::{Extension, Path},
12-
http::header::ACCESS_CONTROL_ALLOW_ORIGIN,
1312
response::IntoResponse,
14-
Json,
1513
};
1614
use chrono::{DateTime, Utc};
1715
use serde::Serialize;
@@ -79,40 +77,6 @@ pub(crate) async fn build_list_handler(
7977
.into_response())
8078
}
8179

82-
pub(crate) async fn build_list_json_handler(
83-
Path((name, req_version)): Path<(String, String)>,
84-
Extension(pool): Extension<Pool>,
85-
) -> AxumResult<impl IntoResponse> {
86-
let version = match match_version_axum(&pool, &name, Some(&req_version))
87-
.await?
88-
.exact_name_only()?
89-
{
90-
MatchSemver::Exact((version, _)) | MatchSemver::Latest((version, _)) => version,
91-
MatchSemver::Semver((version, _)) => {
92-
return Ok(super::axum_cached_redirect(
93-
&format!("/crate/{name}/{version}/builds.json"),
94-
CachePolicy::ForeverInCdn,
95-
)?
96-
.into_response());
97-
}
98-
};
99-
100-
let builds = spawn_blocking({
101-
move || {
102-
let mut conn = pool.get()?;
103-
get_builds(&mut conn, &name, &version)
104-
}
105-
})
106-
.await?;
107-
108-
Ok((
109-
Extension(CachePolicy::NoStoreMustRevalidate),
110-
[(ACCESS_CONTROL_ALLOW_ORIGIN, "*")],
111-
Json(builds),
112-
)
113-
.into_response())
114-
}
115-
11680
fn get_builds(conn: &mut postgres::Client, name: &str, version: &str) -> Result<Vec<Build>> {
11781
Ok(conn
11882
.query(
@@ -150,7 +114,7 @@ mod tests {
150114
test::{assert_cache_control, wrapper, FakeBuild},
151115
web::cache::CachePolicy,
152116
};
153-
use chrono::{DateTime, Duration, Utc};
117+
use chrono::Duration;
154118
use kuchikiki::traits::TendrilSink;
155119
use reqwest::StatusCode;
156120

@@ -195,88 +159,6 @@ mod tests {
195159
});
196160
}
197161

198-
#[test]
199-
fn build_list_json() {
200-
wrapper(|env| {
201-
env.fake_release()
202-
.name("foo")
203-
.version("0.1.0")
204-
.builds(vec![
205-
FakeBuild::default()
206-
.rustc_version("rustc (blabla 2019-01-01)")
207-
.docsrs_version("docs.rs 1.0.0"),
208-
FakeBuild::default()
209-
.successful(false)
210-
.rustc_version("rustc (blabla 2020-01-01)")
211-
.docsrs_version("docs.rs 2.0.0"),
212-
FakeBuild::default()
213-
.rustc_version("rustc (blabla 2021-01-01)")
214-
.docsrs_version("docs.rs 3.0.0"),
215-
])
216-
.create()?;
217-
218-
let response = env.frontend().get("/crate/foo/0.1.0/builds.json").send()?;
219-
assert_cache_control(&response, CachePolicy::NoStoreMustRevalidate, &env.config());
220-
let value: serde_json::Value = serde_json::from_str(&response.text()?)?;
221-
222-
assert_eq!(value.pointer("/0/build_status"), Some(&true.into()));
223-
assert_eq!(
224-
value.pointer("/0/docsrs_version"),
225-
Some(&"docs.rs 3.0.0".into())
226-
);
227-
assert_eq!(
228-
value.pointer("/0/rustc_version"),
229-
Some(&"rustc (blabla 2021-01-01)".into())
230-
);
231-
assert!(value.pointer("/0/id").unwrap().is_i64());
232-
assert!(serde_json::from_value::<DateTime<Utc>>(
233-
value.pointer("/0/build_time").unwrap().clone()
234-
)
235-
.is_ok());
236-
237-
assert_eq!(value.pointer("/1/build_status"), Some(&false.into()));
238-
assert_eq!(
239-
value.pointer("/1/docsrs_version"),
240-
Some(&"docs.rs 2.0.0".into())
241-
);
242-
assert_eq!(
243-
value.pointer("/1/rustc_version"),
244-
Some(&"rustc (blabla 2020-01-01)".into())
245-
);
246-
assert!(value.pointer("/1/id").unwrap().is_i64());
247-
assert!(serde_json::from_value::<DateTime<Utc>>(
248-
value.pointer("/1/build_time").unwrap().clone()
249-
)
250-
.is_ok());
251-
252-
assert_eq!(value.pointer("/2/build_status"), Some(&true.into()));
253-
assert_eq!(
254-
value.pointer("/2/docsrs_version"),
255-
Some(&"docs.rs 1.0.0".into())
256-
);
257-
assert_eq!(
258-
value.pointer("/2/rustc_version"),
259-
Some(&"rustc (blabla 2019-01-01)".into())
260-
);
261-
assert!(value.pointer("/2/id").unwrap().is_i64());
262-
assert!(serde_json::from_value::<DateTime<Utc>>(
263-
value.pointer("/2/build_time").unwrap().clone()
264-
)
265-
.is_ok());
266-
267-
assert!(
268-
value.pointer("/1/build_time").unwrap().as_str().unwrap()
269-
< value.pointer("/0/build_time").unwrap().as_str().unwrap()
270-
);
271-
assert!(
272-
value.pointer("/2/build_time").unwrap().as_str().unwrap()
273-
< value.pointer("/1/build_time").unwrap().as_str().unwrap()
274-
);
275-
276-
Ok(())
277-
});
278-
}
279-
280162
#[test]
281163
fn limits() {
282164
wrapper(|env| {
@@ -355,15 +237,6 @@ mod tests {
355237
assert!(body.contains("<a href=\"/crate/aquarelle/latest/source/\""));
356238
assert!(body.contains("<a href=\"/crate/aquarelle/latest\""));
357239

358-
let resp_json = env
359-
.frontend()
360-
.get("/crate/aquarelle/latest/builds.json")
361-
.send()?;
362-
assert!(resp_json
363-
.url()
364-
.as_str()
365-
.ends_with("/crate/aquarelle/latest/builds.json"));
366-
367240
Ok(())
368241
});
369242
}

src/web/metrics.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,6 @@ mod tests {
173173
("/", "/"),
174174
("/crate/hexponent/0.2.0", "/crate/:name/:version"),
175175
("/crate/rcc/0.0.0", "/crate/:name/:version"),
176-
(
177-
"/crate/rcc/0.0.0/builds.json",
178-
"/crate/:name/:version/builds.json",
179-
),
180176
(
181177
"/crate/rcc/0.0.0/status.json",
182178
"/crate/:name/:version/status.json",

src/web/routes.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,6 @@ pub(super) fn build_axum_routes() -> AxumRouter {
216216
"/crate/:name/:version/builds",
217217
get_internal(super::builds::build_list_handler),
218218
)
219-
.route(
220-
"/crate/:name/:version/builds.json",
221-
get_internal(super::builds::build_list_json_handler),
222-
)
223219
.route(
224220
"/crate/:name/:version/status.json",
225221
get_internal(super::status::status_handler),

0 commit comments

Comments
 (0)