Skip to content

Commit 133bccf

Browse files
authored
Merge pull request #216 from microsoft/dev
M151 clients and other minor fixes
2 parents b5db5ac + 0cd4ff7 commit 133bccf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1015
-978
lines changed

azure-devops/azure/devops/client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def add_user_agent(self, user_agent):
4646
if user_agent is not None:
4747
self.config.add_user_agent(user_agent)
4848

49-
def _send_request(self, request, headers=None, content=None, **operation_config):
49+
def _send_request(self, request, headers=None, content=None, media_type=None, **operation_config):
5050
"""Prepare and send request object according to configuration.
5151
:param ClientRequest request: The request object to be sent.
5252
:param dict headers: Any headers to add to the request.
@@ -57,10 +57,13 @@ def _send_request(self, request, headers=None, content=None, **operation_config)
5757
or (TRACE_ENV_VAR_COMPAT in os.environ and os.environ[TRACE_ENV_VAR_COMPAT] == 'true'):
5858
print(request.method + ' ' + request.url)
5959
logger.debug('%s %s', request.method, request.url)
60-
logger.debug('Request content: %s', content)
60+
if media_type is not None and media_type == 'application/json':
61+
logger.debug('Request content: %s', content)
6162
response = self._client.send(request=request, headers=headers,
6263
content=content, **operation_config)
63-
logger.debug('Response content: %s', response.content)
64+
if ('Content-Type' in response.headers
65+
and response.headers['Content-Type'].startswith('application/json')):
66+
logger.debug('Response content: %s', response.content)
6467
if response.status_code < 200 or response.status_code >= 300:
6568
self._handle_error(request, response)
6669
return response
@@ -94,7 +97,7 @@ def _send(self, http_method, location_id, version, route_values=None,
9497
headers['X-VSS-ForceMsaPassThrough'] = 'true'
9598
if Client._session_header_key in Client._session_data and Client._session_header_key not in headers:
9699
headers[Client._session_header_key] = Client._session_data[Client._session_header_key]
97-
response = self._send_request(request=request, headers=headers, content=content)
100+
response = self._send_request(request=request, headers=headers, content=content, media_type=media_type)
98101
if Client._session_header_key in response.headers:
99102
Client._session_data[Client._session_header_key] = response.headers[Client._session_header_key]
100103
return response

azure-devops/azure/devops/connection.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from .v5_0.client_factory import ClientFactoryV5_0
1515
from .v5_1.client_factory import ClientFactoryV5_1
1616

17-
1817
logger = logging.getLogger(__name__)
1918

2019

@@ -75,10 +74,25 @@ def _get_url_for_client_instance(self, client_class):
7574
for resource_area in resource_areas:
7675
if resource_area.id.lower() == resource_id.lower():
7776
return resource_area.location_url
77+
78+
# Check SPS deployment level for the resource area
79+
resource_area = self._get_deployment_resource_area_from_sps(resource_id)
80+
if resource_area is not None:
81+
return resource_area.location_url
82+
7883
raise AzureDevOpsClientRequestError(('Could not find information for resource area {id} '
7984
+ 'from server: {url}').format(id=resource_id,
8085
url=self.base_url))
8186

87+
def _get_deployment_resource_area_from_sps(self, resource_id):
88+
resource_id = resource_id.lower()
89+
if resource_id in _deployment_level_resource_areas:
90+
return _deployment_level_resource_areas[resource_id]
91+
location_client = LocationClient(sps_url, self._creds)
92+
resource_area = location_client.get_resource_area(area_id=resource_id)
93+
_deployment_level_resource_areas[resource_id] = resource_area
94+
return resource_area
95+
8296
def authenticate(self):
8397
self._get_resource_areas(force=True)
8498

@@ -110,3 +124,7 @@ def _get_resource_areas(self, force=False):
110124
@staticmethod
111125
def _combine_url(part1, part2):
112126
return part1.rstrip('/') + '/' + part2.strip('/')
127+
128+
129+
_deployment_level_resource_areas = {}
130+
sps_url = 'https://app.vssps.visualstudio.com'

azure-devops/azure/devops/released/profile/profile_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, base_url=None, creds=None):
2323
self._serialize = Serializer(client_models)
2424
self._deserialize = Deserializer(client_models)
2525

26-
resource_area_identifier = None
26+
resource_area_identifier = '8ccfef3d-2b87-4e99-8ccb-66e343d2daa8'
2727

2828
def get_profile(self, id, details=None, with_attributes=None, partition=None, core_attributes=None, force_refresh=None):
2929
"""GetProfile.

