File: git_client.py

package info (click to toggle)
azure-devops-cli-extension 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,384 kB
  • sloc: python: 160,782; xml: 198; makefile: 56; sh: 51
file content (39 lines) | stat: -rw-r--r-- 1,654 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# coding=utf-8

from msrest.universal_http import ClientRequest
from .git_client_base import GitClientBase


class GitClient(GitClientBase):
    """Git
    :param str base_url: Service URL
    :param Authentication creds: Authenticated credentials.
    """

    def __init__(self, base_url=None, creds=None):
        super(GitClient, self).__init__(base_url, creds)

    def get_vsts_info(self, relative_remote_url):
        url = self._client.format_url(relative_remote_url.rstrip('/') + '/vsts/info')
        request = ClientRequest(method='GET', url=url)
        headers = {'Accept': 'application/json'}
        if self._suppress_fedauth_redirect:
            headers['X-TFS-FedAuthRedirect'] = 'Suppress'
        if self._force_msa_pass_through:
            headers['X-VSS-ForceMsaPassThrough'] = 'true'
        response = self._send_request(request, headers)
        return self._deserialize('VstsInfo', response)

    @staticmethod
    def get_vsts_info_by_remote_url(remote_url, credentials,
                                    suppress_fedauth_redirect=True,
                                    force_msa_pass_through=True):
        request = ClientRequest(method='GET', url=remote_url.rstrip('/') + '/vsts/info')
        headers = {'Accept': 'application/json'}
        if suppress_fedauth_redirect:
            headers['X-TFS-FedAuthRedirect'] = 'Suppress'
        if force_msa_pass_through:
            headers['X-VSS-ForceMsaPassThrough'] = 'true'
        git_client = GitClient(base_url=remote_url, creds=credentials)
        response = git_client._send_request(request, headers)
        return git_client._deserialize('VstsInfo', response)