Esempio n. 1
0
 def set_maximum_concurrent_connections(
         self, maximum_concurrent_connections: int):
     # mount new adapter with new parameters
     mount_default_adapter(
         session=self._session,
         max_pool_size=maximum_concurrent_connections,
     )
Esempio n. 2
0
    def __init__(self, api_routes, basic_credentials, tls_verify=False):
        self._routes = not_none(api_routes)
        self._credentials = not_none(basic_credentials)
        self._auth = (basic_credentials.username(), basic_credentials.passwd())
        self._tls_verify = tls_verify
        self._session_id = None
        self._session = requests.Session()
        mount_default_adapter(session=self._session, )

        self._csrf_token = None
Esempio n. 3
0
    def _concourse_version(self, config_factory):
        session = requests.Session()
        http_requests.mount_default_adapter(session)
        concourse_url = urllib.parse.urljoin(
            self.ingress_url(config_factory),
            CONCOURSE_INFO_API_ENDPOINT,
        )
        try:
            response = session.get(concourse_url)
            response.raise_for_status()
        except requests.exceptions.HTTPError:
            ci.util.warning(f'Could not determine version of Concourse running at {concourse_url}')
            return None

        return response.json()['version']
Esempio n. 4
0
    def __init__(
        self,
        api_routes,
        protecode_cfg,
    ):
        self._routes = not_none(api_routes)
        not_none(protecode_cfg)
        self._credentials = protecode_cfg.credentials()
        self._auth_scheme = protecode_cfg.auth_scheme()
        self._tls_verify = protecode_cfg.tls_verify()
        self._session_id = None
        self._session = requests.Session()
        mount_default_adapter(session=self._session, )

        self._csrf_token = None
Esempio n. 5
0
    def __init__(
        self,
        api_routes,
        protecode_cfg: ProtecodeConfig,
    ):
        self._routes = not_none(api_routes)
        not_none(protecode_cfg)
        self._credentials = protecode_cfg.credentials()
        self._auth_scheme = protecode_cfg.auth_scheme()

        if self._auth_scheme is ProtecodeAuthScheme.BASIC_AUTH:
            logger.warning(
                'Using basic auth to authenticate against Protecode.')

        self._tls_verify = protecode_cfg.tls_verify()
        self._session_id = None
        self._session = requests.Session()
        mount_default_adapter(session=self._session, )

        self._csrf_token = None
Esempio n. 6
0
def github_api_ctor(
    github_url: str,
    verify_ssl: bool = True,
    session_adapter: SessionAdapter = SessionAdapter.RETRY,
):
    '''returns the appropriate github3.GitHub constructor for the given github URL

    In case github_url does not refer to github.com, the c'tor for GithubEnterprise is
    returned with the url argument preset, thus disburdening users to differentiate
    between github.com and non-github.com cases.
    '''
    parsed = urllib.parse.urlparse(github_url)
    if parsed.scheme:
        hostname = parsed.hostname
    else:
        raise ValueError('failed to parse url: ' + str(github_url))

    session = github3.session.GitHubSession()
    session_adapter = SessionAdapter(session_adapter)
    if session_adapter is SessionAdapter.NONE:
        pass
    elif session_adapter is SessionAdapter.RETRY:
        session = http_requests.mount_default_adapter(session)
    elif session_adapter is SessionAdapter.CACHE:
        session = cachecontrol.CacheControl(
            session,
            cache_etags=True,
        )
    else:
        raise NotImplementedError

    if log_github_access:
        session.hooks['response'] = log_stack_trace_information_hook

    if hostname.lower() == 'github.com':
        return functools.partial(
            github3.github.GitHub,
            session=session,
        )
    else:
        return functools.partial(
            github3.github.GitHubEnterprise,
            url=github_url,
            verify=verify_ssl,
            session=session,
        )
Esempio n. 7
0
def _create_github_api_object(github_cfg: 'GithubConfig', ):
    github_url = github_cfg.http_url()
    github_auth_token = github_cfg.credentials().auth_token()

    verify_ssl = github_cfg.tls_validation()

    github_ctor = github_api_ctor(github_url=github_url, verify_ssl=verify_ssl)
    github_api = github_ctor(token=github_auth_token, )

    if not github_api:
        util.fail("Could not connect to GitHub-instance {url}".format(
            url=github_url))

    session = mount_default_adapter(github_api.session)

    if log_github_access:
        session.hooks['response'] = log_stack_trace_information

    return github_api