Example #1
0
def _mock_get_mgmt_service_client(client_type,
                                  subscription_bound=True,
                                  subscription_id=None,
                                  api_version=None,
                                  base_url_bound=None,
                                  **kwargs):
    # version of _get_mgmt_service_client to use when recording or playing tests
    profile = Profile()
    cred, subscription_id, _ = profile.get_login_credentials(
        subscription_id=subscription_id)
    client_kwargs = {}

    if base_url_bound:
        client_kwargs = {'base_url': CLOUD.endpoints.resource_manager}
    if api_version:
        client_kwargs['api_version'] = api_version
    if kwargs:
        client_kwargs.update(kwargs)

    if subscription_bound:
        client = client_type(cred, subscription_id, **client_kwargs)
    else:
        client = client_type(cred, **client_kwargs)

    client = _debug.change_ssl_cert_verification(client)

    client.config.add_user_agent("AZURECLI/TEST/{}".format(core_version))

    return (client, subscription_id)
Example #2
0
def configure_common_settings(cli_ctx, client):
    client = _debug.change_ssl_cert_verification(client)

    client.config.enable_http_logger = True

    client.config.add_user_agent(UA_AGENT)
    try:
        client.config.add_user_agent(os.environ[ENV_ADDITIONAL_USER_AGENT])
    except KeyError:
        pass

    try:
        command_ext_name = cli_ctx.data['command_extension_name']
        if command_ext_name:
            client.config.add_user_agent("CliExtension/{}".format(command_ext_name))
    except KeyError:
        pass

    for header, value in cli_ctx.data['headers'].items():
        # We are working with the autorest team to expose the add_header functionality of the generated client to avoid
        # having to access private members
        client._client.add_header(header, value)  # pylint: disable=protected-access

    command_name_suffix = ';completer-request' if cli_ctx.data['completer_active'] else ''
    client._client.add_header('CommandName',  # pylint: disable=protected-access
                              "{}{}".format(cli_ctx.data['command'], command_name_suffix))
    client.config.generate_client_request_id = 'x-ms-client-request-id' not in cli_ctx.data['headers']
Example #3
0
def configure_common_settings(cli_ctx, client):
    client = _debug.change_ssl_cert_verification(client)

    client.config.enable_http_logger = True

    client.config.add_user_agent(UA_AGENT)
    try:
        client.config.add_user_agent(os.environ[ENV_ADDITIONAL_USER_AGENT])
    except KeyError:
        pass

    try:
        command_ext_name = cli_ctx.data['command_extension_name']
        if command_ext_name:
            client.config.add_user_agent(
                "CliExtension/{}".format(command_ext_name))
    except KeyError:
        pass

    for header, value in cli_ctx.data['headers'].items():
        # We are working with the autorest team to expose the add_header functionality of the generated client to avoid
        # having to access private members
        client._client.add_header(header, value)  # pylint: disable=protected-access

    command_name_suffix = ';completer-request' if cli_ctx.data[
        'completer_active'] else ''
    # pylint: disable=protected-access
    client._client.add_header(
        'CommandName', "{}{}".format(cli_ctx.data['command'],
                                     command_name_suffix))
    if cli_ctx.data.get('safe_params'):
        client._client.add_header('ParameterSetName',
                                  ' '.join(cli_ctx.data['safe_params']))
    client.config.generate_client_request_id = 'x-ms-client-request-id' not in cli_ctx.data[
        'headers']
Example #4
0
def _mock_get_mgmt_service_client(client_type,
                                  subscription_bound=True,
                                  subscription_id=None,
                                  api_version=None,
                                  base_url_bound=None,
                                  resource=CLOUD.endpoints.active_directory_resource_id,
                                  **kwargs):
    # version of _get_mgmt_service_client to use when recording or playing tests
    profile = Profile()
    cred, subscription_id, _ = profile.get_login_credentials(subscription_id=subscription_id,
                                                             resource=resource)
    client_kwargs = {}

    if base_url_bound:
        client_kwargs = {'base_url': CLOUD.endpoints.resource_manager}
    if api_version:
        client_kwargs['api_version'] = api_version
    if kwargs:
        client_kwargs.update(kwargs)

    if subscription_bound:
        client = client_type(cred, subscription_id, **client_kwargs)
    else:
        client = client_type(cred, **client_kwargs)

    client = _debug.change_ssl_cert_verification(client)

    client.config.add_user_agent("AZURECLI/TEST/{}".format(core_version))

    return (client, subscription_id)
Example #5
0
 def create_arm_client_factory(config):
     if arm_client_factory:
         return arm_client_factory(config)
     else:
         return change_ssl_cert_verification(
             SubscriptionClient(
                 config, base_url=CLOUD.endpoints.resource_manager))
Example #6
0
 def create_arm_client_factory(credentials):
     if arm_client_factory:
         return arm_client_factory(credentials)
     from azure.cli.core.profiles._shared import get_client_class
     from azure.cli.core.profiles import get_api_version, ResourceType
     from azure.cli.core._debug import change_ssl_cert_verification
     client_type = get_client_class(ResourceType.MGMT_RESOURCE_SUBSCRIPTIONS)
     api_version = get_api_version(ResourceType.MGMT_RESOURCE_SUBSCRIPTIONS)
     return change_ssl_cert_verification(client_type(credentials, api_version=api_version,
                                                     base_url=CLOUD.endpoints.resource_manager))
