def update_credential_from_flags()

in packages/autorest.python/autorest/m4reformatter/__init__.py [0:0]


    def update_credential_from_flags(self) -> Dict[str, Any]:
        default_auth_policy = "BearerTokenCredentialPolicy"
        auth_policy = self._autorestapi.get_value("credential-default-policy-type") or default_auth_policy
        credential_scopes = self.get_credential_scopes_from_flags(auth_policy)
        key = self._autorestapi.get_value("credential-key-header-name")
        if auth_policy.lower() in (
            "armchallengeauthenticationpolicy",
            "bearertokencredentialpolicy",
        ):
            if key:
                raise ValueError(
                    "You have passed in a credential key header name with default credential policy type "
                    f"{auth_policy}. 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."
                )
            return self.get_token_credential(credential_scopes)
        # Otherwise you have AzureKeyCredentialPolicy
        if self._autorestapi.get_value("credential-scopes"):
            raise ValueError(
                "You have passed in credential scopes with default credential policy type "
                "AzureKeyCredentialPolicy. This is not allowed, since credential scopes is tied with "
                f"{default_auth_policy}. Instead, with this policy "
                "you must pass in --credential-key-header-name."
            )
        if not key:
            key = "api-key"
            _LOGGER.info("Defaulting the AzureKeyCredentialPolicy header's name to 'api-key'")
        return get_azure_key_credential(key)