コード例 #1
0
 def get_vsts_info(self, relative_remote_url):
     request = ClientRequest()
     request.url = self._client.format_url(
         relative_remote_url.rstrip('/') + '/vsts/info')
     request.method = 'GET'
     headers = {'Accept': 'application/json'}
     if self._suppress_fedauth_redirect:
         headers['X-TFS-FedAuthRedirect'] = 'Suppress'
     response = self._send_request(request, headers)
     return self._deserialize('VstsInfo', response)
コード例 #2
0
 def get_vsts_info_by_remote_url(remote_url,
                                 credentials,
                                 suppress_fedauth_redirect=True):
     request = ClientRequest()
     request.url = remote_url.rstrip('/') + '/vsts/info'
     request.method = 'GET'
     headers = {'Accept': 'application/json'}
     if suppress_fedauth_redirect:
         headers['X-TFS-FedAuthRedirect'] = 'Suppress'
     git_client = GitClient(base_url=remote_url, creds=credentials)
     response = git_client._send_request(request, headers)
     return git_client._deserialize('VstsInfo', response)
コード例 #3
0
    def _get_resource_locations(self, all_host_types):
        # Check local client's cached Options first
        if all_host_types:
            if self._all_host_types_locations is not None:
                return self._all_host_types_locations
        elif self._locations is not None:
            return self._locations

        # Next check for options cached on disk
        if not all_host_types and OPTIONS_FILE_CACHE[self.normalized_url]:
            try:
                logger.debug('File cache hit for options on: %s',
                             self.normalized_url)
                self._locations = self._base_deserialize.deserialize_data(
                    OPTIONS_FILE_CACHE[self.normalized_url],
                    '[ApiResourceLocation]')
                return self._locations
            except DeserializationError as ex:
                logger.debug(ex, exc_info=True)
        else:
            logger.debug('File cache miss for options on: %s',
                         self.normalized_url)

        # Last resort, make the call to the server
        options_uri = self._combine_url(self.config.base_url, '_apis')
        request = ClientRequest()
        request.url = self._client.format_url(options_uri)
        if all_host_types:
            query_parameters = {'allHostTypes': True}
            request.format_parameters(query_parameters)
        request.method = 'OPTIONS'
        headers = {'Accept': 'application/json'}
        if self._suppress_fedauth_redirect:
            headers['X-TFS-FedAuthRedirect'] = 'Suppress'
        response = self._send_request(request, headers=headers)
        wrapper = self._base_deserialize('VssJsonCollectionWrapper', response)
        if wrapper is None:
            raise VstsClientRequestError(
                "Failed to retrieve resource locations from: {}".format(
                    options_uri))
        collection = wrapper.value
        returned_locations = self._base_deserialize('[ApiResourceLocation]',
                                                    collection)
        if all_host_types:
            self._all_host_types_locations = returned_locations
        else:
            self._locations = returned_locations
            try:
                OPTIONS_FILE_CACHE[self.normalized_url] = wrapper.value
            except SerializationError as ex:
                logger.debug(ex, exc_info=True)
        return returned_locations
コード例 #4
0
 def _create_request_message(self, http_method, location_id, route_values=None,
                             query_parameters=None):
     location = self._get_resource_location(location_id)
     if location is None:
         raise ValueError('API resource location ' + location_id + ' is not registered on '
                          + self.config.base_url + '.')
     if route_values is None:
         route_values = {}
     route_values['area'] = location.area
     route_values['resource'] = location.resource_name
     route_template = self._remove_optional_route_parameters(location.route_template,
                                                             route_values)
     logging.debug('Route template: %s', location.route_template)
     url = self._client.format_url(route_template, **route_values)
     request = ClientRequest()
     request.url = self._client.format_url(url)
     if query_parameters:
         request.format_parameters(query_parameters)
     request.method = http_method
     return request