Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/terraform/azure-mgmt-terraform/_meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"commit": "ed3e7186654df4ec286c3d92f03dfa6c14b37279",
"commit": "aa41b251e8813bcf4d3b870a2c8f81d17dc1143a",
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
"typespec_src": "specification/terraform/Microsoft.AzureTerraform.Management",
"@azure-tools/typespec-python": "0.36.1"
"@azure-tools/typespec-python": "0.38.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
except AttributeError:
model_name = annotation
if module is not None:
annotation = _get_model(module, model_name)
annotation = _get_model(module, model_name) # type: ignore

try:
if module and _is_model(annotation):
Expand Down Expand Up @@ -894,6 +894,22 @@ def _deserialize(
return _deserialize_with_callable(deserializer, value)


def _failsafe_deserialize(
deserializer: typing.Any,
value: typing.Any,
module: typing.Optional[str] = None,
rf: typing.Optional["_RestField"] = None,
format: typing.Optional[str] = None,
) -> typing.Any:
try:
return _deserialize(deserializer, value, module, rf, format)
except DeserializationError:
_LOGGER.warning(
"Ran into a deserialization error. Ignoring since this is failsafe deserialization", exc_info=True
)
return None


class _RestField:
def __init__(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def _create_xml_node(tag, prefix=None, ns=None):
return ET.Element(tag)


class Model(object):
class Model:
"""Mixin for all client request body/response body models to support
serialization and deserialization.
"""
Expand Down Expand Up @@ -563,7 +563,7 @@ def _decode_attribute_map_key(key):
return key.replace("\\.", ".")


class Serializer(object): # pylint: disable=too-many-public-methods
class Serializer: # pylint: disable=too-many-public-methods
"""Request object model serializer."""

basic_types = {str: "str", int: "int", bool: "bool", float: "float"}
Expand Down Expand Up @@ -1441,7 +1441,7 @@ def xml_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argument
return children[0]


class Deserializer(object):
class Deserializer:
"""Response object model deserializer.

:param dict classes: Class type dictionary for deserializing complex types.
Expand Down Expand Up @@ -1683,17 +1683,21 @@ def _instantiate_model(self, response, attrs, additional_properties=None):
subtype = getattr(response, "_subtype_map", {})
try:
readonly = [
k for k, v in response._validation.items() if v.get("readonly") # pylint: disable=protected-access
k
for k, v in response._validation.items() # pylint: disable=protected-access # type: ignore
if v.get("readonly")
]
const = [
k for k, v in response._validation.items() if v.get("constant") # pylint: disable=protected-access
k
for k, v in response._validation.items() # pylint: disable=protected-access # type: ignore
if v.get("constant")
]
kwargs = {k: v for k, v in attrs.items() if k not in subtype and k not in readonly + const}
response_obj = response(**kwargs)
for attr in readonly:
setattr(response_obj, attr, attrs.get(attr))
if additional_properties:
response_obj.additional_properties = additional_properties
response_obj.additional_properties = additional_properties # type: ignore
return response_obj
except TypeError as err:
msg = "Unable to deserialize {} into model {}. ".format(kwargs, response) # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling

from ... import models as _models
from ..._model_base import SdkJSONEncoder, _deserialize
from ..._model_base import SdkJSONEncoder, _deserialize, _failsafe_deserialize
from ...operations._operations import build_operations_list_request, build_terraform_export_terraform_request

if sys.version_info >= (3, 9):
Expand Down Expand Up @@ -137,7 +137,7 @@ async def get_next(next_link=None):

if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
error = _deserialize(_models.ErrorResponse, response.json())
error = _failsafe_deserialize(_models.ErrorResponse, response.json())
raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

return pipeline_response
Expand Down Expand Up @@ -212,7 +212,7 @@ async def _export_terraform_initial(
except (StreamConsumedError, StreamClosedError):
pass
map_error(status_code=response.status_code, response=response, error_map=error_map)
error = _deserialize(_models.ErrorResponse, response.json())
error = _failsafe_deserialize(_models.ErrorResponse, response.json())
raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

response_headers = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from ._enums import ( # type: ignore
ActionType,
AuthorizationScopeFilter,
Origin,
ResourceProvisioningState,
TargetProvider,
Expand All @@ -51,6 +52,7 @@
"OperationDisplay",
"TerraformOperationStatus",
"ActionType",
"AuthorizationScopeFilter",
"Origin",
"ResourceProvisioningState",
"TargetProvider",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ class ActionType(str, Enum, metaclass=CaseInsensitiveEnumMeta):
"""Actions are for internal-only APIs."""


class AuthorizationScopeFilter(str, Enum, metaclass=CaseInsensitiveEnumMeta):
"""The Azure Resource Graph Authorization Scope Filter parameter."""

AT_SCOPE_AND_BELOW = "AtScopeAndBelow"
"""Returns assignments for the given scope and all child scopes."""
AT_SCOPE_AND_ABOVE = "AtScopeAndAbove"
"""Returns assignments for the given scope and all parent scopes, but not child scopes."""
AT_SCOPE_ABOVE_AND_BELOW = "AtScopeAboveAndBelow"
"""Returns assignments for the given scope, all parent scopes, and all child scopes."""
AT_SCOPE_EXACT = "AtScopeExact"
"""Returns assignments only for the given scope; no parent or child scopes are included."""


class Origin(str, Enum, metaclass=CaseInsensitiveEnumMeta):
"""The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit
logs UX. Default value is "user,system".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ class ExportQuery(BaseExportModel, discriminator="ExportQuery"):
:vartype recursive: bool
:ivar type: The parameter type. Required.
:vartype type: str or ~azure.mgmt.terraform.models.EXPORT_QUERY
:ivar table: The ARG table name.
:vartype table: str
:ivar authorization_scope_filter: The ARG Scope Filter parameter. Known values are:
"AtScopeAndBelow", "AtScopeAndAbove", "AtScopeAboveAndBelow", and "AtScopeExact".
:vartype authorization_scope_filter: str or
~azure.mgmt.terraform.models.AuthorizationScopeFilter
"""

query: str = rest_field()
Expand All @@ -184,6 +190,13 @@ class ExportQuery(BaseExportModel, discriminator="ExportQuery"):
"""Whether to recursively list child resources of the query result."""
type: Literal[Type.EXPORT_QUERY] = rest_discriminator(name="type") # type: ignore
"""The parameter type. Required."""
table: Optional[str] = rest_field()
"""The ARG table name."""
authorization_scope_filter: Optional[Union[str, "_models.AuthorizationScopeFilter"]] = rest_field(
name="authorizationScopeFilter"
)
"""The ARG Scope Filter parameter. Known values are: \"AtScopeAndBelow\", \"AtScopeAndAbove\",
\"AtScopeAboveAndBelow\", and \"AtScopeExact\"."""

@overload
def __init__(
Expand All @@ -195,6 +208,8 @@ def __init__(
mask_sensitive: Optional[bool] = None,
name_pattern: Optional[str] = None,
recursive: Optional[bool] = None,
table: Optional[str] = None,
authorization_scope_filter: Optional[Union[str, "_models.AuthorizationScopeFilter"]] = None,
) -> None: ...

@overload
Expand Down Expand Up @@ -325,6 +340,9 @@ class ExportResult(_model_base.Model):

:ivar configuration: The Terraform configuration content.
:vartype configuration: str
:ivar import_property: The Terraform import blocks for the current export, which users can use
to run "terraform plan" with to import the resources.
:vartype import_property: str
:ivar skipped_resources: A list of Azure resources which are not exported to Terraform due to
there is no corresponding resources in Terraform.
:vartype skipped_resources: list[str]
Expand All @@ -334,6 +352,9 @@ class ExportResult(_model_base.Model):

configuration: Optional[str] = rest_field()
"""The Terraform configuration content."""
import_property: Optional[str] = rest_field(name="import")
"""The Terraform import blocks for the current export, which users can use to run \"terraform
plan\" with to import the resources."""
skipped_resources: Optional[List[str]] = rest_field(name="skippedResources")
"""A list of Azure resources which are not exported to Terraform due to there is no corresponding
resources in Terraform."""
Expand All @@ -345,6 +366,7 @@ def __init__(
self,
*,
configuration: Optional[str] = None,
import_property: Optional[str] = None,
skipped_resources: Optional[List[str]] = None,
errors: Optional[List["_models.ErrorDetail"]] = None,
) -> None: ...
Expand Down Expand Up @@ -389,21 +411,21 @@ class Operation(_model_base.Model):
is_data_action: Optional[bool] = rest_field(name="isDataAction", visibility=["read"])
"""Whether the operation applies to data-plane. This is \"true\" for data-plane operations and
\"false\" for Azure Resource Manager/control-plane operations."""
display: Optional["_models.OperationDisplay"] = rest_field(visibility=["read"])
display: Optional["_models.OperationDisplay"] = rest_field()
"""Localized display information for this particular operation."""
origin: Optional[Union[str, "_models.Origin"]] = rest_field(visibility=["read"])
"""The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit
logs UX. Default value is \"user,system\". Known values are: \"user\", \"system\", and
\"user,system\"."""
action_type: Optional[Union[str, "_models.ActionType"]] = rest_field(name="actionType")
action_type: Optional[Union[str, "_models.ActionType"]] = rest_field(name="actionType", visibility=["read"])
"""Extensible enum. Indicates the action type. \"Internal\" refers to actions that are for
internal only APIs. \"Internal\""""

@overload
def __init__(
self,
*,
action_type: Optional[Union[str, "_models.ActionType"]] = None,
display: Optional["_models.OperationDisplay"] = None,
) -> None: ...

@overload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from azure.mgmt.core.polling.arm_polling import ARMPolling

from .. import models as _models
from .._model_base import SdkJSONEncoder, _deserialize
from .._model_base import SdkJSONEncoder, _deserialize, _failsafe_deserialize
from .._serialization import Serializer

if sys.version_info >= (3, 9):
Expand Down Expand Up @@ -185,7 +185,7 @@ def get_next(next_link=None):

if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
error = _deserialize(_models.ErrorResponse, response.json())
error = _failsafe_deserialize(_models.ErrorResponse, response.json())
raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

return pipeline_response
Expand Down Expand Up @@ -260,7 +260,7 @@ def _export_terraform_initial(
except (StreamConsumedError, StreamClosedError):
pass
map_error(status_code=response.status_code, response=response, error_map=error_map)
error = _deserialize(_models.ErrorResponse, response.json())
error = _failsafe_deserialize(_models.ErrorResponse, response.json())
raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

response_headers = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ def test_terraform_begin_export_terraform(self, resource_group):
body={
"query": "str",
"type": "ExportQuery",
"authorizationScopeFilter": "str",
"fullProperties": bool,
"maskSensitive": bool,
"namePattern": "str",
"recursive": bool,
"table": "str",
"targetProvider": "str",
},
).result() # call '.result()' to poll until service return final result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ async def test_terraform_begin_export_terraform(self, resource_group):
body={
"query": "str",
"type": "ExportQuery",
"authorizationScopeFilter": "str",
"fullProperties": bool,
"maskSensitive": bool,
"namePattern": "str",
"recursive": bool,
"table": "str",
"targetProvider": "str",
},
)
Expand Down
8 changes: 3 additions & 5 deletions sdk/terraform/azure-mgmt-terraform/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@

# Version extraction inspired from 'requests'
with open(
(
os.path.join(package_folder_path, "version.py")
if os.path.exists(os.path.join(package_folder_path, "version.py"))
else os.path.join(package_folder_path, "_version.py")
),
os.path.join(package_folder_path, "version.py")
if os.path.exists(os.path.join(package_folder_path, "version.py"))
else os.path.join(package_folder_path, "_version.py"),
"r",
) as fd:
version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE).group(1)
Expand Down
2 changes: 1 addition & 1 deletion sdk/terraform/azure-mgmt-terraform/tsp-location.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
directory: specification/terraform/Microsoft.AzureTerraform.Management
commit: ed3e7186654df4ec286c3d92f03dfa6c14b37279
commit: aa41b251e8813bcf4d3b870a2c8f81d17dc1143a
repo: Azure/azure-rest-api-specs
additionalDirectories:
Loading