gitlab_users.services

Unified service for all GitLab users and groups operations. This module provides a service class for managing GitLab users and groups, including listing, creating, deleting users, and managing groups.

Classes

GitLabService([gitlab_id])

Service for interacting with GitLab users, groups, and related operations.

class GitLabService(gitlab_id: str | None = None)

Service for interacting with GitLab users, groups, and related operations.

list_users() list[User]

List all users on the GitLab instance.

Returns:

A list of User objects representing all users.

create_user(username: str, email: str, name: str, **kwargs) User

Create a new user.

Parameters:
  • username – Username.

  • email – Email address.

  • name – Full name.

  • **kwargs – Other GitLab user fields.

Returns:

The created user.

delete_user(user_id: int, hard_delete: bool = False) None

Delete a user by ID.

Parameters:
  • user_id – User ID.

  • hard_delete – If True, hard delete the user.

get_user_by_username(username: str) User

Get a user by their username.

Parameters:

username – The username of the user to retrieve.

Returns:

The user object with ID, username, email, name, and state.

Raises:

ValueError – If the user with the given username does not exist.

list_groups() list[Group]

List all groups on the GitLab instance.

Returns:

A list of Group objects.

get_group_by_id(group_id: int) Group

Get a group by its ID.

Returns:

The group object with ID, name, and path.

delete_user_from_group(group: Group, user: User, hard_delete: bool = False)

Remove a user from a group.

Parameters:
  • group – The group from which to remove the user.

  • user – The user to remove.

  • hard_delete – If True, permanently delete the user from the group.

export_ssh_keys(user: User) list[str]

Export SSH keys of a user.

Parameters:

user – The user whose SSH keys to export.

Returns:

A list of SSH keys for the user.