posit-dev / posit-sdk-py

Posit SDK for Python
MIT License
7 stars 3 forks source link

Implement `groups` functions to compliment `users` #178

Open kmasiello opened 4 months ago

kmasiello commented 4 months ago

For:

client = connect.Client()

Enable group find / get functionality similar to what is enabled for users, i.e.,

user_guids = pl.DataFrame(client.users.find()).select(["username","guid"])
group_guids = pl.DataFrame(client.groups.find()).select(["name","guid"])
tnederlof commented 3 months ago

It would be helpful to have a built in way to lookup by group name since this is pretty common. Here is the Python code I wrote to do this in a recipe with the SDK as in if its helpful...

group_guid = ""
group_name = "GROUP_NAME_HERE"

if not group_guid and group_name:
    group_match = client.get("/v1/groups", params={"prefix": group_name}).json()
    if not group_match["results"]:
        raise Exception("Invalid group name")
    elif len(group_match["results"]) != 1:
        raise Exception("More than one group name found, ensure you enter a unique name")
    else:
        group_guid = group_match["results"][0]["guid"]
        print(group_guid)
elif not group_name: 
    raise Exception("Either group_guid or group_name must be specified")