azure-devops/azure/devops/v5_0/nuget/nuget_client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, base_url=None, creds=None):
2525

2626
resource_area_identifier = 'b3be7473-68ea-4a81-bfc7-9530baaa19ad'
2727

28-
def download_package(self, feed_id, package_name, package_version, source_protocol_version=None):
28+
def download_package(self, feed_id, package_name, package_version, source_protocol_version=None, **kwargs):
2929
"""DownloadPackage.
3030
[Preview API] Download a package version directly. This API is intended for manual UI download options, not for programmatic access and scripting. You may be heavily throttled if accessing this api for scripting purposes.
3131
:param str feed_id: Name or ID of the feed.
@@ -48,8 +48,13 @@ def download_package(self, feed_id, package_name, package_version, source_protoc
4848
location_id='6ea81b8c-7386-490b-a71f-6cf23c80b388',
4949
version='5.0-preview.1',
5050
route_values=route_values,
51-
query_parameters=query_parameters)
52-
return self._deserialize('object', response)
51+
query_parameters=query_parameters,
52+
accept_media_type='application/octet-stream')
53+
if "callback" in kwargs:
54+
callback = kwargs["callback"]
55+
else:
56+
callback = None
57+
return self._client.stream_download(response, callback=callback)
5358

5459
def update_package_versions(self, batch_request, feed_id):
5560
"""UpdatePackageVersions.

azure-devops/azure/devops/v5_0/profile/profile_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, base_url=None, creds=None):
2323
self._serialize = Serializer(client_models)
2424
self._deserialize = Deserializer(client_models)
2525

26-
resource_area_identifier = None
26+
resource_area_identifier = '8ccfef3d-2b87-4e99-8ccb-66e343d2daa8'
2727

2828
def get_profile(self, id, details=None, with_attributes=None, partition=None, core_attributes=None, force_refresh=None):
2929
"""GetProfile.

azure-devops/azure/devops/v5_1/build/build_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,14 @@ def get_project_resources(self, project, type=None, id=None):
246246
query_parameters=query_parameters)
247247
return self._deserialize('[DefinitionResourceReference]', self._unwrap_collection(response))
248248

249-
def list_branches(self, project, provider_name, service_endpoint_id=None, repository=None):
249+
def list_branches(self, project, provider_name, service_endpoint_id=None, repository=None, branch_name=None):
250250
"""ListBranches.
251251
[Preview API] Gets a list of branches for the given source code repository.
252252
:param str project: Project ID or project name
253253
:param str provider_name: The name of the source provider.
254254
:param str service_endpoint_id: If specified, the ID of the service endpoint to query. Can only be omitted for providers that do not use service endpoints, e.g. TFVC or TFGit.
255-
:param str repository: If specified, the vendor-specific identifier or the name of the repository to get branches. Can only be omitted for providers that do not support multiple repositories.
255+
:param str repository: The vendor-specific identifier or the name of the repository to get branches. Can only be omitted for providers that do not support multiple repositories.
256+
:param str branch_name: If supplied, the name of the branch to check for specifically.
256257
:rtype: [str]
257258
"""
258259
route_values = {}
@@ -265,6 +266,8 @@ def list_branches(self, project, provider_name, service_endpoint_id=None, reposi
265266
query_parameters['serviceEndpointId'] = self._serialize.query('service_endpoint_id', service_endpoint_id, 'str')
266267
if repository is not None:
267268
query_parameters['repository'] = self._serialize.query('repository', repository, 'str')
269+
if branch_name is not None:
270+
query_parameters['branchName'] = self._serialize.query('branch_name', branch_name, 'str')
268271
response = self._send(http_method='GET',
269272
location_id='e05d4403-9b81-4244-8763-20fde28d1976',
270273
version='5.1-preview.1',

azure-devops/azure/devops/v5_1/build/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,13 +1572,13 @@ def __init__(self, links=None):
15721572
class ReleaseReference(Model):
15731573
"""ReleaseReference.
15741574
1575-
:param attempt:
1575+
:param attempt: Number of Release Attempt.
15761576
:type attempt: int
1577-
:param creation_date:
1577+
:param creation_date: Release Creation Date.
15781578
:type creation_date: datetime
15791579
:param definition_id: Release definition ID.
15801580
:type definition_id: int
1581-
:param environment_creation_date:
1581+
:param environment_creation_date: Environment creation Date.
15821582
:type environment_creation_date: datetime
15831583
:param environment_definition_id: Release environment definition ID.
15841584
:type environment_definition_id: int

