Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to manage group's users on Artifactory SaaS #431

Open
vittoriocanilli opened this issue Aug 31, 2023 · 1 comment
Open

Unable to manage group's users on Artifactory SaaS #431

vittoriocanilli opened this issue Aug 31, 2023 · 1 comment
Labels
Bug Help Wanted We will be glad if somebody proposes a solution via PR

Comments

@vittoriocanilli
Copy link

vittoriocanilli commented Aug 31, 2023

I am using Artifactory SaaS and I am trying to create a group with users as specified in the documentation:

from artifactory import ArtifactorySaaSPath
from dohq_artifactory import Group

artifactory_ = ArtifactorySaaSPath(
                'https://mycompany.jfrog.io/artifactory',
                apikey='myApiKey123'
            )

group = artifactory_.find_group("groupname")

if group is None:
    group = Group(artifactory_, "groupname")
    group.create()

group.read()

group.users = ["admin", "anonymous"]
group.create()

The group is created but it has no user as members. I have found this working alternative though:

from artifactory import ArtifactorySaaSPath
from dohq_artifactory import Group

artifactory_ = ArtifactorySaaSPath(
                'https://mycompany.jfrog.io/artifactory',
                apikey='myApiKey123'
            )

group = artifactory_.find_group("groupname")

if group is None:
    group = Group(artifactory_, "groupname")
    group.create()

group.read()

for user in ["admin", "anonymous"]:
  user = artifactory_.find_user(user)
  user.add_to_group(group)
  user.update()

But then I have the same problem again if I want to delete all group members:

from artifactory import ArtifactorySaaSPath
from dohq_artifactory import Group

artifactory_ = ArtifactorySaaSPath(
                'https://mycompany.jfrog.io/artifactory',
                apikey='myApiKey123'
            )

group = artifactory_.find_group("groupname")

if group is None:
    group = Group(artifactory_, "groupname")
    group.create()

group.read()

group.users = []
group.update() # group.create() has the same effect

The previously added users are not removed. I set every time group.users as a list, as required by the source code, but that does not seem to work.

Has somebody else had the same issue? I am currently using dohq-artifactory 0.9.0. Thanks in advance

@allburov allburov added Bug Help Wanted We will be glad if somebody proposes a solution via PR labels Sep 4, 2023
@PatriceG
Copy link

PatriceG commented Dec 12, 2024

Hi,
We have the same issue.
This is because the _create_json and _read_response method are not using the right attributes for the list of group members.
this should be "userNames".

I'm considering to contribute the fix via a pull request.
However in the meantime, I've fixed it by subclassing the Group class in my app, with GroupFixed.
With the content below.
I also implemented a method to create a GroupFixed from the Group instance returned by the find method (in order to be able to modify the group members.
This is a quick and dirty hack until the lib is fixed.


def create_groupfixed_from_group(group):
                """
                This method creates a GroupFixed object from a Group object.
                This is meant to be a TEMPORARY FIX until the Group class in the lib is fixed.
                """
                groupFixed = GroupFixed(group._artifactory, group.name)
                groupFixed.description = group.description
                groupFixed.auto_join = group.auto_join
                groupFixed.external = group.external
                groupFixed.new_user_default = group.new_user_default
                groupFixed.realm = group.realm
                groupFixed.users = group.users
                return groupFixed

class GroupFixed(Group):
        """
        This is a subclass of Group that fixes the fact that the user members are not set (the wrong json attribute is sent)        
        This should be replaced by a fixed version of Group once the lib is fixed
        """
        def __init__(self, artifactory, name):
                super(GroupFixed, self).__init__(artifactory,name)
                
        
        ##we're overriding the 2 following methods and replacing the usersInGroup attribute by userNames
        def _create_json(self):
                """
                JSON Documentation: https://www.jfrog.com/confluence/display/RTF/Security+Configuration+JSON
                """
                data_json = {
                "name": self.name,
                "description": self.description,
                "autoJoin": self.auto_join,
                "external": self.external,
                "newUserDefault": self.new_user_default,
                "realm": self.realm,
                }

                if isinstance(self.users, list):
                        data_json.update({"userNames": self.users})

                return data_json

        def _read_response(self, response):
                """
                JSON Documentation: https://www.jfrog.com/confluence/display/RTF/Security+Configuration+JSON
                """
                self.name = response.get("name")
                self.description = response.get("description")
                self.auto_join = response.get("autoJoin")
                self.realm = response.get("realm")
                self.realm_attributes = response.get("realmAttributes")
                self.external = response.get("external")
                self.new_user_default = response.get("newUserDefault")
                self.users = response.get("userNames")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Help Wanted We will be glad if somebody proposes a solution via PR
Development

No branches or pull requests

3 participants