From 3f72e81e8be470870c431b6e434b73a5efcdcf1f Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Tue, 22 Jun 2021 17:14:33 +0800 Subject: [PATCH 1/9] cae support --- autorest/codegen/__init__.py | 18 +++++++++--------- autorest/codegen/models/code_model.py | 2 +- .../codegen/serializers/general_serializer.py | 8 +++++--- .../codegen/serializers/metadata_serializer.py | 2 +- autorest/codegen/templates/config.py.jinja2 | 4 ++-- .../templates/multiapi_config.py.jinja2 | 4 ++-- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/autorest/codegen/__init__.py b/autorest/codegen/__init__.py index defd861456f..8703b65c778 100644 --- a/autorest/codegen/__init__.py +++ b/autorest/codegen/__init__.py @@ -19,7 +19,7 @@ def _get_credential_default_policy_type_has_async_version(credential_default_policy_type: str) -> bool: mapping = { - "BearerTokenCredentialPolicy": True, + "ARMChallengeAuthenticationPolicy": True, "AzureKeyCredentialPolicy": False } return mapping[credential_default_policy_type] @@ -142,7 +142,7 @@ def _get_credential_param(self, azure_arm, credential, credential_default_policy credential_scopes = self._get_credential_scopes(credential) credential_key_header_name = self._autorestapi.get_value('credential-key-header-name') - if credential_default_policy_type == "BearerTokenCredentialPolicy": + if credential_default_policy_type == "ARMChallengeAuthenticationPolicy": if not credential_scopes: if azure_arm: credential_scopes = ["https://management.azure.com/.default"] @@ -150,7 +150,7 @@ def _get_credential_param(self, azure_arm, credential, credential_default_policy # If add-credential is specified, we still want to add a credential_scopes variable. # Will make it an empty list so we can differentiate between this case and None _LOGGER.warning( - "You have default credential policy BearerTokenCredentialPolicy" + "You have default credential policy ARMChallengeAuthenticationPolicy" "but not the --credential-scopes flag set while generating non-management plane code. " "This is not recommend because it forces the customer to pass credential scopes " "through kwargs if they want to authenticate." @@ -159,7 +159,7 @@ def _get_credential_param(self, azure_arm, credential, credential_default_policy if credential_key_header_name: raise ValueError( "You have passed in a credential key header name with default credential policy type " - "BearerTokenCredentialPolicy. This is not allowed, since credential key header name is tied with " + "ARMChallengeAuthenticationPolicy. This is not allowed, since credential key header name is tied with " "AzureKeyCredentialPolicy. Instead, with this policy it is recommend you pass in " "--credential-scopes." ) @@ -169,7 +169,7 @@ def _get_credential_param(self, azure_arm, credential, credential_default_policy raise ValueError( "You have passed in credential scopes with default credential policy type " "AzureKeyCredentialPolicy. This is not allowed, since credential scopes is tied with " - "BearerTokenCredentialPolicy. Instead, with this policy you must pass in " + "ARMChallengeAuthenticationPolicy. Instead, with this policy you must pass in " "--credential-key-header-name." ) if not credential_key_header_name: @@ -182,11 +182,11 @@ def _get_credential_param(self, azure_arm, credential, credential_default_policy def _handle_default_authentication_policy(self, azure_arm, credential): passed_in_credential_default_policy_type = ( - self._autorestapi.get_value("credential-default-policy-type") or "BearerTokenCredentialPolicy" + self._autorestapi.get_value("credential-default-policy-type") or "ARMChallengeAuthenticationPolicy" ) - # right now, we only allow BearerTokenCredentialPolicy and AzureKeyCredentialPolicy - allowed_policies = ["BearerTokenCredentialPolicy", "AzureKeyCredentialPolicy"] + # right now, we only allow ARMChallengeAuthenticationPolicy and AzureKeyCredentialPolicy + allowed_policies = ["ARMChallengeAuthenticationPolicy", "AzureKeyCredentialPolicy"] try: credential_default_policy_type = [ cp for cp in allowed_policies if cp.lower() == passed_in_credential_default_policy_type.lower() @@ -194,7 +194,7 @@ def _handle_default_authentication_policy(self, azure_arm, credential): except IndexError: raise ValueError( "The credential you pass in with --credential-default-policy-type must be either " - "BearerTokenCredentialPolicy or AzureKeyCredentialPolicy" + "ARMChallengeAuthenticationPolicy or AzureKeyCredentialPolicy" ) credential_scopes, credential_key_header_name = self._get_credential_param( diff --git a/autorest/codegen/models/code_model.py b/autorest/codegen/models/code_model.py index 3956580bada..27b56426575 100644 --- a/autorest/codegen/models/code_model.py +++ b/autorest/codegen/models/code_model.py @@ -125,7 +125,7 @@ def add_credential_global_parameter(self) -> None: :rtype: None """ credential_schema: Union[AzureKeyCredentialSchema, TokenCredentialSchema] - if self.options["credential_default_policy_type"] == "BearerTokenCredentialPolicy": + if self.options["credential_default_policy_type"] == "ARMChallengeAuthenticationPolicy": credential_schema = TokenCredentialSchema(async_mode=False) else: credential_schema = AzureKeyCredentialSchema() diff --git a/autorest/codegen/serializers/general_serializer.py b/autorest/codegen/serializers/general_serializer.py index b6b03da4748..e6393ddf38e 100644 --- a/autorest/codegen/serializers/general_serializer.py +++ b/autorest/codegen/serializers/general_serializer.py @@ -18,7 +18,9 @@ def config_imports(code_model, global_parameters: ParameterList, async_mode: boo for gp in global_parameters: file_import.merge(gp.imports()) if code_model.options["azure_arm"]: - file_import.add_from_import("azure.mgmt.core.policies", "ARMHttpLoggingPolicy", ImportType.AZURECORE) + async_policy = "ARMHttpLoggingPolicy, AsyncARMChallengeAuthenticationPolicy" + policy = "ARMHttpLoggingPolicy, ARMChallengeAuthenticationPolicy" + file_import.add_from_import("azure.mgmt.core.policies", async_policy if async_mode else policy, ImportType.AZURECORE) return file_import @@ -53,7 +55,7 @@ def _service_client_imports() -> FileImport: if ( self.code_model.options['credential'] and - self.code_model.options['credential_default_policy_type'] == "BearerTokenCredentialPolicy" + self.code_model.options['credential_default_policy_type'] == "ARMChallengeAuthenticationPolicy" ): self._correct_credential_parameter() @@ -75,7 +77,7 @@ def serialize_config_file(self) -> str: if ( self.code_model.options['credential'] and - self.code_model.options['credential_default_policy_type'] == "BearerTokenCredentialPolicy" + self.code_model.options['credential_default_policy_type'] == "ARMChallengeAuthenticationPolicy" ): self._correct_credential_parameter() diff --git a/autorest/codegen/serializers/metadata_serializer.py b/autorest/codegen/serializers/metadata_serializer.py index f94fa4c3865..7580730ceb2 100644 --- a/autorest/codegen/serializers/metadata_serializer.py +++ b/autorest/codegen/serializers/metadata_serializer.py @@ -143,7 +143,7 @@ def _is_paging(operation): async_global_parameters = self.code_model.global_parameters if ( self.code_model.options['credential'] and - self.code_model.options['credential_default_policy_type'] == "BearerTokenCredentialPolicy" + self.code_model.options['credential_default_policy_type'] == "ARMChallengeAuthenticationPolicy" ): # this ensures that the TokenCredentialSchema showing up in the list of code model's global parameters # is sync. This way we only have to make a copy for an async_credential diff --git a/autorest/codegen/templates/config.py.jinja2 b/autorest/codegen/templates/config.py.jinja2 index 84b58885286..3edb3f2873f 100644 --- a/autorest/codegen/templates/config.py.jinja2 +++ b/autorest/codegen/templates/config.py.jinja2 @@ -80,6 +80,6 @@ class {{ code_model.class_name }}Configuration(Configuration): {% endif %} if self.credential and not self.authentication_policy: {% set credential_default_policy_type = ("Async" if (async_mode and code_model.options['credential_default_policy_type_has_async_version']) else "") + code_model.options['credential_default_policy_type'] %} - {% set credential_param_type = ("'" + code_model.options['credential_key_header_name'] + "', ") if code_model.options['credential_key_header_name'] else ("*self.credential_scopes, " if "BearerTokenCredentialPolicy" in credential_default_policy_type else "") %} - self.authentication_policy = policies.{{ credential_default_policy_type }}(self.credential, {{ credential_param_type if credential_param_type }}**kwargs) + {% set credential_param_type = ("'" + code_model.options['credential_key_header_name'] + "', ") if code_model.options['credential_key_header_name'] else ("*self.credential_scopes, " if "ARMChallengeAuthenticationPolicy" in credential_default_policy_type else "") %} + self.authentication_policy = {{ credential_default_policy_type }}(self.credential, {{ credential_param_type if credential_param_type }}**kwargs) {% endif %} diff --git a/autorest/multiapi/templates/multiapi_config.py.jinja2 b/autorest/multiapi/templates/multiapi_config.py.jinja2 index 468036058e4..b32c7acc87f 100644 --- a/autorest/multiapi/templates/multiapi_config.py.jinja2 +++ b/autorest/multiapi/templates/multiapi_config.py.jinja2 @@ -92,6 +92,6 @@ class {{ code_model.service_client.name }}Configuration(Configuration): {% endif %} if self.credential and not self.authentication_policy: {% set credential_default_policy_type = ("Async" if (async_mode and code_model.config.credential_default_policy_type_has_async_version) else "") + code_model.config.credential_default_policy_type %} - {% set credential_param_type = ("'" + code_model.config.credential_key_header_name + "', ") if code_model.config.credential_key_header_name else ("*self.credential_scopes, " if "BearerTokenCredentialPolicy" in credential_default_policy_type else "") %} - self.authentication_policy = policies.{{ credential_default_policy_type }}(self.credential, {{ credential_param_type if credential_param_type }}**kwargs) + {% set credential_param_type = ("'" + code_model.config.credential_key_header_name + "', ") if code_model.config.credential_key_header_name else ("*self.credential_scopes, " if "ARMChallengeAuthenticationPolicy" in credential_default_policy_type else "") %} + self.authentication_policy = {{ credential_default_policy_type }}(self.credential, {{ credential_param_type if credential_param_type }}**kwargs) {% endif %} From 82c9dbcbbbf291ba68e4ce4bf5b74b393a888cd6 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Tue, 29 Jun 2021 10:03:47 +0800 Subject: [PATCH 2/9] pylint --- autorest/codegen/serializers/general_serializer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autorest/codegen/serializers/general_serializer.py b/autorest/codegen/serializers/general_serializer.py index e6393ddf38e..9116bd97523 100644 --- a/autorest/codegen/serializers/general_serializer.py +++ b/autorest/codegen/serializers/general_serializer.py @@ -20,7 +20,8 @@ def config_imports(code_model, global_parameters: ParameterList, async_mode: boo if code_model.options["azure_arm"]: async_policy = "ARMHttpLoggingPolicy, AsyncARMChallengeAuthenticationPolicy" policy = "ARMHttpLoggingPolicy, ARMChallengeAuthenticationPolicy" - file_import.add_from_import("azure.mgmt.core.policies", async_policy if async_mode else policy, ImportType.AZURECORE) + file_import.add_from_import("azure.mgmt.core.policies", async_policy if async_mode else policy, + ImportType.AZURECORE) return file_import From a6fa00184a595574b764c0d62151413aeaac18cc Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Tue, 29 Jun 2021 11:07:12 +0800 Subject: [PATCH 3/9] pylint --- autorest/codegen/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autorest/codegen/__init__.py b/autorest/codegen/__init__.py index 8703b65c778..99370e47919 100644 --- a/autorest/codegen/__init__.py +++ b/autorest/codegen/__init__.py @@ -159,8 +159,8 @@ def _get_credential_param(self, azure_arm, credential, credential_default_policy if credential_key_header_name: raise ValueError( "You have passed in a credential key header name with default credential policy type " - "ARMChallengeAuthenticationPolicy. This is not allowed, since credential key header name is tied with " - "AzureKeyCredentialPolicy. Instead, with this policy it is recommend you pass in " + "ARMChallengeAuthenticationPolicy. This is not allowed, since credential key header name is tied " + "with AzureKeyCredentialPolicy. Instead, with this policy it is recommend you pass in " "--credential-scopes." ) else: From 17b7d50853465ad2b3f9819aaa65ea15c5ac6bb7 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:02:19 +0800 Subject: [PATCH 4/9] update dependency version --- autorest/codegen/templates/setup.py.jinja2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autorest/codegen/templates/setup.py.jinja2 b/autorest/codegen/templates/setup.py.jinja2 index f1433121652..4675e3323bb 100644 --- a/autorest/codegen/templates/setup.py.jinja2 +++ b/autorest/codegen/templates/setup.py.jinja2 @@ -1,5 +1,5 @@ {% set name = code_model.options["package_name"] or code_model.class_name %} -{% set azure_mgmt_core_import = ', "azure-mgmt-core<2.0.0,>=1.2.1"' if code_model.options["azure_arm"] else "" %} +{% set azure_mgmt_core_import = ', "azure-mgmt-core<2.0.0,>=1.3.0"' if code_model.options["azure_arm"] else "" %} # coding=utf-8 {{ code_model.options['license_header'] }} # coding: utf-8 @@ -16,7 +16,7 @@ VERSION = "{{ code_model.options.get('package_version', '0.0.0') }}" # prerequisite: setuptools # http://pypi.python.org/pypi/setuptools -REQUIRES = ["msrest>=0.6.21", "azure-core<2.0.0,>=1.8.2"{{ azure_mgmt_core_import }}] +REQUIRES = ["msrest>=0.6.21", "azure-core<2.0.0,>=1.15.0"{{ azure_mgmt_core_import }}] setup( name=NAME, From 21904a04ace274be3f06e40da109f2b84cf0e331 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:40:13 +0800 Subject: [PATCH 5/9] review --- autorest/codegen/__init__.py | 24 ++++++++++++------- autorest/codegen/models/code_model.py | 3 ++- .../codegen/serializers/general_serializer.py | 12 ++++------ .../serializers/metadata_serializer.py | 6 ++--- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/autorest/codegen/__init__.py b/autorest/codegen/__init__.py index 99370e47919..6ca861ceb03 100644 --- a/autorest/codegen/__init__.py +++ b/autorest/codegen/__init__.py @@ -20,6 +20,7 @@ def _get_credential_default_policy_type_has_async_version(credential_default_policy_type: str) -> bool: mapping = { "ARMChallengeAuthenticationPolicy": True, + "BearerTokenCredentialPolicy": True, "AzureKeyCredentialPolicy": False } return mapping[credential_default_policy_type] @@ -142,7 +143,7 @@ def _get_credential_param(self, azure_arm, credential, credential_default_policy credential_scopes = self._get_credential_scopes(credential) credential_key_header_name = self._autorestapi.get_value('credential-key-header-name') - if credential_default_policy_type == "ARMChallengeAuthenticationPolicy": + if credential_default_policy_type in ["ARMChallengeAuthenticationPolicy", "BearerTokenCredentialPolicy"]: if not credential_scopes: if azure_arm: credential_scopes = ["https://management.azure.com/.default"] @@ -150,7 +151,8 @@ def _get_credential_param(self, azure_arm, credential, credential_default_policy # If add-credential is specified, we still want to add a credential_scopes variable. # Will make it an empty list so we can differentiate between this case and None _LOGGER.warning( - "You have default credential policy ARMChallengeAuthenticationPolicy" + "You have default credential policy " + "ARMChallengeAuthenticationPolicy/BearerTokenCredentialPolicy " "but not the --credential-scopes flag set while generating non-management plane code. " "This is not recommend because it forces the customer to pass credential scopes " "through kwargs if they want to authenticate." @@ -159,8 +161,10 @@ def _get_credential_param(self, azure_arm, credential, credential_default_policy if credential_key_header_name: raise ValueError( "You have passed in a credential key header name with default credential policy type " - "ARMChallengeAuthenticationPolicy. This is not allowed, since credential key header name is tied " - "with AzureKeyCredentialPolicy. Instead, with this policy it is recommend you pass in " + "ARMChallengeAuthenticationPolicy/BearerTokenCredentialPolicy. " + "This is not allowed, since credential key header name is tied " + "with AzureKeyCredentialPolicy/BearerTokenCredentialPolicy. " + "Instead, with this policy it is recommend you pass in " "--credential-scopes." ) else: @@ -169,8 +173,8 @@ def _get_credential_param(self, azure_arm, credential, credential_default_policy raise ValueError( "You have passed in credential scopes with default credential policy type " "AzureKeyCredentialPolicy. This is not allowed, since credential scopes is tied with " - "ARMChallengeAuthenticationPolicy. Instead, with this policy you must pass in " - "--credential-key-header-name." + "ARMChallengeAuthenticationPolicy/BearerTokenCredentialPolicy. " + "Instead, with this policy you must pass in --credential-key-header-name." ) if not credential_key_header_name: credential_key_header_name = "api-key" @@ -185,8 +189,10 @@ def _handle_default_authentication_policy(self, azure_arm, credential): self._autorestapi.get_value("credential-default-policy-type") or "ARMChallengeAuthenticationPolicy" ) - # right now, we only allow ARMChallengeAuthenticationPolicy and AzureKeyCredentialPolicy - allowed_policies = ["ARMChallengeAuthenticationPolicy", "AzureKeyCredentialPolicy"] + # right now, we only allow ARMChallengeAuthenticationPolicy, BearerTokenCredentialPolicy and + # AzureKeyCredentialPolicy + allowed_policies = ["ARMChallengeAuthenticationPolicy", "BearerTokenCredentialPolicy", + "AzureKeyCredentialPolicy"] try: credential_default_policy_type = [ cp for cp in allowed_policies if cp.lower() == passed_in_credential_default_policy_type.lower() @@ -194,7 +200,7 @@ def _handle_default_authentication_policy(self, azure_arm, credential): except IndexError: raise ValueError( "The credential you pass in with --credential-default-policy-type must be either " - "ARMChallengeAuthenticationPolicy or AzureKeyCredentialPolicy" + "ARMChallengeAuthenticationPolicy or BearerTokenCredentialPolicy or AzureKeyCredentialPolicy" ) credential_scopes, credential_key_header_name = self._get_credential_param( diff --git a/autorest/codegen/models/code_model.py b/autorest/codegen/models/code_model.py index 27b56426575..b6c0f66fc84 100644 --- a/autorest/codegen/models/code_model.py +++ b/autorest/codegen/models/code_model.py @@ -125,7 +125,8 @@ def add_credential_global_parameter(self) -> None: :rtype: None """ credential_schema: Union[AzureKeyCredentialSchema, TokenCredentialSchema] - if self.options["credential_default_policy_type"] == "ARMChallengeAuthenticationPolicy": + if self.options["credential_default_policy_type"] in ["ARMChallengeAuthenticationPolicy", + "BearerTokenCredentialPolicy"]: credential_schema = TokenCredentialSchema(async_mode=False) else: credential_schema = AzureKeyCredentialSchema() diff --git a/autorest/codegen/serializers/general_serializer.py b/autorest/codegen/serializers/general_serializer.py index 9116bd97523..1e66190d5f7 100644 --- a/autorest/codegen/serializers/general_serializer.py +++ b/autorest/codegen/serializers/general_serializer.py @@ -54,10 +54,8 @@ def _service_client_imports() -> FileImport: template = self.env.get_template("service_client.py.jinja2") - if ( - self.code_model.options['credential'] and - self.code_model.options['credential_default_policy_type'] == "ARMChallengeAuthenticationPolicy" - ): + if (self.code_model.options['credential'] and self.code_model.options['credential_default_policy_type'] in [ + "ARMChallengeAuthenticationPolicy", "BearerTokenCredentialPolicy"]): self._correct_credential_parameter() return template.render( @@ -76,10 +74,8 @@ def serialize_config_file(self) -> str: package_name = package_name[len("azure-"):] sdk_moniker = package_name if package_name else self.code_model.class_name.lower() - if ( - self.code_model.options['credential'] and - self.code_model.options['credential_default_policy_type'] == "ARMChallengeAuthenticationPolicy" - ): + if (self.code_model.options['credential'] and self.code_model.options['credential_default_policy_type'] in [ + "ARMChallengeAuthenticationPolicy", "BearerTokenCredentialPolicy"]): self._correct_credential_parameter() template = self.env.get_template("config.py.jinja2") diff --git a/autorest/codegen/serializers/metadata_serializer.py b/autorest/codegen/serializers/metadata_serializer.py index 7580730ceb2..5629431c328 100644 --- a/autorest/codegen/serializers/metadata_serializer.py +++ b/autorest/codegen/serializers/metadata_serializer.py @@ -141,10 +141,8 @@ def _is_paging(operation): # In this case, we need two copies of the credential global parameter # for typing purposes. async_global_parameters = self.code_model.global_parameters - if ( - self.code_model.options['credential'] and - self.code_model.options['credential_default_policy_type'] == "ARMChallengeAuthenticationPolicy" - ): + if (self.code_model.options['credential'] and self.code_model.options['credential_default_policy_type'] in [ + "ARMChallengeAuthenticationPolicy", "BearerTokenCredentialPolicy"]): # this ensures that the TokenCredentialSchema showing up in the list of code model's global parameters # is sync. This way we only have to make a copy for an async_credential _correct_credential_parameter(self.code_model.global_parameters, False) From 30f917b44dce21f876e24b873c7829897dbfc1c3 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Wed, 7 Jul 2021 16:54:30 +0800 Subject: [PATCH 6/9] fix test --- autorest/codegen/templates/config.py.jinja2 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autorest/codegen/templates/config.py.jinja2 b/autorest/codegen/templates/config.py.jinja2 index 3edb3f2873f..1ff61b4a0cb 100644 --- a/autorest/codegen/templates/config.py.jinja2 +++ b/autorest/codegen/templates/config.py.jinja2 @@ -81,5 +81,6 @@ class {{ code_model.class_name }}Configuration(Configuration): if self.credential and not self.authentication_policy: {% set credential_default_policy_type = ("Async" if (async_mode and code_model.options['credential_default_policy_type_has_async_version']) else "") + code_model.options['credential_default_policy_type'] %} {% set credential_param_type = ("'" + code_model.options['credential_key_header_name'] + "', ") if code_model.options['credential_key_header_name'] else ("*self.credential_scopes, " if "ARMChallengeAuthenticationPolicy" in credential_default_policy_type else "") %} - self.authentication_policy = {{ credential_default_policy_type }}(self.credential, {{ credential_param_type if credential_param_type }}**kwargs) + {% set policy_source = "" if "ARMChallengeAuthenticationPolicy" in credential_default_policy_type else "policies."} + self.authentication_policy = {{ policy_source }}{{ credential_default_policy_type }}(self.credential, {{ credential_param_type if credential_param_type }}**kwargs) {% endif %} From f7e7407fea8dcaf9f3e7fd23d22c73cf7385c326 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Wed, 7 Jul 2021 16:58:42 +0800 Subject: [PATCH 7/9] fix test --- autorest/multiapi/templates/multiapi_config.py.jinja2 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autorest/multiapi/templates/multiapi_config.py.jinja2 b/autorest/multiapi/templates/multiapi_config.py.jinja2 index b32c7acc87f..96fce0ffe0b 100644 --- a/autorest/multiapi/templates/multiapi_config.py.jinja2 +++ b/autorest/multiapi/templates/multiapi_config.py.jinja2 @@ -93,5 +93,6 @@ class {{ code_model.service_client.name }}Configuration(Configuration): if self.credential and not self.authentication_policy: {% set credential_default_policy_type = ("Async" if (async_mode and code_model.config.credential_default_policy_type_has_async_version) else "") + code_model.config.credential_default_policy_type %} {% set credential_param_type = ("'" + code_model.config.credential_key_header_name + "', ") if code_model.config.credential_key_header_name else ("*self.credential_scopes, " if "ARMChallengeAuthenticationPolicy" in credential_default_policy_type else "") %} - self.authentication_policy = {{ credential_default_policy_type }}(self.credential, {{ credential_param_type if credential_param_type }}**kwargs) + {% set policy_source = "" if "ARMChallengeAuthenticationPolicy" in credential_default_policy_type else "policies."} + self.authentication_policy ={{ policy_source }}{{ credential_default_policy_type }}(self.credential, {{ credential_param_type if credential_param_type }}**kwargs) {% endif %} From 8bbbf9770cfc93fc068bdd8c24d221607a8600ab Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Wed, 7 Jul 2021 17:00:12 +0800 Subject: [PATCH 8/9] fix test --- autorest/codegen/templates/config.py.jinja2 | 2 +- autorest/multiapi/templates/multiapi_config.py.jinja2 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/autorest/codegen/templates/config.py.jinja2 b/autorest/codegen/templates/config.py.jinja2 index 1ff61b4a0cb..1719fef3dd4 100644 --- a/autorest/codegen/templates/config.py.jinja2 +++ b/autorest/codegen/templates/config.py.jinja2 @@ -81,6 +81,6 @@ class {{ code_model.class_name }}Configuration(Configuration): if self.credential and not self.authentication_policy: {% set credential_default_policy_type = ("Async" if (async_mode and code_model.options['credential_default_policy_type_has_async_version']) else "") + code_model.options['credential_default_policy_type'] %} {% set credential_param_type = ("'" + code_model.options['credential_key_header_name'] + "', ") if code_model.options['credential_key_header_name'] else ("*self.credential_scopes, " if "ARMChallengeAuthenticationPolicy" in credential_default_policy_type else "") %} - {% set policy_source = "" if "ARMChallengeAuthenticationPolicy" in credential_default_policy_type else "policies."} + {% set policy_source = "" if "ARMChallengeAuthenticationPolicy" in credential_default_policy_type else "policies." %} self.authentication_policy = {{ policy_source }}{{ credential_default_policy_type }}(self.credential, {{ credential_param_type if credential_param_type }}**kwargs) {% endif %} diff --git a/autorest/multiapi/templates/multiapi_config.py.jinja2 b/autorest/multiapi/templates/multiapi_config.py.jinja2 index 96fce0ffe0b..0104e214d04 100644 --- a/autorest/multiapi/templates/multiapi_config.py.jinja2 +++ b/autorest/multiapi/templates/multiapi_config.py.jinja2 @@ -93,6 +93,6 @@ class {{ code_model.service_client.name }}Configuration(Configuration): if self.credential and not self.authentication_policy: {% set credential_default_policy_type = ("Async" if (async_mode and code_model.config.credential_default_policy_type_has_async_version) else "") + code_model.config.credential_default_policy_type %} {% set credential_param_type = ("'" + code_model.config.credential_key_header_name + "', ") if code_model.config.credential_key_header_name else ("*self.credential_scopes, " if "ARMChallengeAuthenticationPolicy" in credential_default_policy_type else "") %} - {% set policy_source = "" if "ARMChallengeAuthenticationPolicy" in credential_default_policy_type else "policies."} + {% set policy_source = "" if "ARMChallengeAuthenticationPolicy" in credential_default_policy_type else "policies." %} self.authentication_policy ={{ policy_source }}{{ credential_default_policy_type }}(self.credential, {{ credential_param_type if credential_param_type }}**kwargs) {% endif %} From 5d2821e402140be27a1d46977288b5c3dc81bd22 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Fri, 9 Jul 2021 14:40:42 +0800 Subject: [PATCH 9/9] set different default policy between data-plan and mgmt-plan --- autorest/codegen/__init__.py | 3 ++- docs/client/initializing.md | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/autorest/codegen/__init__.py b/autorest/codegen/__init__.py index 6ca861ceb03..9e933c849d2 100644 --- a/autorest/codegen/__init__.py +++ b/autorest/codegen/__init__.py @@ -185,8 +185,9 @@ def _get_credential_param(self, azure_arm, credential, credential_default_policy def _handle_default_authentication_policy(self, azure_arm, credential): + default_policy = 'ARMChallengeAuthenticationPolicy' if azure_arm else "BearerTokenCredentialPolicy" passed_in_credential_default_policy_type = ( - self._autorestapi.get_value("credential-default-policy-type") or "ARMChallengeAuthenticationPolicy" + self._autorestapi.get_value("credential-default-policy-type") or default_policy ) # right now, we only allow ARMChallengeAuthenticationPolicy, BearerTokenCredentialPolicy and diff --git a/docs/client/initializing.md b/docs/client/initializing.md index 02bb6e3f06e..d743b035200 100644 --- a/docs/client/initializing.md +++ b/docs/client/initializing.md @@ -22,9 +22,9 @@ The following are core libraries your generated code depend on, and the minimum | Library | Description | Min Version | | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | -| [`azure-core`][azure_core_library] | The most important library to have installed. It provides shared exceptions and modules for all the Python SDK client libraries. | 1.8.2 | +| [`azure-core`][azure_core_library] | The most important library to have installed. It provides shared exceptions and modules for all the Python SDK client libraries. | 1.15.0 | | [`msrest`][msrest_library] | Library mainly used for serializing and deserializing objects | 0.6.21 | -| [`azure-mgmt-core`][azure_mgmt_core_library] | Required if you're generating mgmt plane code (see `--azure-arm` flag in our [flag index][flag_index]. Provides mgmt plane specific shared exceptions and modules. | 1.2.1 | +| [`azure-mgmt-core`][azure_mgmt_core_library] | Required if you're generating mgmt plane code (see `--azure-arm` flag in our [flag index][flag_index]. Provides mgmt plane specific shared exceptions and modules. | 1.3.0 | > Note: We highly recommend tying your library to a major version, for instance, adding `azure-core<2.0.0` to tie the `azure-core` library to `1.x.x`