Skip to content

Commit

Permalink
Add endpoint for getting build check jobs
Browse files Browse the repository at this point in the history
The general job log endpoint requires the "jobs" scope, but this one
only requires access to the associated build.
  • Loading branch information
jameswestman authored and barthalion committed Jul 19, 2023
1 parent 960ba61 commit a7f5d35
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flat-manager-client
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ async def wait_for_checks(session, build_url, token):

for check in build["checks"]:
print("Waiting for check: %s" % (check["check_name"]))
job_url = build_url_to_api(build_url) + "/job/" + str(check["job_id"])
job_url = build_url + "/check/" + check["check_name"] + "/job"
await wait_for_job(session, job_url, token)

@retry(
Expand Down
39 changes: 39 additions & 0 deletions src/api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,45 @@ async fn publish_async(
respond_with_url(&job, &req, "show_publish_job", &[params.id.to_string()])
}

#[derive(Deserialize)]
pub struct BuildCheckPathParams {
id: i32,
check_name: String,
}

pub fn get_check_job(
args: Json<JobArgs>,
params: Path<BuildCheckPathParams>,
db: Data<Db>,
req: HttpRequest,
) -> impl Future<Item = HttpResponse, Error = ApiError> {
Box::pin(get_check_job_async(args, params, db, req)).compat()
}

async fn get_check_job_async(
args: Json<JobArgs>,
params: Path<BuildCheckPathParams>,
db: Data<Db>,
req: HttpRequest,
) -> Result<HttpResponse, ApiError> {
req.has_token_claims(&format!("build/{}", params.id), ClaimsScope::Build)?;

let build = db.lookup_build(params.id).await?;
has_token_for_build(&req, &build)?;

let checks = db.lookup_checks(build.id).await?;
let check = checks
.iter()
.find(|check| check.check_name == params.check_name);

if let Some(check) = check {
let job = db.lookup_job(check.job_id, args.log_offset).await?;
Ok(HttpResponse::Ok().json(job))
} else {
Err(ApiError::NotFound)
}
}

pub fn purge(
params: Path<BuildPathParams>,
db: Data<Db>,
Expand Down
5 changes: 5 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ pub fn create_app(
.route(web::post().to_async(api::build::publish))
.route(web::get().to_async(api::build::get_publish_job)),
)
.service(
web::resource("/build/{id}/check/{check_name}/job")
.name("show_check_job")
.route(web::get().to_async(api::build::get_check_job)),
)
.service(
web::resource("/build/{id}/purge")
.route(web::post().to_async(api::build::purge)),
Expand Down

0 comments on commit a7f5d35

Please sign in to comment.