azure-devops/azure/devops/v5_1/cix/models.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,16 @@ def __init__(self, content=None, is_base64_encoded=None, path=None):
3636
class CreatedResources(Model):
3737
"""CreatedResources.
3838
39-
:param error:
40-
:type error: str
4139
:param resources:
4240
:type resources: dict
4341
"""
4442

4543
_attribute_map = {
46-
'error': {'key': 'error', 'type': 'str'},
4744
'resources': {'key': 'resources', 'type': '{object}'}
4845
}
4946

50-
def __init__(self, error=None, resources=None):
47+
def __init__(self, resources=None):
5148
super(CreatedResources, self).__init__()
52-
self.error = error
5349
self.resources = resources
5450

5551

azure-devops/azure/devops/v5_1/core/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
__all__ = [
1313
'GraphSubjectBase',
14+
'Identity',
15+
'IdentityBase',
1416
'IdentityData',
1517
'IdentityRef',
1618
'JsonPatchOperation',

azure-devops/azure/devops/v5_1/core/core_client.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,13 @@ def get_proxies(self, proxy_url=None):
372372
query_parameters=query_parameters)
373373
return self._deserialize('[Proxy]', self._unwrap_collection(response))
374374

375-
def get_all_teams(self, mine=None, top=None, skip=None):
375+
def get_all_teams(self, mine=None, top=None, skip=None, expand_identity=None):
376376
"""GetAllTeams.
377377
[Preview API] Get a list of all teams.
378-
:param bool mine: If true return all the teams requesting user is member, otherwise return all the teams user has read access
378+
:param bool mine: If true, then return all teams requesting user is member. Otherwise return all teams user has read access.
379379
:param int top: Maximum number of teams to return.
380380
:param int skip: Number of teams to skip.
381+
:param bool expand_identity: A value indicating whether or not to expand Identity information in the result WebApiTeam object.
381382
:rtype: [WebApiTeam]
382383
"""
383384
query_parameters = {}
@@ -387,9 +388,11 @@ def get_all_teams(self, mine=None, top=None, skip=None):
387388
query_parameters['$top'] = self._serialize.query('top', top, 'int')
388389
if skip is not None:
389390
query_parameters['$skip'] = self._serialize.query('skip', skip, 'int')
391+
if expand_identity is not None:
392+
query_parameters['$expandIdentity'] = self._serialize.query('expand_identity', expand_identity, 'bool')
390393
response = self._send(http_method='GET',
391394
location_id='7a4d9ee9-3433-4347-b47a-7a80f1cf307e',
392-
version='5.1-preview.2',
395+
version='5.1-preview.3',
393396
query_parameters=query_parameters)
394397
return self._deserialize('[WebApiTeam]', self._unwrap_collection(response))
395398

