def get_client(personal_access_token, base_url): """Get a client for interacting with devops :param str http_method: GET/POST :param str url: The request target url :param dict headers: Any headers to add to the request. :param content: Any body data to add to the request. """ config = Configuration(base_url) VERSION = "6.0.0b2" config.add_user_agent('azure-devops/{}'.format(VERSION)) config.additional_headers = {} creds = BasicAuthentication('', personal_access_token) client = ServiceClient(creds, config=config) return client
def search_extensions(search_query): """ Search extensions from marketplace """ from msrest.universal_http import ClientRequest from msrest.service_client import ServiceClient from msrest import Configuration from azext_devops.version import VERSION config = Configuration(base_url=None) config.add_user_agent('devOpsCli/{}'.format(VERSION)) client = ServiceClient(creds=None, config=config) request = ClientRequest( method='POST', url= 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery' ) search_request = { 'assetTypes': [ 'Microsoft.VisualStudio.Services.Icons.Default', 'Microsoft.VisualStudio.Services.Icons.Branding', 'Microsoft.VisualStudio.Services.Icons.Small' ], 'filters': [{ 'criteria': [{ 'filterType': 8, 'value': 'Microsoft.VisualStudio.Services' }, { 'filterType': 8, 'value': 'Microsoft.VisualStudio.Services.Integration' }, { 'filterType': 8, 'value': 'Microsoft.VisualStudio.Services.Cloud' }, { 'filterType': 8, 'value': 'Microsoft.TeamFoundation.Server' }, { 'filterType': 8, 'value': 'Microsoft.TeamFoundation.Server.Integration' }, { 'filterType': 8, 'value': 'Microsoft.VisualStudio.Services.Cloud.Integration' }, { 'filterType': 8, 'value': 'Microsoft.VisualStudio.Services.Resource.Cloud' }, { 'filterType': 10, 'value': search_query }, { 'filterType': 12, 'value': '37888' }], 'direction': 2, 'pageSize': 50, 'pageNumber': 1, 'sortBy': 0, 'sortOrder': 0, 'pagingToken': None }], 'flags': 870 } headers = { 'Content-Type': 'application/json' + '; charset=utf-8', 'Accept': 'application/json' + ';api-version=' + '5.0-preview.1' } response = client.send(request=request, headers=headers, content=search_request) response_json = response.json() return response_json['results'][0]['extensions']