harborapi.ext.artifact
Module that defines the ArtifactInfo
class that aggregates information about an artifact from several Harbor API models.
ArtifactInfo
Bases: BaseModel
Class composed of models returned by the Harbor API that gives information about an artifact.
Source code in harborapi/ext/artifact.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
cvss: CVSSData
cached
property
Key CVSS metrics for the artifact.
Returns:
Type | Description |
---|---|
CVSSData
|
Key CVSS metrics for the artifact. |
cvss_max: float
cached
property
Maximum CVSS score of all vulnerabilities affecting the artifact.
Returns:
Type | Description |
---|---|
float
|
Maximum CVSS score of all vulnerabilities affecting the artifact. |
name_with_digest: str
property
The name of the artifact with the first 15 characters of the SHA256 digest, mimicking the notation used in the web interface.
Returns:
Type | Description |
---|---|
str
|
The artifact's name in the form of |
name_with_digest_full: str
property
The name of the artifact with its full SHA256 digest.
Returns:
Type | Description |
---|---|
str
|
The artifact's name in the form of |
name_with_tag: str
property
The name of the artifact as denoted by its primary tag.
Returns:
Type | Description |
---|---|
str
|
The artifact's name in the form of |
project_name: str
property
The name of the project that the artifact belongs to.
Returns:
Type | Description |
---|---|
str
|
The name of the project that the artifact belongs to. |
repository_name: str
property
Name of the repository that the artifact belongs to.
Returns:
Type | Description |
---|---|
str
|
Name of the repository that the artifact belongs to. |
tags: List[str]
property
has_cve(cve_id)
has_description(description, case_sensitive=False)
Returns whether the artifact is affected by a vulnerability whose description contains the given string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
description |
str
|
The string to search for in vulnerability descriptions. |
required |
case_sensitive |
bool
|
Case sensitive matching |
False
|
Returns:
Type | Description |
---|---|
bool
|
Whether the artifact is affected by a vulnerability whose description contains the given string. |
Source code in harborapi/ext/artifact.py
has_package(package, case_sensitive=False, min_version=None, max_version=None)
Returns whether the artifact is affected by a vulnerability whose affected package matches the given string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package |
str
|
The name of the package to search for. |
required |
case_sensitive |
bool
|
Case sensitive matching |
False
|
min_version |
Optional[VersionType]
|
Minimum version of the package to match |
None
|
max_version |
Optional[VersionType]
|
Maximum version of the package to match |
None
|
Returns:
Type | Description |
---|---|
bool
|
Whether the artifact is affected by a vulnerability whose affected package matches the given string. |
Source code in harborapi/ext/artifact.py
has_tag(tag)
Returns whether the artifact has the given tag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tag |
str
|
The tag to search for. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the artifact has the given tag. |
Source code in harborapi/ext/artifact.py
vuln_with_cve(cve)
Returns the vulnerability with the specified CVE ID if the artifact is affected by it.
To just check if the artifact is affected by a given CVE, use has_cve()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cve |
str
|
The CVE ID of the vulnerability to return. Supports regular expressions. |
required |
Returns:
Type | Description |
---|---|
Optional[VulnerabilityItem]
|
The vulnerability with the specified CVE ID if it exists, otherwise |
Source code in harborapi/ext/artifact.py
vulns_with_package(package, case_sensitive=False)
Generator of all vulnerabilities whose affected package name contains the given string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package |
str
|
The name of the affected package to search for. Supports regular expressions. |
required |
case_sensitive |
bool
|
Case sensitive search, by default False |
False
|
Yields:
Type | Description |
---|---|
VulnerabilityItem
|
Vulnerability that affects the given package. |
Source code in harborapi/ext/artifact.py
vulns_with_description(description, case_sensitive=False)
Generator of all vulnerabilities whose description contains the given string. Optionally, the comparison can be case sensitive.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
description |
str
|
The string to search for in the vulnerability descriptions. Supports regular expressions. |
required |
case_sensitive |
Optional[bool]
|
Case sensitive comparison, by default False |
False
|
Yields:
Type | Description |
---|---|
VulnerabilityItem
|
A vulnerability whose description contains the given string. |
Source code in harborapi/ext/artifact.py
filter_artifacts_latest(artifacts, fallback=None)
async
Get the latest version of all artifacts from a list of ArtifactInfo objects.
Optionally takes a comparison function to fall back on if the push time of two artifacts are the same, or if one of the artifacts being compared doesn't have a push time.
Example
# Our comparison function used to determine which artifact is the latest
# (don't actually compare digests, use a better heuristic for your use case)
def compare_artifacts(latest_artifact, other_artifact):
# we know they have no push_time, so we compare digests
if latest_artifact.artifact.digest and other_artifact.artifact.digest:
return latest_artifact if latest_artifact.artifact.digest > other_artifact.artifact.digest else other_artifact
return latest_artifact # fallback if no digest
artifacts = await get_artifacts(client)
latest_artifacts = filter_artifacts_latest(artifacts, compare_artifacts)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
artifacts |
List[ArtifactInfo]
|
The list of artifacts to filter. |
required |
fallback |
Optional[Callable[[ArtifactInfo, ArtifactInfo], ArtifactInfo]]
|
Optional comparison function to use if one of the artifacts has no |
None
|
Returns:
Type | Description |
---|---|
List[ArtifactInfo]
|
A list of ArtifactInfo objects, with the latest artifact for each repository. |