Example #7
0
 def create_arm_client_factory(credentials):
     if arm_client_factory:
         return arm_client_factory(credentials)
     from azure.cli.core.profiles._shared import get_client_class
     from azure.cli.core.profiles import ResourceType, get_api_version
     from azure.cli.core._debug import change_ssl_cert_verification
     client_type = get_client_class(ResourceType.MGMT_RESOURCE_SUBSCRIPTIONS)
     api_version = get_api_version(cli_ctx, ResourceType.MGMT_RESOURCE_SUBSCRIPTIONS)
     return change_ssl_cert_verification(client_type(credentials, api_version=api_version,
                                                     base_url=self.cli_ctx.cloud.endpoints.resource_manager))
    def test_verify_client_connection(self):
        os.environ[_debug.DISABLE_VERIFY_VARIABLE_NAME] = ""
        self.assertFalse(_debug.should_disable_connection_verify())

        os.environ[_debug.DISABLE_VERIFY_VARIABLE_NAME] = "1"
        self.assertTrue(_debug.should_disable_connection_verify())

        clientMock = MagicMock()
        clientMock.config.connection.verify = True
        clientMock = _debug.change_ssl_cert_verification(clientMock)
        self.assertFalse(clientMock.config.connection.verify)
    def test_verify_client_connection(self):
        os.environ[_debug.DISABLE_VERIFY_VARIABLE_NAME] = ""
        self.assertFalse(_debug.should_disable_connection_verify())

        os.environ[_debug.DISABLE_VERIFY_VARIABLE_NAME] = "1"
        self.assertTrue(_debug.should_disable_connection_verify())

        clientMock = MagicMock()
        clientMock.config.connection.verify = True
        clientMock = _debug.change_ssl_cert_verification(clientMock)
        self.assertFalse(clientMock.config.connection.verify)
def _mock_get_mgmt_service_client(client_type,
                                  subscription_bound=True,
                                  subscription_id=None,
                                  api_version=None):
    # version of _get_mgmt_service_client to use when recording or playing tests
    profile = Profile()
    cred, subscription_id, _ = profile.get_login_credentials(
        subscription_id=subscription_id)
    if subscription_bound:
        client = client_type(cred, subscription_id, api_version=api_version) \
            if api_version else client_type(cred, subscription_id)
    else:
        client = client_type(cred, api_version=api_version) \
            if api_version else client_type(cred)

    client = _debug.change_ssl_cert_verification(client)

    client.config.add_user_agent("AZURECLI/TEST/{}".format(core_version))

    return (client, subscription_id)
def configure_common_settings(client):
    client = _debug.change_ssl_cert_verification(client)

    client.config.add_user_agent(UA_AGENT)
    try:
        client.config.add_user_agent(os.environ[ENV_ADDITIONAL_USER_AGENT])
    except KeyError:
        pass

    for header, value in APPLICATION.session['headers'].items():
        # We are working with the autorest team to expose the add_header functionality of the generated client to avoid
        # having to access private members
        client._client.add_header(header, value)  # pylint: disable=protected-access

    command_name_suffix = ';completer-request' if APPLICATION.session[
        'completer_active'] else ''
    client._client.add_header(
        'CommandName',  # pylint: disable=protected-access
        "{}{}".format(APPLICATION.session['command'], command_name_suffix))
    client.config.generate_client_request_id = 'x-ms-client-request-id' not in APPLICATION.session[
        'headers']
Example #12
0
def configure_common_settings(cli_ctx, client):
    client = _debug.change_ssl_cert_verification(client)

    client.config.enable_http_logger = True

    client.config.add_user_agent(get_az_user_agent())

    try:
        command_ext_name = cli_ctx.data['command_extension_name']
        if command_ext_name:
            client.config.add_user_agent(
                "CliExtension/{}".format(command_ext_name))
    except KeyError:
        pass

    # Prepare CommandName header
    command_name_suffix = ';completer-request' if cli_ctx.data[
        'completer_active'] else ''
    cli_ctx.data['headers']['CommandName'] = "{}{}".format(
        cli_ctx.data['command'], command_name_suffix)

    # Prepare ParameterSetName header
    if cli_ctx.data.get('safe_params'):
        cli_ctx.data['headers']['ParameterSetName'] = ' '.join(
            cli_ctx.data['safe_params'])

    # Prepare x-ms-client-request-id header
    client.config.generate_client_request_id = 'x-ms-client-request-id' not in cli_ctx.data[
        'headers']

    logger.debug("Adding custom headers to the client:")

    for header, value in cli_ctx.data['headers'].items():
        # msrest doesn't print custom headers in debug log, so CLI should do that
        logger.debug("    '%s': '%s'", header, value)
        # We are working with the autorest team to expose the add_header functionality of the generated client to avoid
        # having to access private members
        client._client.add_header(header, value)  # pylint: disable=protected-access
 def create_arm_client_factory(config):
     if arm_client_factory:
         return arm_client_factory(config)
     else:
         return change_ssl_cert_verification(SubscriptionClient(
             config, base_url=CLOUD.endpoints.resource_manager))