microsoft / azure-devops-python-api

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

Connection module fails to load Resource Areas with the sps_url #401

Open smzelek opened 2 years ago

smzelek commented 2 years ago

https://developercommunity.visualstudio.com/t/Resource-Areas-REST-API-unavailable/1661030

The Resource Areas REST API used by the Python SDK is currently unavailable. The API returns the following error:

$ curl https://app.vssps.visualstudio.com/_apis/ResourceAreas
{"$id":"1","innerException":null,"message":"Service Unavailable","typeName":"Microsoft.VisualStudio.Services.Common.VssServiceException, Microsoft.VisualStudio.Services.Common","typeKey":"VssServiceException","errorCode":0,"eventId":3000}
The [Azure DevOps documentation](https://docs.microsoft.com/en-us/azure/devops/extend/develop/work-with-urls?view=azure-devops&tabs=http#how-to-get-an-organizations-url) lists a slightly different URL which also returns the same error:

$ curl https://dev.azure.com/_apis/resourceAreas
{"$id":"1","innerException":null,"message":"Service Unavailable","typeName":"Microsoft.VisualStudio.Services.Common.VssServiceException, Microsoft.VisualStudio.Services.Common","typeKey":"VssServiceException","errorCode":0,"eventId":3000}

This means that any connections instantiated with the sps_url fail to load the resource ids for clients like git_client, accounts_client, etc.

smzelek commented 2 years ago

We were able to implement a temporary workaround by monkey patching the Python SDK:

from azure.devops.connection import Connection, sps_url
from azure.devops.v5_1.location import ResourceAreaInfo

original_get_resource_areas = Connection._get_resource_areas

def _get_resource_areas(self, force=False):
    if self.base_url == sps_url:
        return [ResourceAreaInfo(id='')]
    return original_get_resource_areas(self, force=force)

Connection._get_resource_areas = _get_resource_areas

at the top-level of our API that uses this SDK, but an official fix would be preferable since this is a major use case.