diff --git a/pritunl_api/utils/query.py b/pritunl_api/utils/query.py index 51038e3..b160de7 100644 --- a/pritunl_api/utils/query.py +++ b/pritunl_api/utils/query.py @@ -1,21 +1,28 @@ def org_user(pritunl, org_name, user_name=None): - def __get_org_by_name(orgs_obj, org_name): - for org in orgs_obj: - if org['name'] == org_name: - return org - return None + """ + Retrieve an organization and optionally a user from Pritunl. - def __get_user_by_name(users_obj, user_name): - for user in users_obj: - if user["name"] == user_name: - return user - return None + Args: + pritunl (object): Pritunl API client + org_name (str): Name of the organization + user_name (str, optional): Name of the user. If not provided, returns all users in the organization. - org = __get_org_by_name(pritunl.organization.get(), org_name) - user = pritunl.user.get(org_id=org['id']) + Returns: + tuple: (org, user) where org is the organization object and user is the user object or a list of user objects - if user_name: - user = __get_user_by_name(pritunl.user.get(org_id=org['id']), user_name) - return org, user + Notes: + If user_name is provided, returns the user object if found, otherwise returns None. + If user_name is not provided, returns a list of all user objects in the organization. + """ + def __get_by_name(objs, name): + for obj in objs: + if obj['name'] == name: + return obj + return None + org = next((org for org in pritunl.organization.get() if org['name'] == org_name), None) + if user_name: + user = next((user for user in pritunl.user.get(org_id=org['id']) if user['name'] == user_name), None) + else: + user = pritunl.user.get(org_id=org['id']) # Return all users return org, user diff --git a/pyproject.toml b/pyproject.toml index ac1e536..280c75b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pritunl-api" -version = "1.1.11" +version = "1.1.12" description = "Pritunl API Client for Python" authors = ["Nathaniel Varona "] license = "MIT"