unioslo / harborapi

Python async client for the Harbor REST API v2.0.
https://unioslo.github.io/harborapi/
MIT License
28 stars 6 forks source link

Bake `ext.api.get_artifact_vulnerabilities` into `ext.api.get_artifacts` #11

Open pederhan opened 1 year ago

pederhan commented 1 year ago

The two functions ext.api.get_artifacts and ext.api.get_artifact_vulnerabilities do more or less the same thing, except the latter also fetches the Harbor vulnerability report for the artifacts and populates the report field of the resulting ArtifactInfo objects.

They also operate on somewhat different resources; ext.api.get_artifacts can take a list of Projects or Repositories, while ext.api.get_artifact_vulnerabilities can only take a list of Projects.

Having two similar functions who have differing APIs (Project/Repos vs only Projects), where one directly calls the other is convoluted and inconsistent.

get_artifacts

https://github.com/pederhan/harborapi/blob/6b4e9f9c3fdf233819af0e33d862c63607f9f283/harborapi/ext/api.py#L245-L247

get_artifact_vulnerabilites

https://github.com/pederhan/harborapi/blob/6b4e9f9c3fdf233819af0e33d862c63607f9f283/harborapi/ext/api.py#L322-L329

Solution

We can add with_report as an optional parameter to ext.api.get_artifacts, where the reports are fetched if this parameter is True. By implementing the code found in ext.api.get_artifact_vulnerabilities, we can combine the functionality of both functions into a single function.