def update_member(
        member_id: str,
        project_id: str,
        roles: list[str],
        **kwargs: Any,
    ) -> Member:
        """
        Update the role(s) of the specified member.

        Parameters
        ----------
        member_id : str
            Unique member identifier.
            For Service Account members, this is the Service Account ID.
            For User members, this is the unique User ID.
        project_id : str
            Unique ID of the project to update a member in.
        roles : list[str]
            List of new :ref:`roles <role_types>` for the specified member.
        **kwargs
            Arbitrary keyword arguments.
            See the :ref:`Configuration <configuration>` page.

        Returns
        -------
        member : Member
            Object representing the updated member.

        Examples
        --------
        >>> # Update a member's role to project.user.
        >>> member = dt.Project.update_member(
        ...     member_id='<MEMBER_ID>',
        ...     project_id='<PROJECT_ID>',
        ...     roles=[dt.Role.PROJECT_USER],
        ... )

        """

        # Construct URL
        url = '/projects/{}/members/{}'.format(
            project_id,
            member_id,
        )

        # Construct request body.
        body: dict = dict()
        if roles is not None:
            body['roles'] = ['roles/' + r for r in roles]

        # Return updated Member object of PATCH request response.
        return Member(
            dtrequests.DTRequest.patch(
                url=url,
                body=body,
                **kwargs,
            ))
    def add_member(
        project_id: str,
        email: str,
        roles: list[str],
        **kwargs: Any,
    ) -> Member:
        """
        Add a new member to the specified project.

        Parameters
        ----------
        project_id : str
            Unique ID of the project to add a member to.
        email : str
            User- or Service Account email address.
        roles : list[str]
            The :ref:`role(s) <role_types>` to provide the
            new member in the project.
        **kwargs
            Arbitrary keyword arguments.
            See the :ref:`Configuration <configuration>` page.

        Returns
        -------
        member : Member
            Object representing the newly added member.

        Examples
        --------
        >>> # Add a new member with the role project.developer.
        >>> member = dt.Project.add_member(
        ...     project_id='<PROJECT_ID>',
        ...     email='<MEMBER_EMAIL_ADDRESS>',
        ...     roles=[dt.Role.PROJECT_DEVELOPER],
        ... )

        """

        # Construct URL
        url = '/projects/{}/members'.format(project_id)

        # Construct request body.
        body: dict = dict()
        body['roles'] = ['roles/' + r for r in roles]
        body['email'] = email

        # Return Member object of POST request response.
        return Member(dtrequests.DTRequest.post(
            url=url,
            body=body,
            **kwargs,
        ))
Exemplo n.º 3
0
    def add_member(
        organization_id: str,
        email: str,
        roles: list[str],
        **kwargs: Any,
    ) -> Member:
        """
        Add a new member to the specified organization.

        Parameters
        ----------
        organization_id : str
            Unique ID of the organization to add a member to.
        email : str
            Email of the user or Service Account to be added.
        roles : {["organization.admin"]} list[str]
            The role(s) to provide the new member in the organization.
            Currently only supports organization.admin.
        **kwargs
            Arbitrary keyword arguments.
            See the :ref:`Configuration <configuration>` page.

        Returns
        -------
        member : Member
            Object representing the newly added member.

        Examples
        --------
        >>> # Add a new member to an organization.
        >>> member = dt.Organization.add_member(
        ...     organization_id='<ORGANIZATION_ID>',
        ...     email='<EMAIL_ADDRESS>',
        ...     roles=[dt.Role.ORGANIZATION_ADMIN],
        ... )

        """

        # Construct URL
        url = '/organizations/{}/members'.format(organization_id)

        # Construct request body.
        body: dict = dict()
        body['roles'] = ['roles/' + r for r in roles]
        body['email'] = email

        # Return Member object of POST request response.
        return Member(dtrequests.DTRequest.post(
            url=url,
            body=body,
            **kwargs,
        ))
    def get_member(
        member_id: str,
        project_id: str,
        **kwargs: Any,
    ) -> Member:
        """
        Get a single member in the specified project.

        Parameters
        ----------
        member_id : str
            Unique member identifier.
            For Service Account members, this is the Service Account ID.
            For User members, this is the unique User ID.
        project_id : str
            Unique ID of the project to get a member from.
        **kwargs
            Arbitrary keyword arguments.
            See the :ref:`Configuration <configuration>` page.

        Returns
        -------
        member : Member
            Object representing the member.

        Examples
        --------
        >>> # Fetch information about the specified member.
        >>> member = dt.Project.get_member(
        ...     member_id='<MEMBER_ID>',
        ...     project_id='<PROJECT_ID>',
        ... )

        """

        # Construct URL
        url = '/projects/{}/members/{}'.format(
            project_id,
            member_id,
        )

        # Return Member object of GET request response.
        return Member(dtrequests.DTRequest.get(
            url=url,
            **kwargs,
        ))
Exemplo n.º 5
0
    def get_member(
        member_id: str,
        organization_id: str,
        **kwargs: Any,
    ) -> Member:
        """
        Get a member from the specified organization.

        Parameters
        ----------
        member_id : str
            Unique ID of the member to get.
            For Service Account members, this is the Service Account ID.
            For User members, this is the unique User ID.
        organization_id : str
            Unique ID of the organization to get a member from.
        **kwargs
            Arbitrary keyword arguments.
            See the :ref:`Configuration <configuration>` page.

        Returns
        -------
        member : Member
            Object representing the member.

        Examples
        --------
        >>> # Fetch information about a specific member in an organization.
        >>> org = dt.Organization.get_organization(
        ...     member_id='<MEMBER_ID>',
        ...     organization_id='<ORGANIZATION_ID>',
        ... )

        """

        # Construct URL
        url = '/organizations/{}/members/{}'.format(
            organization_id,
            member_id,
        )

        # Return Member object of GET request response.
        return Member(dtrequests.DTRequest.get(
            url=url,
            **kwargs,
        ))
    def list_members(
        project_id: str,
        **kwargs: Any,
    ) -> list[Member]:
        """
        Gets a list of all members in a project.

        Parameters
        ----------
        project_id : str
            Unique ID of the project to get members from.
        **kwargs
            Arbitrary keyword arguments.
            See the :ref:`Configuration <configuration>` page.

        Returns
        -------
        members : list[Member]
            List of objects each representing a member.

        Examples
        --------
        >>> # List all members in a project.
        >>> members = dt.Project.list_members('<PROJECT_ID>')

        """

        # Construct URL
        url = '/projects/{}/members'.format(project_id)

        # Return list of Member objects of paginated GET response.
        members = dtrequests.DTRequest.paginated_get(
            url=url,
            pagination_key='members',
            **kwargs,
        )
        members_list: list[Member] = [Member(m) for m in members]
        return members_list
Exemplo n.º 7
0
    def list_members(
        organization_id: str,
        **kwargs: Any,
    ) -> list[Member]:
        """
        Gets a list of all members in an organization.

        Parameters
        ----------
        organization_id : str
            Unique ID of the organization to get members from.
        **kwargs
            Arbitrary keyword arguments.
            See the :ref:`Configuration <configuration>` page.

        Returns
        -------
        members : list[Member]
            List of objects each representing a member.

        Examples
        --------
        >>> # Fetch information about all members in an organization.
        >>> members = dt.Organization.list_members('<ORGANIZATION_ID>')

        """

        # Construct URL
        url = '/organizations/{}/members'.format(organization_id)

        # Return list of Member objects of paginated GET response.
        members = dtrequests.DTRequest.paginated_get(
            url=url,
            pagination_key='members',
            **kwargs,
        )
        return [Member(m) for m in members]