@@ -406,7 +409,7 @@ def create_team(self, team, project_id):
406409
content = self._serialize.body(team, 'WebApiTeam')
407410
response = self._send(http_method='POST',
408411
location_id='d30a3dd1-f8ba-442a-b86a-bd0c0c383e59',
409-
version='5.1-preview.2',
412+
version='5.1-preview.3',
410413
route_values=route_values,
411414
content=content)
412415
return self._deserialize('WebApiTeam', response)
@@ -424,34 +427,40 @@ def delete_team(self, project_id, team_id):
424427
route_values['teamId'] = self._serialize.url('team_id', team_id, 'str')
425428
self._send(http_method='DELETE',
426429
location_id='d30a3dd1-f8ba-442a-b86a-bd0c0c383e59',
427-
version='5.1-preview.2',
430+
version='5.1-preview.3',
428431
route_values=route_values)
429432

430-
def get_team(self, project_id, team_id):
433+
def get_team(self, project_id, team_id, expand_identity=None):
431434
"""GetTeam.
432435
[Preview API] Get a specific team.
433436
:param str project_id: The name or ID (GUID) of the team project containing the team.
434437
:param str team_id: The name or ID (GUID) of the team.
438+
:param bool expand_identity: A value indicating whether or not to expand Identity information in the result WebApiTeam object.
435439
:rtype: :class:`<WebApiTeam> <azure.devops.v5_1.core.models.WebApiTeam>`
436440
"""
437441
route_values = {}
438442
if project_id is not None:
439443
route_values['projectId'] = self._serialize.url('project_id', project_id, 'str')
440444
if team_id is not None:
441445
route_values['teamId'] = self._serialize.url('team_id', team_id, 'str')
446+
query_parameters = {}
447+
if expand_identity is not None:
448+
query_parameters['$expandIdentity'] = self._serialize.query('expand_identity', expand_identity, 'bool')
442449
response = self._send(http_method='GET',
443450
location_id='d30a3dd1-f8ba-442a-b86a-bd0c0c383e59',
444-
version='5.1-preview.2',
445-
route_values=route_values)
451+
version='5.1-preview.3',
452+
route_values=route_values,
453+
query_parameters=query_parameters)
446454
return self._deserialize('WebApiTeam', response)
447455

448-
def get_teams(self, project_id, mine=None, top=None, skip=None):
456+
def get_teams(self, project_id, mine=None, top=None, skip=None, expand_identity=None):
449457
"""GetTeams.
450458
[Preview API] Get a list of teams.
451459
:param str project_id:
452-
:param bool mine: If true return all the teams requesting user is member, otherwise return all the teams user has read access
460+
:param bool mine: If true return all the teams requesting user is member, otherwise return all the teams user has read access.
453461
:param int top: Maximum number of teams to return.
454462
:param int skip: Number of teams to skip.
463+
:param bool expand_identity: A value indicating whether or not to expand Identity information in the result WebApiTeam object.
455464
:rtype: [WebApiTeam]
456465
"""
457466
route_values = {}
@@ -464,9 +473,11 @@ def get_teams(self, project_id, mine=None, top=None, skip=None):
464473
query_parameters['$top'] = self._serialize.query('top', top, 'int')
465474
if skip is not None:
466475
query_parameters['$skip'] = self._serialize.query('skip', skip, 'int')
476+
if expand_identity is not None:
477+
query_parameters['$expandIdentity'] = self._serialize.query('expand_identity', expand_identity, 'bool')
467478
response = self._send(http_method='GET',
468479
location_id='d30a3dd1-f8ba-442a-b86a-bd0c0c383e59',
469-
version='5.1-preview.2',
480+
version='5.1-preview.3',
470481
route_values=route_values,
471482
query_parameters=query_parameters)
472483
return self._deserialize('[WebApiTeam]', self._unwrap_collection(response))
@@ -487,7 +498,7 @@ def update_team(self, team_data, project_id, team_id):
487498
content = self._serialize.body(team_data, 'WebApiTeam')
488499
response = self._send(http_method='PATCH',
489500
location_id='d30a3dd1-f8ba-442a-b86a-bd0c0c383e59',
490-
version='5.1-preview.2',
501+
version='5.1-preview.3',
491502
route_values=route_values,
492503
content=content)
493504
return self._deserialize('WebApiTeam', response)

0 commit comments

Comments
 (0)