devopshq / artifactory

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

Patterns for PermissionTarget #434

Open vittoriocanilli opened 8 months ago

vittoriocanilli commented 8 months ago

I need to create a permission target with a repository and an include pattern; I have found out that the pattern can not be defined in the PermissionTarget.add_repository() function, but I had to set the pattern in the constructor of the permission target; I found it quite different from the UI experience on Artifactory, but it worked at least till September of this year.

Unfortunately it does not work anymore: when I create a new permission target, it comes out with no pattern at all, either if I pass it to the constructor or not: I mean that even the default ** include pattern is not set, which results to an useless permission target. Here is my code's snippet:

connection = ArtifactorySaaSPath(
    'https://mycompany.jfrog.io' + '/artifactory',
    apikey=`1234567890`
)

perm_target = PermissionTarget(
    connection,
    `my_permission_target`,
    includes_pattern='@mycompany-myproject/**'
)
perm_target.create()

I am using the latest version of the library, which is currently 0.9.1. Thanks in advance!

vittoriocanilli commented 7 months ago

As workaround I have stopped using the PermissionTarget.add_repository() to add the repository to an existing permission target and instead I set both the repository and the include pattern when I create the permission template:

connection = ArtifactorySaaSPath(
    'https://mycompany.jfrog.io' + '/artifactory',
    apikey=`1234567890`
)

repos_names = 'repo1,repo2,repo3'
repos_list = repos_names.split(',')
repos_obj_list = []

for repo in repos_list:
    repos_obj_list.append(connection.find_repository_local(repo))

perm_target = PermissionTarget(
    connection,
    `my_permission_target`,
    repositories=repos_obj_list,
    includes_pattern='@mycompany-myproject/**'
)
perm_target.create()

It works both with the library's version 0.9.1 and 0.9.2. Nevertheless it is just a workaround and I think that a properly documented solution is still needed.