-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(black-duck): Add a mechanism to query vulnerabilities by origin-id
By default, the vulnerabilities are queried by the respective purl. This does not work in all cases, e.g.: 1. Some origins do not (yet) have a purl associated. 2. For some ecosystem, querying by purl doesn't work, even though the data sets have a purl. 3. The knowledge base may not contain a data set for the exact package but for the same "package" in a different ecosystem. For example, query vulnerabilities for the "ubuntu" package instead of for the "github" package. So, allow to set the origin-id via a package label curation, to override the origin for which the vulnerabilities shall be retrieved. Note: Since the amount of external namespaces is rather large, test the querying only for a few ecosystems. This should be fine, because there is very little namespace specific logic in ORT's code involved. Signed-off-by: Frank Viernau <x9fviern@zeiss.com>
- Loading branch information
Showing
7 changed files
with
559 additions
and
3 deletions.
There are no files selected for viewing
411 changes: 411 additions & 0 deletions
411
plugins/advisors/black-duck/src/funTest/assets/recorded-responses.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
plugins/advisors/black-duck/src/main/kotlin/BlackDuckOriginId.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) 2025 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/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.ossreviewtoolkit.plugins.advisors.blackduck | ||
|
||
import com.blackduck.integration.bdio.model.Forge | ||
import com.blackduck.integration.bdio.model.externalid.ExternalId | ||
|
||
/** | ||
* A unique identifier of a Black Duck Origin, see also | ||
* https://community.blackduck.com/s/article/What-is-an-Origin-and-Origin-ID-in-Blackduck. | ||
* Note: While the term "origin" is still current, the properties `originType` and`originId` haven been deprecated in | ||
* favor of `externalNamespace` and `externalId`. | ||
*/ | ||
internal data class BlackDuckOriginId( | ||
/** | ||
* The namespace such as 'maven', 'pypi' or 'github'. | ||
*/ | ||
val externalNamespace: String, | ||
|
||
/** | ||
* The component's identifier within the external namespace. | ||
*/ | ||
val externalId: String | ||
) { | ||
fun toExternalId(): ExternalId { | ||
val forge = requireNotNull(Forge.getKnownForges()[externalNamespace]) { | ||
"Unknown forge for namespace: '$externalNamespace'." | ||
} | ||
|
||
return ExternalId.createFromExternalId(forge, externalId, null, null) | ||
} | ||
|
||
companion object { | ||
fun parse(coordinates: String): BlackDuckOriginId { | ||
val parts = coordinates.split(':', limit = 2) | ||
require(parts.size == 2) { | ||
"Could not parse originId '$coordinates'. Missing ':' separator ." | ||
} | ||
|
||
return BlackDuckOriginId(externalNamespace = parts[0], externalId = parts[1]) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters