Skip to content

Commit

Permalink
feat(api): Add runs route for issues
Browse files Browse the repository at this point in the history
Add an endpoint to retrieve issues, their source and affected packages
for an ORT run.

Resolves #405.

Signed-off-by: Marcel Bochtler <marcel.bochtler@bosch.com>
  • Loading branch information
MarcelBochtler committed Sep 12, 2024
1 parent 42adab3 commit e331a0a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/v1/mapping/src/commonMain/kotlin/Mappings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.eclipse.apoapsis.ortserver.api.v1.model.EvaluatorJobConfiguration as
import org.eclipse.apoapsis.ortserver.api.v1.model.Identifier as ApiIdentifier
import org.eclipse.apoapsis.ortserver.api.v1.model.InfrastructureService as ApiInfrastructureService
import org.eclipse.apoapsis.ortserver.api.v1.model.Issue as ApiIssue
import org.eclipse.apoapsis.ortserver.api.v1.model.IssueWithIdentifier as ApiIssueWithIdentifier
import org.eclipse.apoapsis.ortserver.api.v1.model.JiraNotificationConfiguration as ApiJiraNotificationConfiguration
import org.eclipse.apoapsis.ortserver.api.v1.model.JiraRestClientConfiguration as ApiJiraRestClientConfiguration
import org.eclipse.apoapsis.ortserver.api.v1.model.JobConfigurations as ApiJobConfigurations
Expand Down Expand Up @@ -83,6 +84,7 @@ import org.eclipse.apoapsis.ortserver.model.EvaluatorJob
import org.eclipse.apoapsis.ortserver.model.EvaluatorJobConfiguration
import org.eclipse.apoapsis.ortserver.model.InfrastructureService
import org.eclipse.apoapsis.ortserver.model.InfrastructureServiceDeclaration
import org.eclipse.apoapsis.ortserver.model.IssueWithIdentifier
import org.eclipse.apoapsis.ortserver.model.JiraNotificationConfiguration
import org.eclipse.apoapsis.ortserver.model.JiraRestClientConfiguration
import org.eclipse.apoapsis.ortserver.model.JobConfigurations
Expand Down Expand Up @@ -455,6 +457,8 @@ fun ApiScannerJobConfiguration.mapToModel() = ScannerJobConfiguration(

fun Secret.mapToApi() = ApiSecret(name, description)

fun IssueWithIdentifier.mapToApi() = ApiIssueWithIdentifier(issue.mapToApi(), identifier?.mapToApi())

fun VulnerabilityWithIdentifier.mapToApi() =
ApiVulnerabilityWithIdentifier(vulnerability.mapToApi(), identifier.mapToApi())

Expand Down
31 changes: 31 additions & 0 deletions api/v1/model/src/commonMain/kotlin/IssueWithIdentifier.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2024 The ORT Server Authors (See <https://github.com/eclipse-apoapsis/ort-server/blob/main/NOTICE>)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/

package org.eclipse.apoapsis.ortserver.api.v1.model

import kotlinx.serialization.Serializable

/**
* A union data class to associate a [Issue] with an [Identifier].
*/
@Serializable
data class IssueWithIdentifier(
val issue: Issue,
val identifier: Identifier?
)
21 changes: 21 additions & 0 deletions core/src/main/kotlin/api/RunsRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.eclipse.apoapsis.ortserver.api.v1.mapping.mapToApi
import org.eclipse.apoapsis.ortserver.api.v1.mapping.mapToModel
import org.eclipse.apoapsis.ortserver.api.v1.model.SortDirection
import org.eclipse.apoapsis.ortserver.api.v1.model.SortProperty
import org.eclipse.apoapsis.ortserver.core.apiDocs.getIssuesByRunId
import org.eclipse.apoapsis.ortserver.core.apiDocs.getLogsByRunId
import org.eclipse.apoapsis.ortserver.core.apiDocs.getOrtRunById
import org.eclipse.apoapsis.ortserver.core.apiDocs.getReportByRunIdAndFileName
Expand All @@ -51,10 +52,12 @@ import org.eclipse.apoapsis.ortserver.dao.QueryParametersException
import org.eclipse.apoapsis.ortserver.logaccess.LogFileService
import org.eclipse.apoapsis.ortserver.logaccess.LogLevel
import org.eclipse.apoapsis.ortserver.logaccess.LogSource
import org.eclipse.apoapsis.ortserver.model.IssueWithIdentifier
import org.eclipse.apoapsis.ortserver.model.OrtRun
import org.eclipse.apoapsis.ortserver.model.VulnerabilityWithIdentifier
import org.eclipse.apoapsis.ortserver.model.authorization.RepositoryPermission
import org.eclipse.apoapsis.ortserver.model.repositories.OrtRunRepository
import org.eclipse.apoapsis.ortserver.services.IssueService
import org.eclipse.apoapsis.ortserver.services.ReportStorageService
import org.eclipse.apoapsis.ortserver.services.RepositoryService
import org.eclipse.apoapsis.ortserver.services.VulnerabilityService
Expand All @@ -65,6 +68,7 @@ import org.koin.ktor.ext.inject
* API for the run's endpoint. This endpoint provides information related to ORT runs and their results.
*/
fun Route.runs() = route("runs/{runId}") {
val issueService by inject<IssueService>()
val ortRunRepository by inject<OrtRunRepository>()
val repositoryService by inject<RepositoryService>()
val vulnerabilityService by inject<VulnerabilityService>()
Expand Down Expand Up @@ -111,6 +115,23 @@ fun Route.runs() = route("runs/{runId}") {
}
}

route("issues") {
get(getIssuesByRunId) {
call.forRun(ortRunRepository) { ortRun ->
requirePermission(RepositoryPermission.READ_ORT_RUNS.roleName(ortRun.repositoryId))

val pagingOptions = call.pagingOptions(SortProperty("timestamp", SortDirection.ASCENDING))

// FIXME: Add pagingOptions, which doesn't work yet in the service.
val issueForOrtRun = issueService.listForOrtRunId(ortRun.id)

val pagedResponse = issueForOrtRun.mapToApi(IssueWithIdentifier::mapToApi)

call.respond(HttpStatusCode.OK, pagedResponse)
}
}
}

route("vulnerabilities") {
get(getVulnerabilitiesByRunId) {
call.forRun(ortRunRepository) { ortRun ->
Expand Down
47 changes: 47 additions & 0 deletions core/src/main/kotlin/apiDocs/RunsDocs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ import io.ktor.http.HttpStatusCode
import kotlinx.datetime.Clock

import org.eclipse.apoapsis.ortserver.api.v1.model.Identifier
import org.eclipse.apoapsis.ortserver.api.v1.model.Issue
import org.eclipse.apoapsis.ortserver.api.v1.model.IssueWithIdentifier
import org.eclipse.apoapsis.ortserver.api.v1.model.OrtRun
import org.eclipse.apoapsis.ortserver.api.v1.model.OrtRunStatus
import org.eclipse.apoapsis.ortserver.api.v1.model.PagedResponse
import org.eclipse.apoapsis.ortserver.api.v1.model.PagingData
import org.eclipse.apoapsis.ortserver.api.v1.model.Severity
import org.eclipse.apoapsis.ortserver.api.v1.model.SortDirection
import org.eclipse.apoapsis.ortserver.api.v1.model.SortProperty
import org.eclipse.apoapsis.ortserver.api.v1.model.Vulnerability
Expand Down Expand Up @@ -145,6 +148,50 @@ val getLogsByRunId: OpenApiRoute.() -> Unit = {
}
}

val getIssuesByRunId: OpenApiRoute.() -> Unit = {
operationId = "GetIssuesByRunId"
summary = "Get the issues of an ORT run."
tags = listOf("Issues")

request {
pathParameter<Long>("runId") {
description = "The ID of the ORT run."
}

standardListQueryParameters()
}

response {
HttpStatusCode.OK to {
description = "Success."
jsonBody<PagedResponse<IssueWithIdentifier>> {
example("Get issues for an ORT run") {
value = PagedResponse(
listOf(
Issue(
message = "An issue",
severity = Severity.ERROR,
source = "source",
timestamp = Clock.System.now()
)
),
PagingData(
limit = 20,
offset = 0,
totalCount = 1,
sortProperties = listOf(SortProperty("timestamp", SortDirection.DESCENDING))
)
)
}
}
}

HttpStatusCode.NotFound to {
description = "The ORT run does not exist."
}
}
}

val getVulnerabilitiesByRunId: OpenApiRoute.() -> Unit = {
operationId = "GetVulnerabilitiesByRunId"
summary = "Get the vulnerabilities found in an ORT run."
Expand Down

0 comments on commit e331a0a

Please sign in to comment.