devopshq / artifactory

dohq-artifactory: a Python client for Artifactory
https://devopshq.github.io/artifactory/
MIT License
273 stars 144 forks source link

Incorrect Docker API Version #333

Closed jfining closed 2 years ago

jfining commented 2 years ago

When retrieving an existing docker respository with V2 enabled, there is a mismatch in Repository.docker_api_version and Repository.raw["dockerApiVersion"].

For example, create a new docker repository in the artifactory web console with V2 enabled. Then:

Retrieve the repository and enumerate the object's properties:

repo = artifactory_.find_repository("james-test")
print("raw_docker_version", repo.raw["dockerApiVersion"])
print("object_property_docker_version", repo.docker_api_version)

You'll see something like this:

raw_docker_version V2 object_property_docker_version V1

If you update the repo using repo.update() the result is that repo.docker_api_version is used and the repository is incorrectly changed to V1. https://github.com/devopshq/artifactory/blob/0.8.0/dohq_artifactory/admin.py#L771

I believe the culprit is the init function of RepositoryLocal sets the version to V1: https://github.com/devopshq/artifactory/blob/0.8.0/dohq_artifactory/admin.py#L734

And then _read_response does not grab the real value from the API response: https://github.com/devopshq/artifactory/blob/0.8.0/dohq_artifactory/admin.py#L791

So the default value of V1 is always used.

Solution:

I propose the _read_response function should be changed to also update self.docker_api_version using the value from the api response.