diff --git a/src/aks-preview/azext_aks_preview/_client_factory.py b/src/aks-preview/azext_aks_preview/_client_factory.py index 2beb55ae0ec..4b48500daa9 100644 --- a/src/aks-preview/azext_aks_preview/_client_factory.py +++ b/src/aks-preview/azext_aks_preview/_client_factory.py @@ -39,6 +39,10 @@ def cf_machines(cli_ctx, *_): return get_container_service_client(cli_ctx).machines +def cf_identity_bindings(cli_ctx, *_): + return get_container_service_client(cli_ctx).identity_bindings + + def cf_operations(cli_ctx, *_): return get_container_service_client(cli_ctx).operation_status_result diff --git a/src/aks-preview/azext_aks_preview/aks_identity_binding/__init__.py b/src/aks-preview/azext_aks_preview/aks_identity_binding/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/aks-preview/azext_aks_preview/aks_identity_binding/commands.py b/src/aks-preview/azext_aks_preview/aks_identity_binding/commands.py new file mode 100644 index 00000000000..e7784fe2e89 --- /dev/null +++ b/src/aks-preview/azext_aks_preview/aks_identity_binding/commands.py @@ -0,0 +1,92 @@ +# `az aks identity-binding create` command +def aks_ib_cmd_create( + cmd, client, + resource_group_name: str, + cluster_name: str, + name: str, + managed_identity_resource_id: str, + no_wait: bool = False, +): + from azure.mgmt.core.tools import parse_resource_id + from azure.cli.core.util import sdk_no_wait + from azext_aks_preview._client_factory import get_msi_client + from azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks.models import ( + IdentityBinding, + IdentityBindingProperties, + IdentityBindingManagedIdentityProfile, + ) + + # FIXME(hbc): workaround for resolving MI from client side + parsed_managed_identity_resource_id = parse_resource_id(managed_identity_resource_id) + msi_client = get_msi_client(cmd.cli_ctx, subscription_id=parsed_managed_identity_resource_id['subscription']) + msi = msi_client.user_assigned_identities.get( + parsed_managed_identity_resource_id['resource_group'], + parsed_managed_identity_resource_id['resource_name'], + ) + + instance = IdentityBinding( + name=name, + properties=IdentityBindingProperties( + managed_identity=IdentityBindingManagedIdentityProfile( + resource_id=managed_identity_resource_id, + client_id=msi.client_id, + object_id=msi.principal_id, + tenant_id=msi.tenant_id, + ) + ) + ) + instance.name = name + print(instance) + + return sdk_no_wait( + no_wait, + client.begin_create_or_update, + resource_group_name, + cluster_name, + name, + instance, + ) + +# `az aks identity-binding delete` command +def aks_ib_cmd_delete( + cmd, client, + resource_group_name: str, + cluster_name: str, + name: str, + no_wait: bool = False, +): + from azure.cli.core.util import sdk_no_wait + + return sdk_no_wait( + no_wait, + client.begin_delete, + resource_group_name=resource_group_name, + resource_name=cluster_name, + identity_binding_name=name, + ) + + +# `az aks identity-binding show` command +def aks_ib_cmd_show( + cmd, client, + resource_group_name: str, + cluster_name: str, + name: str, +): + return client.get( + resource_group_name=resource_group_name, + resource_name=cluster_name, + identity_binding_name=name, + ) + + +# `az aks identity-binding list` command +def aks_ib_cmd_list( + cmd, client, + resource_group_name: str, + cluster_name: str, +): + return client.list_by_managed_cluster( + resource_group_name=resource_group_name, + resource_name=cluster_name, + ) diff --git a/src/aks-preview/azext_aks_preview/commands.py b/src/aks-preview/azext_aks_preview/commands.py index 98de881c916..410efd54cbc 100644 --- a/src/aks-preview/azext_aks_preview/commands.py +++ b/src/aks-preview/azext_aks_preview/commands.py @@ -14,6 +14,7 @@ cf_machines, cf_operations, cf_load_balancers, + cf_identity_bindings, ) from azext_aks_preview._format import ( aks_addon_list_available_table_format, @@ -430,3 +431,12 @@ def load_command_table(self, _): "aks check-network", managed_clusters_sdk, client_factory=cf_managed_clusters ) as g: g.custom_command("outbound", "aks_check_network_outbound") + + # AKS identity binding commands + with self.command_group( + "aks identity-binding", managed_clusters_sdk, client_factory=cf_identity_bindings + ) as g: + g.custom_command("create", "aks_identity_binding_create") + g.custom_command("delete", "aks_identity_binding_delete") + g.custom_command("show", "aks_identity_binding_show") + g.custom_command("list", "aks_identity_binding_list") \ No newline at end of file diff --git a/src/aks-preview/azext_aks_preview/custom.py b/src/aks-preview/azext_aks_preview/custom.py index bb0bddd2982..c36fa290ffa 100644 --- a/src/aks-preview/azext_aks_preview/custom.py +++ b/src/aks-preview/azext_aks_preview/custom.py @@ -89,6 +89,12 @@ from azext_aks_preview.maintenanceconfiguration import ( aks_maintenanceconfiguration_update_internal, ) +from azext_aks_preview.aks_identity_binding.commands import ( + aks_ib_cmd_create, + aks_ib_cmd_delete, + aks_ib_cmd_show, + aks_ib_cmd_list, +) from azure.cli.command_modules.acs._helpers import ( get_user_assigned_identity_by_resource_id ) @@ -3821,3 +3827,9 @@ def aks_loadbalancer_rebalance_nodes( } return aks_loadbalancer_rebalance_internal(managed_clusters_client, parameters) + + +aks_identity_binding_create = aks_ib_cmd_create +aks_identity_binding_delete = aks_ib_cmd_delete +aks_identity_binding_show = aks_ib_cmd_show +aks_identity_binding_list = aks_ib_cmd_list \ No newline at end of file diff --git a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/_container_service_client.py b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/_container_service_client.py index 0feccc2ad48..ee1d10ef4fb 100644 --- a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/_container_service_client.py +++ b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/_container_service_client.py @@ -136,6 +136,9 @@ def models(cls, api_version=DEFAULT_API_VERSION): elif api_version == '2025-02-02-preview': from .v2025_02_02_preview import models return models + elif api_version == '2025-04-02-preview': + from .v2025_02_02_preview import models + return models raise ValueError("API version {} is not available".format(api_version)) @property @@ -220,6 +223,17 @@ def machines(self): self._config.api_version = api_version return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)), api_version) + @property + def identity_bindings(self): + api_version = '2025-04-02-preview' + from .v2025_02_02_preview.operations import IdentityBindingsOperations as OperationClass + return OperationClass( + self._client, self._config, + Serializer(self._models_dict(api_version)), + Deserializer(self._models_dict(api_version)), + api_version + ) + @property def maintenance_configurations(self): """Instance depends on the API version: diff --git a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/_serialization.py b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/_serialization.py index 05bcd7d403a..a4e6b9db168 100644 --- a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/_serialization.py +++ b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/_serialization.py @@ -1413,6 +1413,11 @@ def _deserialize(self, target_obj, data): # pylint: disable=inconsistent-return :return: Deserialized object. :rtype: object """ + # FIXME(hbc): wrong server side response content type header + if isinstance(target_obj, str) and 'IdentityBinding' in target_obj and isinstance(data, str): + import json + data = json.loads(data) + # This is already a model, go recursive just in case if hasattr(data, "_attribute_map"): constants = [name for name, config in getattr(data, "_validation", {}).items() if config.get("constant")] @@ -1470,6 +1475,7 @@ def _deserialize(self, target_obj, data): # pylint: disable=inconsistent-return value = self.deserialize_data(raw_value, attr_desc["type"]) d_attrs[attr] = value except (AttributeError, TypeError, KeyError) as err: + print(err) msg = "Unable to deserialize to object: " + class_name # type: ignore raise DeserializationError(msg) from err additional_properties = self._build_additional_properties(attributes, data) diff --git a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/_container_service_client.py b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/_container_service_client.py index 8f61570898d..98072d91011 100644 --- a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/_container_service_client.py +++ b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/_container_service_client.py @@ -21,6 +21,7 @@ from .operations import ( AgentPoolsOperations, ContainerServiceOperations, + IdentityBindingsOperations, LoadBalancersOperations, MachinesOperations, MaintenanceConfigurationsOperations, @@ -135,6 +136,7 @@ def __init__( self._client: ARMPipelineClient = ARMPipelineClient(base_url=base_url, policies=_policies, **kwargs) client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)} + print('client_models', client_models) self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) self._serialize.client_side_validation = False @@ -186,6 +188,9 @@ def __init__( self.load_balancers = LoadBalancersOperations( self._client, self._config, self._serialize, self._deserialize, "2025-02-02-preview" ) + self.identity_bindings = IdentityBindingsOperations( + self._client, self._config, self._serialize, self._deserialize, "2025-04-02-preview" + ) def _send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: """Runs the network request through the client's chained policies. diff --git a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/models/__init__.py b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/models/__init__.py index 435a5ac131b..71413886367 100644 --- a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/models/__init__.py +++ b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/models/__init__.py @@ -62,6 +62,11 @@ GuardrailsAvailableVersionsList, GuardrailsAvailableVersionsProperties, IPTag, + IdentityBinding, + IdentityBindingListResult, + IdentityBindingManagedIdentityProfile, + IdentityBindingOidcIssuerProfile, + IdentityBindingProperties, IstioCertificateAuthority, IstioComponents, IstioEgressGateway, @@ -245,6 +250,7 @@ GPUInstanceProfile, GuardrailsSupport, IPFamily, + IdentityBindingProvisioningState, IpvsScheduler, IstioIngressGatewayMode, KeyVaultNetworkAccessTypes, @@ -347,6 +353,11 @@ "GuardrailsAvailableVersionsList", "GuardrailsAvailableVersionsProperties", "IPTag", + "IdentityBinding", + "IdentityBindingListResult", + "IdentityBindingManagedIdentityProfile", + "IdentityBindingOidcIssuerProfile", + "IdentityBindingProperties", "IstioCertificateAuthority", "IstioComponents", "IstioEgressGateway", @@ -527,6 +538,7 @@ "GPUInstanceProfile", "GuardrailsSupport", "IPFamily", + "IdentityBindingProvisioningState", "IpvsScheduler", "IstioIngressGatewayMode", "KeyVaultNetworkAccessTypes", diff --git a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/models/_container_service_client_enums.py b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/models/_container_service_client_enums.py index d1a019a7f91..afd7304dcfb 100644 --- a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/models/_container_service_client_enums.py +++ b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/models/_container_service_client_enums.py @@ -232,6 +232,23 @@ class GuardrailsSupport(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The version is stable and can be used on critical production clusters.""" +class IdentityBindingProvisioningState(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """The provisioning state of the last accepted operation.""" + + SUCCEEDED = "Succeeded" + """Resource has been created.""" + FAILED = "Failed" + """Resource creation failed.""" + CANCELED = "Canceled" + """Resource creation was canceled.""" + CREATING = "Creating" + """The provisioning state of an identity binding being created.""" + UPDATING = "Updating" + """The provisioning state of an identity binding being updated.""" + DELETING = "Deleting" + """The provisioning state of an identity binding being deleted.""" + + class IPFamily(str, Enum, metaclass=CaseInsensitiveEnumMeta): """To determine if address belongs IPv4 or IPv6 family.""" diff --git a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/models/_models_py3.py b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/models/_models_py3.py index 1a5df5a902e..7228d9ae3df 100644 --- a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/models/_models_py3.py +++ b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/models/_models_py3.py @@ -11534,3 +11534,227 @@ def __init__( self.enabled = enabled self.dns_server = dns_server self.root_domain_name = root_domain_name + + +class IdentityBinding(ProxyResource): + """The IdentityBinding resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. E.g. + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}". + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~azure.mgmt.containerservice.v2025_02_02_preview.models.SystemData + :ivar properties: The resource-specific properties for this resource. + :vartype properties: + ~azure.mgmt.containerservice.v2025_02_02_preview.models.IdentityBindingProperties + :ivar e_tag: If eTag is provided in the response body, it may also be provided as a header per + the normal etag convention. Entity tags are used for comparing two or more entities from the + same requested resource. HTTP/1.1 uses entity tags in the etag (section 14.19), If-Match + (section 14.24), If-None-Match (section 14.26), and If-Range (section 14.27) header fields. + :vartype e_tag: str + """ + + _validation = { + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "system_data": {"readonly": True}, + "e_tag": {"readonly": True}, + } + + _attribute_map = { + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "system_data": {"key": "systemData", "type": "SystemData"}, + "properties": {"key": "properties", "type": "IdentityBindingProperties"}, + "e_tag": {"key": "eTag", "type": "str"}, + } + + def __init__(self, *, properties: Optional["_models.IdentityBindingProperties"] = None, **kwargs: Any) -> None: + """ + :keyword properties: The resource-specific properties for this resource. + :paramtype properties: + ~azure.mgmt.containerservice.v2025_02_02_preview.models.IdentityBindingProperties + """ + super().__init__(**kwargs) + self.properties = properties + self.e_tag: Optional[str] = None + + +class IdentityBindingListResult(_serialization.Model): + """The response of a IdentityBinding list operation. + + All required parameters must be populated in order to send to server. + + :ivar value: The IdentityBinding items on this page. Required. + :vartype value: list[~azure.mgmt.containerservice.v2025_02_02_preview.models.IdentityBinding] + :ivar next_link: The link to the next page of items. + :vartype next_link: str + """ + + _validation = { + "value": {"required": True}, + } + + _attribute_map = { + "value": {"key": "value", "type": "[IdentityBinding]"}, + "next_link": {"key": "nextLink", "type": "str"}, + } + + def __init__( + self, *, value: List["_models.IdentityBinding"], next_link: Optional[str] = None, **kwargs: Any + ) -> None: + """ + :keyword value: The IdentityBinding items on this page. Required. + :paramtype value: list[~azure.mgmt.containerservice.v2025_02_02_preview.models.IdentityBinding] + :keyword next_link: The link to the next page of items. + :paramtype next_link: str + """ + super().__init__(**kwargs) + self.value = value + self.next_link = next_link + + +class IdentityBindingManagedIdentityProfile(_serialization.Model): + """IdentityBinding managed identity profile. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to server. + + :ivar resource_id: The resource ID of the managed identity. Required. + :vartype resource_id: str + :ivar object_id: The object ID of the managed identity. + :vartype object_id: str + :ivar client_id: The client ID of the managed identity. + :vartype client_id: str + :ivar tenant_id: The tenant ID of the managed identity. + :vartype tenant_id: str + """ + + _validation = { + "resource_id": { + "required": True, + "pattern": r"^/subscriptions/[a-zA-Z0-9-]+/resourceGroups/[a-zA-Z0-9-]+/providers/Microsoft.ManagedIdentity/userAssignedIdentities/[a-zA-Z0-9-]+$", + }, + "object_id": { + # FIXME: disable for client side value + # "readonly": True, + "max_length": 36, + "min_length": 36, + "pattern": r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", + }, + "client_id": { + # FIXME: disable for client side value + # "readonly": True, + "max_length": 36, + "min_length": 36, + "pattern": r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", + }, + "tenant_id": { + # FIXME: disable for client side value + # "readonly": True, + "max_length": 36, + "min_length": 36, + "pattern": r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", + }, + } + + _attribute_map = { + "resource_id": {"key": "resourceId", "type": "str"}, + "object_id": {"key": "objectId", "type": "str"}, + "client_id": {"key": "clientId", "type": "str"}, + "tenant_id": {"key": "tenantId", "type": "str"}, + } + + def __init__(self, *, resource_id: str, **kwargs: Any) -> None: + """ + :keyword resource_id: The resource ID of the managed identity. Required. + :paramtype resource_id: str + """ + super().__init__(**kwargs) + self.resource_id = resource_id + # FIXME: disable for client side value + self.object_id = kwargs.get('object_id', None) + self.client_id = kwargs.get('client_id', None) + self.tenant_id = kwargs.get('tenant_id', None) + # self.object_id: Optional[str] = None + # self.client_id: Optional[str] = None + # self.tenant_id: Optional[str] = None + + +class IdentityBindingOidcIssuerProfile(_serialization.Model): + """IdentityBinding OIDC issuer profile. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to server. + + :ivar oidc_issuer_url: The OIDC issuer URL of the IdentityBinding. Required. + :vartype oidc_issuer_url: str + """ + + _validation = { + "oidc_issuer_url": {"required": True, "readonly": True}, + } + + _attribute_map = { + "oidc_issuer_url": {"key": "oidcIssuerUrl", "type": "str"}, + } + + def __init__(self, **kwargs: Any) -> None: + """ """ + super().__init__(**kwargs) + self.oidc_issuer_url: Optional[str] = None + + +class IdentityBindingProperties(_serialization.Model): + """IdentityBinding properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to server. + + :ivar managed_identity: The managed cluster resource ID. Required. + :vartype managed_identity: + ~azure.mgmt.containerservice.v2025_02_02_preview.models.IdentityBindingManagedIdentityProfile + :ivar oidc_issuer: The OIDC issuer URL of the IdentityBinding. + :vartype oidc_issuer: + ~azure.mgmt.containerservice.v2025_02_02_preview.models.IdentityBindingOidcIssuerProfile + :ivar provisioning_state: The status of the last operation. Known values are: "Succeeded", + "Failed", "Canceled", "Creating", "Updating", and "Deleting". + :vartype provisioning_state: str or + ~azure.mgmt.containerservice.v2025_02_02_preview.models.IdentityBindingProvisioningState + """ + + _validation = { + "managed_identity": {"required": True}, + "oidc_issuer": {"readonly": True}, + "provisioning_state": {"readonly": True}, + } + + _attribute_map = { + "managed_identity": {"key": "managedIdentity", "type": "IdentityBindingManagedIdentityProfile"}, + "oidc_issuer": {"key": "oidcIssuer", "type": "IdentityBindingOidcIssuerProfile"}, + "provisioning_state": {"key": "provisioningState", "type": "str"}, + } + + def __init__(self, *, managed_identity: "_models.IdentityBindingManagedIdentityProfile", **kwargs: Any) -> None: + """ + :keyword managed_identity: The managed cluster resource ID. Required. + :paramtype managed_identity: + ~azure.mgmt.containerservice.v2025_02_02_preview.models.IdentityBindingManagedIdentityProfile + """ + super().__init__(**kwargs) + self.managed_identity = managed_identity + self.oidc_issuer: Optional["_models.IdentityBindingOidcIssuerProfile"] = None + self.provisioning_state: Optional[Union[str, "_models.IdentityBindingProvisioningState"]] = None \ No newline at end of file diff --git a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/operations/__init__.py b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/operations/__init__.py index f8fd4f978b6..f51f3039fa4 100644 --- a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/operations/__init__.py +++ b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/operations/__init__.py @@ -28,6 +28,7 @@ from ._trusted_access_roles_operations import TrustedAccessRolesOperations # type: ignore from ._trusted_access_role_bindings_operations import TrustedAccessRoleBindingsOperations # type: ignore from ._load_balancers_operations import LoadBalancersOperations # type: ignore +from ._identity_bindings_operations import IdentityBindingsOperations # type: ignore from ._patch import __all__ as _patch_all from ._patch import * @@ -50,6 +51,7 @@ "TrustedAccessRolesOperations", "TrustedAccessRoleBindingsOperations", "LoadBalancersOperations", + "IdentityBindingsOperations", ] __all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore _patch_sdk() diff --git a/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/operations/_identity_bindings_operations.py b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/operations/_identity_bindings_operations.py new file mode 100644 index 00000000000..2ea699945a8 --- /dev/null +++ b/src/aks-preview/azext_aks_preview/vendored_sdks/azure_mgmt_preview_aks/v2025_02_02_preview/operations/_identity_bindings_operations.py @@ -0,0 +1,763 @@ +# pylint: disable=line-too-long,useless-suppression +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from collections.abc import MutableMapping +from io import IOBase +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, TypeVar, Union, cast, overload +import urllib.parse + +from azure.core import PipelineClient +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, + map_error, +) +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest, HttpResponse +from azure.core.tracing.decorator import distributed_trace +from azure.core.utils import case_insensitive_dict +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from ..._serialization import Deserializer, Serializer +from .._configuration import ContainerServiceClientConfiguration + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + + +def build_list_by_managed_cluster_request( + resource_group_name: str, resource_name: str, subscription_id: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2025-01-02-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/identityBindings", + ) + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url( + "resource_group_name", resource_group_name, "str", max_length=90, min_length=1 + ), + "resourceName": _SERIALIZER.url( + "resource_name", + resource_name, + "str", + max_length=63, + min_length=1, + pattern=r"^[a-zA-Z0-9]$|^[a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]$", + ), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_get_request( + resource_group_name: str, resource_name: str, identity_binding_name: str, subscription_id: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2025-01-02-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/identityBindings/{identityBindingName}", + ) + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url( + "resource_group_name", resource_group_name, "str", max_length=90, min_length=1 + ), + "resourceName": _SERIALIZER.url( + "resource_name", + resource_name, + "str", + max_length=63, + min_length=1, + pattern=r"^[a-zA-Z0-9]$|^[a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]$", + ), + "identityBindingName": _SERIALIZER.url( + "identity_binding_name", + identity_binding_name, + "str", + max_length=63, + min_length=1, + pattern=r"^[a-z][a-z0-9]{0,63}$", + ), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_create_or_update_request( + resource_group_name: str, resource_name: str, identity_binding_name: str, subscription_id: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2025-01-02-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/identityBindings/{identityBindingName}", + ) + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url( + "resource_group_name", resource_group_name, "str", max_length=90, min_length=1 + ), + "resourceName": _SERIALIZER.url( + "resource_name", + resource_name, + "str", + max_length=63, + min_length=1, + pattern=r"^[a-zA-Z0-9]$|^[a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]$", + ), + "identityBindingName": _SERIALIZER.url( + "identity_binding_name", + identity_binding_name, + "str", + max_length=63, + min_length=1, + pattern=r"^[a-z][a-z0-9]{0,63}$", + ), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_delete_request( + resource_group_name: str, resource_name: str, identity_binding_name: str, subscription_id: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2025-01-02-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/identityBindings/{identityBindingName}", + ) + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url( + "resource_group_name", resource_group_name, "str", max_length=90, min_length=1 + ), + "resourceName": _SERIALIZER.url( + "resource_name", + resource_name, + "str", + max_length=63, + min_length=1, + pattern=r"^[a-zA-Z0-9]$|^[a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]$", + ), + "identityBindingName": _SERIALIZER.url( + "identity_binding_name", + identity_binding_name, + "str", + max_length=63, + min_length=1, + pattern=r"^[a-z][a-z0-9]{0,63}$", + ), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + + +class IdentityBindingsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.containerservice.v2025_01_02_preview.ContainerServiceClient`'s + :attr:`identity_bindings` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client: PipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") + self._config: ContainerServiceClientConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") + self._api_version = input_args.pop(0) if input_args else kwargs.pop("api_version") + + @distributed_trace + def list_by_managed_cluster( + self, resource_group_name: str, resource_name: str, **kwargs: Any + ) -> Iterable["_models.IdentityBinding"]: + """Gets a list of identity bindings in the specified managed cluster. + + Gets a list of identity bindings in the specified managed cluster. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + Required. + :type resource_group_name: str + :param resource_name: The name of the managed cluster resource. Required. + :type resource_name: str + :return: An iterator like instance of either IdentityBinding or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.containerservice.v2025_01_02_preview.models.IdentityBinding] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop( + "api_version", _params.pop("api-version", self._api_version or "2025-01-02-preview") + ) + cls: ClsType[_models.IdentityBindingListResult] = kwargs.pop("cls", None) + + error_map: MutableMapping = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + _request = build_list_by_managed_cluster_request( + resource_group_name=resource_group_name, + resource_name=resource_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._api_version + _request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request + + def extract_data(pipeline_response): + deserialized = self._deserialize("IdentityBindingListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + _request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + @distributed_trace + def get( + self, resource_group_name: str, resource_name: str, identity_binding_name: str, **kwargs: Any + ) -> _models.IdentityBinding: + """Gets the specified Identity Binding. + + Gets the specified Identity Binding. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + Required. + :type resource_group_name: str + :param resource_name: The name of the managed cluster resource. Required. + :type resource_name: str + :param identity_binding_name: The name of the identity binding. Required. + :type identity_binding_name: str + :return: IdentityBinding or the result of cls(response) + :rtype: ~azure.mgmt.containerservice.v2025_01_02_preview.models.IdentityBinding + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map: MutableMapping = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop( + "api_version", _params.pop("api-version", self._api_version or "2025-01-02-preview") + ) + cls: ClsType[_models.IdentityBinding] = kwargs.pop("cls", None) + + _request = build_get_request( + resource_group_name=resource_group_name, + resource_name=resource_name, + identity_binding_name=identity_binding_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + response_body = pipeline_response.http_response + deserialized = self._deserialize("IdentityBinding", response_body) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + def _create_or_update_initial( + self, + resource_group_name: str, + resource_name: str, + identity_binding_name: str, + parameters: Union[_models.IdentityBinding, IO[bytes]], + **kwargs: Any + ) -> Iterator[bytes]: + error_map: MutableMapping = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop( + "api_version", _params.pop("api-version", self._api_version or "2025-01-02-preview") + ) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "IdentityBinding") + + _request = build_create_or_update_request( + resource_group_name=resource_group_name, + resource_name=resource_name, + identity_binding_name=identity_binding_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + response_headers = {} + response_headers["Location"] = self._deserialize("str", response.headers.get("Location")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + resource_name: str, + identity_binding_name: str, + parameters: _models.IdentityBinding, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.IdentityBinding]: + """Creates or updates an identity binding in the specified managed cluster. + + Creates or updates an identity binding in the specified managed cluster. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + Required. + :type resource_group_name: str + :param resource_name: The name of the managed cluster resource. Required. + :type resource_name: str + :param identity_binding_name: The name of the identity binding. Required. + :type identity_binding_name: str + :param parameters: The identity binding to create or update. Required. + :type parameters: ~azure.mgmt.containerservice.v2025_01_02_preview.models.IdentityBinding + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of LROPoller that returns either IdentityBinding or the result of + cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.containerservice.v2025_01_02_preview.models.IdentityBinding] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_create_or_update( + self, + resource_group_name: str, + resource_name: str, + identity_binding_name: str, + parameters: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.IdentityBinding]: + """Creates or updates an identity binding in the specified managed cluster. + + Creates or updates an identity binding in the specified managed cluster. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + Required. + :type resource_group_name: str + :param resource_name: The name of the managed cluster resource. Required. + :type resource_name: str + :param identity_binding_name: The name of the identity binding. Required. + :type identity_binding_name: str + :param parameters: The identity binding to create or update. Required. + :type parameters: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of LROPoller that returns either IdentityBinding or the result of + cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.containerservice.v2025_01_02_preview.models.IdentityBinding] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name: str, + resource_name: str, + identity_binding_name: str, + parameters: Union[_models.IdentityBinding, IO[bytes]], + **kwargs: Any + ) -> LROPoller[_models.IdentityBinding]: + """Creates or updates an identity binding in the specified managed cluster. + + Creates or updates an identity binding in the specified managed cluster. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + Required. + :type resource_group_name: str + :param resource_name: The name of the managed cluster resource. Required. + :type resource_name: str + :param identity_binding_name: The name of the identity binding. Required. + :type identity_binding_name: str + :param parameters: The identity binding to create or update. Is either a IdentityBinding type + or a IO[bytes] type. Required. + :type parameters: ~azure.mgmt.containerservice.v2025_01_02_preview.models.IdentityBinding or + IO[bytes] + :return: An instance of LROPoller that returns either IdentityBinding or the result of + cls(response) + :rtype: + ~azure.core.polling.LROPoller[~azure.mgmt.containerservice.v2025_01_02_preview.models.IdentityBinding] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop( + "api_version", _params.pop("api-version", self._api_version or "2025-01-02-preview") + ) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.IdentityBinding] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token: Optional[str] = kwargs.pop("continuation_token", None) + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + resource_name=resource_name, + identity_binding_name=identity_binding_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + raw_result.http_response.read() # type: ignore + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): + response_headers = {} + response = pipeline_response.http_response + response_headers["Location"] = self._deserialize("str", response.headers.get("Location")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("IdentityBinding", pipeline_response.http_response) + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + return deserialized + + if polling is True: + polling_method: PollingMethod = cast( + PollingMethod, ARMPolling(lro_delay, lro_options={"final-state-via": "location"}, **kwargs) + ) + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling + if cont_token: + return LROPoller[_models.IdentityBinding].from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output, + ) + return LROPoller[_models.IdentityBinding]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) + + def _delete_initial( + self, resource_group_name: str, resource_name: str, identity_binding_name: str, **kwargs: Any + ) -> Iterator[bytes]: + error_map: MutableMapping = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop( + "api_version", _params.pop("api-version", self._api_version or "2025-01-02-preview") + ) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) + + _request = build_delete_request( + resource_group_name=resource_group_name, + resource_name=resource_name, + identity_binding_name=identity_binding_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + response_headers = {} + if response.status_code == 202: + response_headers["Location"] = self._deserialize("str", response.headers.get("Location")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + + @distributed_trace + def begin_delete( + self, resource_group_name: str, resource_name: str, identity_binding_name: str, **kwargs: Any + ) -> LROPoller[None]: + """Deletes an identity binding in the specified managed cluster. + + Deletes an identity binding in the specified managed cluster. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + Required. + :type resource_group_name: str + :param resource_name: The name of the managed cluster resource. Required. + :type resource_name: str + :param identity_binding_name: The name of the identity binding. Required. + :type identity_binding_name: str + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop( + "api_version", _params.pop("api-version", self._api_version or "2025-01-02-preview") + ) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token: Optional[str] = kwargs.pop("continuation_token", None) + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + resource_name=resource_name, + identity_binding_name=identity_binding_name, + api_version=api_version, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + raw_result.http_response.read() # type: ignore + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements + if cls: + return cls(pipeline_response, None, {}) # type: ignore + + if polling is True: + polling_method: PollingMethod = cast( + PollingMethod, ARMPolling(lro_delay, lro_options={"final-state-via": "location"}, **kwargs) + ) + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling + if cont_token: + return LROPoller[None].from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output, + ) + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore \ No newline at end of file