コード例 #1
0
def get_openr_ctrl_cpp_client(
    host: str,
    options: Optional[bunch.Bunch] = None,
    client_type=ClientType.THRIFT_HEADER_CLIENT_TYPE,
) -> OpenrCtrlCppClient:
    """
    Utility function to get py3 OpenrClient. We must eventually move all of our
    client use-case to py3 as python2 support is deprecated.
    https://fburl.com/ef0eq78f

    Major Usecase for: py3 supports streaming
    """

    options = options if options else getDefaultOptions(host)
    ssl_context = None

    # Create ssl context if specified
    if options.ssl:
        # Translate ssl verification option
        ssl_verify_opt = SSLVerifyOption.NO_VERIFY
        if options.cert_reqs == ssl.CERT_OPTIONAL:
            ssl_verify_opt = SSLVerifyOption.VERIFY_REQ_CLIENT_CERT
        if options.cert_reqs == ssl.CERT_REQUIRED:
            ssl_verify_opt = SSLVerifyOption.VERIFY

        # Create ssl context
        ssl_context = SSLContext()
        ssl_context.set_verify_option(ssl_verify_opt)
        ssl_context.load_cert_chain(certfile=options.cert_file,
                                    keyfile=options.key_file)
        ssl_context.load_verify_locations(cafile=options.ca_file)

    # Create and return client
    return get_client(
        OpenrCtrlCppClient,
        host=host,
        port=options.openr_ctrl_port,
        timeout=(options.timeout /
                 1000),  # NOTE: Timeout expected is in seconds
        client_type=client_type,
        ssl_context=ssl_context,
        ssl_timeout=(options.timeout /
                     1000),  # NOTE: Timeout expected is in seconds
    )
コード例 #2
0
ファイル: openr_client.py プロジェクト: zxh1986123/openr
def get_openr_ctrl_client(host: str,
                          options: Optional[bunch.Bunch] = None
                          ) -> OpenrCtrl.Client:
    """
    Utility function to get openr clients with default smart options. For
    options override please look at openr.cli.utils.options.OPTIONS
    """

    options = options if options else getDefaultOptions(host)
    if options.ssl:
        return OpenrCtrlSecureClient(
            host,
            options.ca_file,
            options.cert_file,
            options.key_file,
            options.acceptable_peer_name,
            options.openr_ctrl_port,
            options.timeout,
        )
    else:
        return OpenrCtrlPlainTextClient(options.host, options.openr_ctrl_port,
                                        options.timeout)