anancarv / python-artifactory

Typed interactions with the Jfrog Artifactory REST API
MIT License
60 stars 51 forks source link

Update existing virtual repo #44

Closed EslamElHusseiny closed 4 years ago

EslamElHusseiny commented 4 years ago

Hi,

I'm trying to use pyartifactory to update an existing virtual repo, but it seems like the update isn't straightforward.

so I've tried to find the repo first and update the properties but seems like the returned type of art.repositories.get_virtual_repo() is VirtualRepositoryResponse and art.repositories.update_virtual_repo requires an input of type VirtualRepository and there is no straightforward method to convert the VirtualRepositoryResponse to VirtualRepository or copy the properties over to avoid any undesirable changes!

creating a VirtualRepository object via pyartifactory.models.VirtualRepository(key="test-virtual") creates the required input for the update but a) with defaults that could be different than the config of existing repo b) surprisingly, creates the object with rclass of type 'rclass' <RClassEnum.local: 'local'> eg.

In [96]: from pyartifactory.models import VirtualRepository
In [97]: VirtualRepository(key='test').dict()
Out[97]:
{'key': 'test',
 'rclass': <RClassEnum.local: 'local'>,
 'packageType': <PackageTypeEnum.generic: 'generic'>,
 'description': None,
 'notes': None,
 'includesPattern': '**/*',
 'excludesPattern': '',
 'repoLayoutRef': 'maven-2-default',
 'repositories': None,
 'artifactoryRequestsCanRetrieveRemoteArtifacts': False,
 'debianTrivialLayout': False,
 'keyPair': None,
 'pomRepositoryReferencesCleanupPolicy': <PomRepoRefCleanupPolicy.discard_active_reference: 'discard_active_reference'>,
 'defaultDeploymentRepo': None,
 'forceMavenAuthentication': False,
 'externalDependenciesEnabled': False,
 'externalDependenciesPatterns': None,
 'externalDependenciesRemoteRepo': None}
anancarv commented 4 years ago

Hi @EslamElHusseiny ,

Thanks for your feedback :smiley:

  1. For updating an existing virtual repository, you can do the following:

    # For updating the description for example
    virtual_repo = art.repositories.get_virtual_repo("test")
    virtual_repo.description = "test repo"
    updated_virtual_repo = art.repositories.update_virtual_repo(virtual_repo)
  2. Virtual repo creation By default, if you create a repository without expliciting its type (rclass), it will be local (rclass=local). So for creating a virtual repo, you'll have to do the following:

    from pyartifactory.models import  VirtualRepository
    virtual_repo = VirtualRepository(key="test_virtual_repo", rclass="virtual")
    new_virtual_repo = art.repositories.create_virtual_repo(virtual_repo)

    Thanks for pointing out this issue, it will be fixed very soon in the release :thumbsup:

EslamElHusseiny commented 4 years ago

Hi @anancarv Thanks a lot for your prompt response!

I've tried the above example of updating an existing repo and unfortunately, I couldn't find the repositories property in the response of art.repositories.get_virtual_repo("test") which is the property I'm trying to update 🤷‍♂

anancarv commented 4 years ago

I found the issue. In the model definition, VirtualRepositoryResponse inherits from LocalRepository instead of VirtualRepository. That's why you're misssing the property repositories that is only visible for virtual repositories.

Thanks again for this issue. I'll do a PR ASAP to fix it

anancarv commented 4 years ago

@EslamElHusseiny , A new release of pyartifactory v1.3.1 is available that fixes both the virtual repositories issue and the rclass one while creating virtual and/or remote repositories. Please let me know if you're still facing issues

anancarv commented 4 years ago

Hi @EslamElHusseiny , A new release of pyartifactory is available (v1.4.0) with generic methods get_repo, create_repo & update_repo. With this new version, you'll no longer have to bother with the repository since it is automatically detected 😉. I'll be glad to have a feedback from you for this new feature.