microsoft / azure-devops-python-api

Azure DevOps Python API
https://docs.microsoft.com/azure/devops/integrate/index?view=azure-devops
MIT License
578 stars 198 forks source link

list_groups() documentation unclear, as is the REST API related to it. #346

Open FilBot3 opened 4 years ago

FilBot3 commented 4 years ago

In this section:

which has this blob of code:

    def list_groups(self, scope_descriptor=None, subject_types=None, continuation_token=None):
        """ListGroups.
        [Preview API] Gets a list of all groups in the current scope (usually organization or account).
        :param str scope_descriptor: Specify a non-default scope (collection, project) to search for groups.
        :param [str] subject_types: A comma separated list of user subject subtypes to reduce the retrieved results, e.g. Microsoft.IdentityModel.Claims.ClaimsIdentity
        :param str continuation_token: An opaque data blob that allows the next page of data to resume immediately after where the previous page ended. The only reliable way to know if there is more data left is the presence of a continuation token.
        :rtype: :class:`<PagedGraphGroups> <azure.devops.v5_1.graph.models.PagedGraphGroups>`
        """

what is actually meant by these pieces and where should I find that information? The REST API docs dont' really tell much and aren't much help either.

FilBot3 commented 4 years ago

Here is how I figured it out, but the documentation needs to be a bit more clear. This was through much trial and error.

"""List and Sort Groups in Azure DevOps Project
"""

import configparser
import logging
import os
import pprint as pp
# import json
from azure.devops.connection import Connection  # pylint: disable=import-error
from msrest.authentication import BasicAuthentication  # pylint: disable=import-error

def login_bits() -> Connection:
    """Just does login precursor bits.
    """
    if os.environ.get('AZDO_LOG'):
        logging.basicConfig(level=logging.DEBUG)

    if 'AZDO_PAT' in os.environ and 'AZDO_ORG' in os.environ:
        azdo_pat = os.environ.get('AZDO_PAT')
        ado_org_url = os.environ.get('AZDO_ORG')
    else:
        logging.info('Attempting to read ${HOME}/.local/azdo_config.ini')
        azdo_config = configparser.ConfigParser()
        azdo_config.read(os.environ.get('HOME') + '/.local/azdo_config.ini')
        azdo_pat = azdo_config['auth']['pat']
        ado_org_url = azdo_config['org']['name']

    credentials = BasicAuthentication('', azdo_pat)
    connection = Connection(base_url=ado_org_url, creds=credentials)

    return connection

def main():
    """Main
    """
    # Create a Core Client. This gives us access to the Projects API.
    core_client = login_bits().clients_v5_1.get_core_client()

    # We'll get the Project's information.
    project_info = core_client.get_project(project_id='dudleyp',
                                           include_capabilities=True)

    # Create a Graph Client.
    graph_client = login_bits().clients_v5_1.get_graph_client()

    # Get the descriptor for the project, since it's not in the actual Project
    # information originally retrieved.
    project_response = graph_client.get_descriptor(storage_key=project_info.id)

    # Get a list of all our groups for this Project we got the descriptor for.
    graph_response = graph_client.list_groups(
        scope_descriptor=project_response.value)

    # print it.
    pp.pprint(graph_response.graph_groups[0].display_name)

if __name__ == '__main__':
    main()