@autorest/python 6.1.11 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autorest/_utils.py +2 -1
- package/autorest/codegen/__init__.py +23 -81
- package/autorest/codegen/models/__init__.py +5 -3
- package/autorest/codegen/models/{base_type.py → base.py} +24 -3
- package/autorest/codegen/models/base_builder.py +9 -5
- package/autorest/codegen/models/client.py +183 -13
- package/autorest/codegen/models/code_model.py +154 -141
- package/autorest/codegen/models/combined_type.py +5 -2
- package/autorest/codegen/models/constant_type.py +38 -4
- package/autorest/codegen/models/credential_types.py +1 -1
- package/autorest/codegen/models/dictionary_type.py +1 -1
- package/autorest/codegen/models/enum_type.py +5 -3
- package/autorest/codegen/models/imports.py +78 -29
- package/autorest/codegen/models/list_type.py +1 -1
- package/autorest/codegen/models/lro_operation.py +5 -1
- package/autorest/codegen/models/model_type.py +1 -2
- package/autorest/codegen/models/operation.py +34 -10
- package/autorest/codegen/models/operation_group.py +16 -5
- package/autorest/codegen/models/paging_operation.py +5 -4
- package/autorest/codegen/models/parameter.py +19 -6
- package/autorest/codegen/models/primitive_types.py +1 -2
- package/autorest/codegen/models/property.py +4 -4
- package/autorest/codegen/models/request_builder.py +17 -6
- package/autorest/codegen/models/request_builder_parameter.py +5 -2
- package/autorest/codegen/models/response.py +6 -3
- package/autorest/codegen/serializers/__init__.py +207 -135
- package/autorest/codegen/serializers/builder_serializer.py +2 -4
- package/autorest/codegen/serializers/client_serializer.py +41 -45
- package/autorest/codegen/serializers/general_serializer.py +80 -37
- package/autorest/codegen/serializers/import_serializer.py +30 -36
- package/autorest/codegen/serializers/metadata_serializer.py +36 -14
- package/autorest/codegen/serializers/model_serializer.py +34 -19
- package/autorest/codegen/serializers/operation_groups_serializer.py +22 -6
- package/autorest/codegen/serializers/operations_init_serializer.py +10 -4
- package/autorest/codegen/serializers/sample_serializer.py +144 -0
- package/autorest/codegen/templates/client.py.jinja2 +7 -15
- package/autorest/codegen/templates/client_container.py.jinja2 +12 -0
- package/autorest/codegen/templates/config.py.jinja2 +13 -26
- package/autorest/codegen/templates/config_container.py.jinja2 +16 -0
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/init.py.jinja2 +9 -3
- package/autorest/codegen/templates/lro_operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/metadata.json.jinja2 +13 -14
- package/autorest/codegen/templates/model_dpg.py.jinja2 +4 -4
- package/autorest/codegen/templates/model_init.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_group.py.jinja2 +2 -2
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +5 -5
- package/autorest/codegen/templates/operation_tools.jinja2 +2 -2
- package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -4
- package/autorest/codegen/templates/{CHANGELOG.md.jinja2 → packaging_templates/CHANGELOG.md.jinja2} +0 -0
- package/autorest/codegen/templates/{LICENSE.jinja2 → packaging_templates/LICENSE.jinja2} +0 -0
- package/autorest/codegen/templates/{MANIFEST.in.jinja2 → packaging_templates/MANIFEST.in.jinja2} +0 -0
- package/autorest/codegen/templates/{README.md.jinja2 → packaging_templates/README.md.jinja2} +0 -0
- package/autorest/codegen/templates/{dev_requirements.txt.jinja2 → packaging_templates/dev_requirements.txt.jinja2} +0 -0
- package/autorest/codegen/templates/{setup.py.jinja2 → packaging_templates/setup.py.jinja2} +12 -9
- package/autorest/codegen/templates/request_builders.py.jinja2 +2 -2
- package/autorest/codegen/templates/sample.py.jinja2 +44 -0
- package/autorest/codegen/templates/vendor.py.jinja2 +4 -2
- package/autorest/m4reformatter/__init__.py +18 -4
- package/autorest/multiapi/models/imports.py +89 -18
- package/autorest/multiapi/serializers/import_serializer.py +88 -7
- package/autorest/multiapi/utils.py +6 -0
- package/autorest/preprocess/__init__.py +20 -8
- package/package.json +1 -1
- package/run_cadl.py +0 -1
- package/autorest/cadlflags/__init__.py +0 -130
- package/autorest/codegen/models/base_model.py +0 -28
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
# -------------------------------------------------------------------------
|
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
-
# license information.
|
|
5
|
-
# --------------------------------------------------------------------------
|
|
6
|
-
import logging
|
|
7
|
-
from typing import Any, Dict, List
|
|
8
|
-
from .. import YamlUpdatePlugin
|
|
9
|
-
from .._utils import parse_args
|
|
10
|
-
|
|
11
|
-
_LOGGER = logging.getLogger(__name__)
|
|
12
|
-
|
|
13
|
-
OAUTH_TYPE = "OAuth2"
|
|
14
|
-
KEY_TYPE = "Key"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def get_azure_key_credential(key: str) -> Dict[str, Any]:
|
|
18
|
-
return {
|
|
19
|
-
"type": KEY_TYPE,
|
|
20
|
-
"policy": {"type": "AzureKeyCredentialPolicy", "key": key},
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class CadlFlags(YamlUpdatePlugin): # pylint: disable=abstract-method
|
|
25
|
-
"""A plugin to apply flags from backdoor python.json into cadl yaml file"""
|
|
26
|
-
|
|
27
|
-
def update_yaml(self, yaml_data: Dict[str, Any]) -> None:
|
|
28
|
-
"""Convert in place the YAML str."""
|
|
29
|
-
if self.options.get("add-credential"):
|
|
30
|
-
self.update_credential(yaml_data)
|
|
31
|
-
if self.options.get("namespace"):
|
|
32
|
-
yaml_data["client"]["namespace"] = self.options["namespace"]
|
|
33
|
-
if self.options.get("title"):
|
|
34
|
-
yaml_data["client"]["name"] = self.options["title"]
|
|
35
|
-
|
|
36
|
-
def get_credential_scopes_from_flags(self, auth_policy: str) -> List[str]:
|
|
37
|
-
if self.options.get("azure-arm"):
|
|
38
|
-
return ["https://management.azure.com/.default"]
|
|
39
|
-
credential_scopes_temp = self.options.get("credential-scopes")
|
|
40
|
-
credential_scopes = (
|
|
41
|
-
credential_scopes_temp.split(",") if credential_scopes_temp else None
|
|
42
|
-
)
|
|
43
|
-
if self.options.get("credential-scopes", False) and not credential_scopes:
|
|
44
|
-
raise ValueError(
|
|
45
|
-
"--credential-scopes takes a list of scopes in comma separated format. "
|
|
46
|
-
"For example: --credential-scopes=https://cognitiveservices.azure.com/.default"
|
|
47
|
-
)
|
|
48
|
-
if not credential_scopes:
|
|
49
|
-
_LOGGER.warning(
|
|
50
|
-
"You have default credential policy %s "
|
|
51
|
-
"but not the --credential-scopes flag set while generating non-management plane code. "
|
|
52
|
-
"This is not recommend because it forces the customer to pass credential scopes "
|
|
53
|
-
"through kwargs if they want to authenticate.",
|
|
54
|
-
auth_policy,
|
|
55
|
-
)
|
|
56
|
-
credential_scopes = []
|
|
57
|
-
return credential_scopes
|
|
58
|
-
|
|
59
|
-
def get_token_credential(self, credential_scopes: List[str]) -> Dict[str, Any]:
|
|
60
|
-
return {
|
|
61
|
-
"type": OAUTH_TYPE,
|
|
62
|
-
"policy": {
|
|
63
|
-
"type": "ARMChallengeAuthenticationPolicy"
|
|
64
|
-
if self.options.get("azure-arm")
|
|
65
|
-
else "BearerTokenCredentialPolicy",
|
|
66
|
-
"credentialScopes": credential_scopes,
|
|
67
|
-
},
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
def update_credential_from_flags(self) -> Dict[str, Any]:
|
|
71
|
-
default_auth_policy = (
|
|
72
|
-
"ARMChallengeAuthenticationPolicy"
|
|
73
|
-
if self.options.get("azure-arm")
|
|
74
|
-
else "BearerTokenCredentialPolicy"
|
|
75
|
-
)
|
|
76
|
-
auth_policy = (
|
|
77
|
-
self.options.get("credential-default-policy-type") or default_auth_policy
|
|
78
|
-
)
|
|
79
|
-
credential_scopes = self.get_credential_scopes_from_flags(auth_policy)
|
|
80
|
-
key = self.options.get("credential-key-header-name")
|
|
81
|
-
if auth_policy.lower() in (
|
|
82
|
-
"armchallengeauthenticationpolicy",
|
|
83
|
-
"bearertokencredentialpolicy",
|
|
84
|
-
):
|
|
85
|
-
if key:
|
|
86
|
-
raise ValueError(
|
|
87
|
-
"You have passed in a credential key header name with default credential policy type "
|
|
88
|
-
f"{auth_policy}. This is not allowed, since credential key header "
|
|
89
|
-
"name is tied with AzureKeyCredentialPolicy. Instead, with this policy it is recommend you "
|
|
90
|
-
"pass in --credential-scopes."
|
|
91
|
-
)
|
|
92
|
-
return self.get_token_credential(credential_scopes)
|
|
93
|
-
# Otherwise you have AzureKeyCredentialPolicy
|
|
94
|
-
if self.options.get("credential-scopes"):
|
|
95
|
-
raise ValueError(
|
|
96
|
-
"You have passed in credential scopes with default credential policy type "
|
|
97
|
-
"AzureKeyCredentialPolicy. This is not allowed, since credential scopes is tied with "
|
|
98
|
-
f"{default_auth_policy}. Instead, with this policy "
|
|
99
|
-
"you must pass in --credential-key-header-name."
|
|
100
|
-
)
|
|
101
|
-
if not key:
|
|
102
|
-
key = "api-key"
|
|
103
|
-
_LOGGER.info(
|
|
104
|
-
"Defaulting the AzureKeyCredentialPolicy header's name to 'api-key'"
|
|
105
|
-
)
|
|
106
|
-
return get_azure_key_credential(key)
|
|
107
|
-
|
|
108
|
-
def update_credential(self, yaml_data: Dict[str, Any]) -> None:
|
|
109
|
-
credential_type = self.update_credential_from_flags()
|
|
110
|
-
yaml_data["types"].append(credential_type)
|
|
111
|
-
credential = {
|
|
112
|
-
"type": credential_type,
|
|
113
|
-
"optional": False,
|
|
114
|
-
"description": "Credential needed for the client to connect to Azure.",
|
|
115
|
-
"clientName": "credential",
|
|
116
|
-
"location": "other",
|
|
117
|
-
"restApiName": "credential",
|
|
118
|
-
"implementation": "Client",
|
|
119
|
-
"skipUrlEncoding": True,
|
|
120
|
-
"inOverload": False,
|
|
121
|
-
}
|
|
122
|
-
yaml_data["client"]["parameters"].append(credential)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if __name__ == "__main__":
|
|
126
|
-
# CADL pipeline will call this
|
|
127
|
-
args, unknown_args = parse_args()
|
|
128
|
-
CadlFlags(
|
|
129
|
-
output_folder=args.output_folder, cadl_file=args.cadl_file, **unknown_args
|
|
130
|
-
).process()
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# -------------------------------------------------------------------------
|
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
-
# license information.
|
|
5
|
-
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import Any, Dict, TYPE_CHECKING
|
|
7
|
-
|
|
8
|
-
if TYPE_CHECKING:
|
|
9
|
-
from .code_model import CodeModel
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class BaseModel:
|
|
13
|
-
"""This is the base class for model representations that are based on some YAML data.
|
|
14
|
-
|
|
15
|
-
:param yaml_data: the yaml data for this schema
|
|
16
|
-
:type yaml_data: dict[str, Any]
|
|
17
|
-
"""
|
|
18
|
-
|
|
19
|
-
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
20
|
-
self.yaml_data = yaml_data
|
|
21
|
-
self.code_model = code_model
|
|
22
|
-
|
|
23
|
-
@property
|
|
24
|
-
def id(self) -> int:
|
|
25
|
-
return id(self.yaml_data)
|
|
26
|
-
|
|
27
|
-
def __repr__(self):
|
|
28
|
-
return f"<{self.__class__.__name__}>"
|