kojiapi: Check job type (job status and logs)
The type verification introduced in the previous commit is now also used
when retrieving the job status (GET /compose/{id}) and the logs (GET
/compose/{id}/logs).
In these cases, job retrieval needs to be performed twice:
1. First the job parameters are retrieved (Job()) to check the type.
2. Then the job result is retrieved (JobStatus()) for the status or
logs.
This makes it unlikely (essentially impossible) that the retrieval will
fail with "not found" on the second retrieval (JobStatus()), but it's
still a good sanity check for the system.
Verifies the Koji job types when retrieving Init and Build jobs as well.
This commit is contained in:
parent
a2c4622930
commit
e59e07a09a
1 changed files with 27 additions and 0 deletions
|
|
@ -295,12 +295,21 @@ func (h *apiHandlers) GetComposeId(ctx echo.Context, idstr string) error {
|
|||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
||||
}
|
||||
|
||||
// Make sure id exists and matches a FinalizeJob
|
||||
if _, _, err := h.getFinalizeJob(id); err != nil {
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Job %s not found: %s", idstr, err))
|
||||
}
|
||||
|
||||
var finalizeResult worker.KojiFinalizeJobResult
|
||||
finalizeStatus, deps, err := h.server.workers.JobStatus(id, &finalizeResult)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Job %s not found: %s", idstr, err))
|
||||
}
|
||||
|
||||
// Make sure deps[0] matches a KojiInitJob
|
||||
if _, err := h.getInitJob(deps[0]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var initResult worker.KojiInitJobResult
|
||||
_, _, err = h.server.workers.JobStatus(deps[0], &initResult)
|
||||
if err != nil {
|
||||
|
|
@ -311,6 +320,10 @@ func (h *apiHandlers) GetComposeId(ctx echo.Context, idstr string) error {
|
|||
var buildResults []worker.OSBuildKojiJobResult
|
||||
var imageStatuses []api.ImageStatus
|
||||
for i := 1; i < len(deps); i++ {
|
||||
// Make sure deps[i] matches an OSBuildKojiJob
|
||||
if _, _, err := h.getBuildJob(deps[i]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var buildResult worker.OSBuildKojiJobResult
|
||||
jobStatus, _, err := h.server.workers.JobStatus(deps[i], &buildResult)
|
||||
if err != nil {
|
||||
|
|
@ -348,12 +361,22 @@ func (h *apiHandlers) GetComposeIdLogs(ctx echo.Context, idstr string) error {
|
|||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
||||
}
|
||||
|
||||
// Make sure id exists and matches a FinalizeJob
|
||||
if _, _, err := h.getFinalizeJob(id); err != nil {
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Job %s not found: %s", idstr, err))
|
||||
}
|
||||
|
||||
var finalizeResult worker.KojiFinalizeJobResult
|
||||
_, deps, err := h.server.workers.JobStatus(id, &finalizeResult)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Job %s not found: %s", idstr, err))
|
||||
}
|
||||
|
||||
// Make sure deps[0] matches a KojiInitJob
|
||||
if _, err := h.getInitJob(deps[0]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var initResult worker.KojiInitJobResult
|
||||
_, _, err = h.server.workers.JobStatus(deps[0], &initResult)
|
||||
if err != nil {
|
||||
|
|
@ -363,6 +386,10 @@ func (h *apiHandlers) GetComposeIdLogs(ctx echo.Context, idstr string) error {
|
|||
|
||||
var buildResults []interface{}
|
||||
for i := 1; i < len(deps); i++ {
|
||||
// Make sure deps[i] matches an OSBuildKojiJob
|
||||
if _, _, err := h.getBuildJob(deps[i]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var buildResult worker.OSBuildJobResult
|
||||
_, _, err = h.server.workers.JobStatus(deps[i], &buildResult)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue