vendor_fabric.google.workspace

Google Workspace (Admin Directory) operations.

This module provides operations for managing Google Workspace users and groups through the Admin Directory API.

Module Contents

Classes

GoogleWorkspaceMixin

Mixin providing Google Workspace operations.

API

class vendor_fabric.google.workspace.GoogleWorkspaceMixin

Mixin providing Google Workspace operations.

This mixin requires the base GoogleConnector class to provide:

  • get_admin_directory_service()

  • get_service()

  • logger

list_workspace_users(domain: str | None = None, max_results: int = 500, unhump_users: bool = False, subject: str | None = None) extended_data.containers.ExtendedList[extended_data.containers.ExtendedDict]

List users from Google Workspace.

Args: domain: Optional domain to filter users. max_results: Maximum results per page. Defaults to 500. unhump_users: Convert keys to snake_case. Defaults to False. subject: Email to impersonate for domain-wide delegation.

Returns: List of user dictionaries.

get_user(user_key: str, subject: str | None = None) extended_data.containers.ExtendedDict | None

Get a specific user from Google Workspace.

Args: user_key: Email or unique ID of the user. subject: Email to impersonate for domain-wide delegation.

Returns: User dictionary or None if not found.

create_user(primary_email: str, given_name: str, family_name: str, password: str | None = None, change_password_at_next_login: bool = True, org_unit_path: str = '/', subject: str | None = None, **additional_fields: Any) extended_data.containers.ExtendedDict

Create a user in Google Workspace.

Args: primary_email: Primary email address. given_name: First name. family_name: Last name. password: Initial password. Generated if not provided. change_password_at_next_login: Force password change. Defaults to True. org_unit_path: Organizational unit path. Defaults to ‘/’. subject: Email to impersonate for domain-wide delegation. **additional_fields: Additional user fields.

Returns: Created user dictionary.

update_user(user_key: str, subject: str | None = None, **fields: Any) extended_data.containers.ExtendedDict

Update a user in Google Workspace.

Args: user_key: Email or unique ID of the user. subject: Email to impersonate for domain-wide delegation. **fields: Fields to update.

Returns: Updated user dictionary.

delete_user(user_key: str, subject: str | None = None) None

Delete a user from Google Workspace.

Args: user_key: Email or unique ID of the user. subject: Email to impersonate for domain-wide delegation.

list_workspace_groups(domain: str | None = None, max_results: int = 200, unhump_groups: bool = False, subject: str | None = None) extended_data.containers.ExtendedList[extended_data.containers.ExtendedDict]

List groups from Google Workspace.

Args: domain: Optional domain to filter groups. max_results: Maximum results per page. Defaults to 200. unhump_groups: Convert keys to snake_case. Defaults to False. subject: Email to impersonate for domain-wide delegation.

Returns: List of group dictionaries.

get_group(group_key: str, subject: str | None = None) extended_data.containers.ExtendedDict | None

Get a specific group from Google Workspace.

Args: group_key: Email or unique ID of the group. subject: Email to impersonate for domain-wide delegation.

Returns: Group dictionary or None if not found.

create_group(email: str, name: str, description: str = '', subject: str | None = None) extended_data.containers.ExtendedDict

Create a group in Google Workspace.

Args: email: Group email address. name: Display name. description: Group description. subject: Email to impersonate for domain-wide delegation.

Returns: Created group dictionary.

delete_group(group_key: str, subject: str | None = None) None

Delete a group from Google Workspace.

Args: group_key: Email or unique ID of the group. subject: Email to impersonate for domain-wide delegation.

list_group_members(group_key: str, roles: list[str] | None = None, unhump_members: bool = False, subject: str | None = None) extended_data.containers.ExtendedList[extended_data.containers.ExtendedDict]

List members of a Google Workspace group.

Args: group_key: Email or unique ID of the group. roles: Filter by roles (OWNER, MANAGER, MEMBER). Defaults to all. unhump_members: Convert keys to snake_case. Defaults to False. subject: Email to impersonate for domain-wide delegation.

Returns: List of member dictionaries.

add_group_member(group_key: str, email: str, role: str = 'MEMBER', subject: str | None = None) extended_data.containers.ExtendedDict

Add a member to a Google Workspace group.

Args: group_key: Email or unique ID of the group. email: Email of the member to add. role: Member role (OWNER, MANAGER, MEMBER). Defaults to MEMBER. subject: Email to impersonate for domain-wide delegation.

Returns: Created member dictionary.

remove_group_member(group_key: str, member_key: str, subject: str | None = None) None

Remove a member from a Google Workspace group.

Args: group_key: Email or unique ID of the group. member_key: Email or unique ID of the member. subject: Email to impersonate for domain-wide delegation.

list_org_units(org_unit_path: str = '/', org_unit_type: str = 'all', subject: str | None = None) extended_data.containers.ExtendedList[extended_data.containers.ExtendedDict]

List organizational units in Google Workspace.

Args: org_unit_path: Parent org unit path. Defaults to ‘/’. org_unit_type: Type filter (all, children, allIncludingParent). subject: Email to impersonate for domain-wide delegation.

Returns: List of org unit dictionaries.

create_or_update_user(primary_email: str, given_name: str, family_name: str, password: str | None = None, update_if_exists: bool = False, change_password_at_next_login: bool = True, org_unit_path: str = '/', subject: str | None = None, **additional_fields: Any) extended_data.containers.ExtendedDict

Create or update a user in Google Workspace.

This method provides terraform-style idempotent user management. If update_if_exists is True and the user exists, it updates instead of failing.

Args: primary_email: Primary email address. given_name: First name. family_name: Last name. password: Initial password. Generated if not provided. update_if_exists: If True, update existing user instead of failing. change_password_at_next_login: Force password change. Defaults to True. org_unit_path: Organizational unit path. Defaults to ‘/’. subject: Email to impersonate for domain-wide delegation. **additional_fields: Additional user fields.

Returns: Created or updated user dictionary.

create_or_update_group(email: str, name: str, description: str = '', update_if_exists: bool = False, subject: str | None = None, **additional_fields: Any) extended_data.containers.ExtendedDict

Create or update a group in Google Workspace.

This method provides terraform-style idempotent group management. If update_if_exists is True and the group exists, it updates instead of failing.

Args: email: Group email address. name: Display name. description: Group description. update_if_exists: If True, update existing group instead of failing. subject: Email to impersonate for domain-wide delegation. **additional_fields: Additional group fields.

Returns: Created or updated group dictionary.

list_available_licenses(customer_id: str = 'my_customer', product_id: str | None = None, subject: str | None = None) extended_data.containers.ExtendedList[extended_data.containers.ExtendedDict]

List available Google Workspace licenses.

Args: customer_id: Customer ID. Defaults to ‘my_customer’. product_id: Filter by product (e.g., ‘Google-Apps’, ‘Google-Vault’). subject: Email to impersonate for domain-wide delegation.

Returns: List of license dictionaries.

get_license_summary(customer_id: str = 'my_customer', subject: str | None = None) extended_data.containers.ExtendedDict

Get a summary of license usage by product.

Args: customer_id: Customer ID. Defaults to ‘my_customer’. subject: Email to impersonate for domain-wide delegation.

Returns: Dictionary mapping product IDs to usage counts.