diff --git a/azext_iot/iothub/_help.py b/azext_iot/iothub/_help.py index f87a4dbb7..a948372b1 100644 --- a/azext_iot/iothub/_help.py +++ b/azext_iot/iothub/_help.py @@ -658,11 +658,13 @@ def load_iothub_help(): type: command short-summary: Update the properties of an existing Cosmos DB Container endpoint for an IoT Hub. long-summary: | - If updating the authentication type from a key-based to identity-based Cosmos DB Container endpoint, you must provide the endpoint account (via --endpoint-account). The old primary key and secondary key will be nulled out. + If updating the authentication type from a key-based to identity-based Cosmos DB Container endpoint, you must provide the identity (via --identity) and the endpoint uri (via --endpoint-uri). The old primary key and secondary key will be nulled out. - If updating the authentication type from an identity-based to key-based Cosmos DB Container endpoint, you must provide the connection string (via --connection-string) or the primary key (via --primary-key) or the secondary key (via --secondary-key). + If updating the authentication type from an identity-based to key-based Cosmos DB Container endpoint, you must provide the connection string (via --connection-string), the primary key (via --primary-key) or the secondary key (via --secondary-key). + + Container name for the endpoint cannot be changed. Account names can only be changed if containers with the same name exist in both accounts. examples: - - name: Update a key-based Cosmos DB Container endpoint for an IoT Hub to use a new specified connection string. + - name: Update a key-based or identity-based Cosmos DB Container endpoint for an IoT Hub to use a new specified connection string. text: > az iot hub message-endpoint update cosmosdb-container -n {iothub_name} --en {endpoint_name} --connection-string {connection_string} - name: Update a Cosmos DB Container endpoint for an IoT Hub to use a specified primary key and secondary key. @@ -672,10 +674,10 @@ def load_iothub_help(): The partition key template will be the default. text: > az iot hub message-endpoint update cosmosdb-container -n {iothub_name} --en {endpoint_name} --pkn {partition_key_name} --identity [system] - - name: Update a Cosmos DB Container endpoint for an IoT Hub to use user assigned identity + - name: Update a key-based Cosmos DB Container endpoint for an IoT Hub to use user assigned identity (you can omit --endpoint-uri if the endpoint is already identity-based). text: > az iot hub message-endpoint update cosmosdb-container -n {iothub_name} --en {endpoint_name} - --identity {user_identity_resource_id} + --identity {user_identity_resource_id} --endpoint-uri {endpoint_uri} """ helps[ @@ -684,20 +686,20 @@ def load_iothub_help(): type: command short-summary: Update the properties of an existing Event Hub endpoint for an IoT Hub. long-summary: | - If updating the authentication type from a key-based to identity-based Event Hub endpoint, you must provide the endpoint uri (via --endpoint-uri) and the entity path (via --entity-path). The old connection string will be nulled out. + If updating the authentication type from a key-based to identity-based Event Hub endpoint, you must provide the identity (via --identity), the endpoint uri (via --endpoint-uri) and the entity path (via --entity-path). The old connection string will be nulled out. If updating the authentication type from an identity-based to key-based Event Hub endpoint, you must provide the connection string (via --connection-string). The old endpoint uri and entity path will be nulled out. examples: - - name: Update an Event Hub endpoint for an IoT Hub to use a new specified connection string. + - name: Update a key-based or identity-based Event Hub endpoint for an IoT Hub to use a new specified connection string. text: > az iot hub message-endpoint update eventhub -n {iothub_name} --en {endpoint_name} -c {connection_string} - name: Update an Event Hub endpoint for an IoT Hub to use system assigned identity and a different entity path. text: > az iot hub message-endpoint update eventhub -n {iothub_name} --en {endpoint_name} --entity-path {entity_path} --identity [system] - - name: Update an Event Hub endpoint for an IoT Hub to use user assigned identity. + - name: Update a key-based Event Hub endpoint for an IoT Hub to use user assigned identity (you can omit --endpoint-uri if the endpoint is already identity-based). text: > - az iot hub message-endpoint update eventhub -n {iothub_name} --en {endpoint_name} --identity {user_identity_resource_id} + az iot hub message-endpoint update eventhub -n {iothub_name} --en {endpoint_name} --identity {user_identity_resource_id} --endpoint-uri {endpoint_uri} --entity-path {entity_path} """ helps[ @@ -706,20 +708,20 @@ def load_iothub_help(): type: command short-summary: Update the properties of an existing Service Bus Queue endpoint for an IoT Hub. long-summary: | - If updating the authentication type from a key-based to identity-based Service Bus Queue endpoint, you must provide the endpoint uri (via --endpoint-uri) and the entity path (via --entity-path). The old connection string will be nulled out. + If updating the authentication type from a key-based to identity-based Service Bus Queue endpoint, you must provide the identity (via --identity), the endpoint uri (via --endpoint-uri) and the entity path (via --entity-path). The old connection string will be nulled out. If updating the authentication type from an identity-based to key-based Service Bus Queue endpoint, you must provide the connection string (via --connection-string). The old endpoint uri and entity path will be nulled out. examples: - - name: Update a Service Bus Queue endpoint for an IoT Hub to use a new specified connection string. + - name: Update a key-based or identity-based Service Bus Queue endpoint for an IoT Hub to use a new specified connection string. text: > az iot hub message-endpoint update servicebus-queue -n {iothub_name} --en {endpoint_name} -c {connection_string} - name: Update a Service Bus Queue endpoint for an IoT Hub to use system assigned identity and a different entity path. text: > az iot hub message-endpoint update servicebus-queue -n {iothub_name} --en {endpoint_name} --entity-path {entity_path} --identity [system] - - name: Update a Service Bus Queue endpoint for an IoT Hub to use user assigned identity. + - name: Update a key-based Service Bus Queue endpoint for an IoT Hub to use user assigned identity (you can omit --endpoint-uri if the endpoint is already identity-based). text: > - az iot hub message-endpoint update servicebus-queue -n {iothub_name} --en {endpoint_name} --identity {user_identity_resource_id} + az iot hub message-endpoint update servicebus-queue -n {iothub_name} --en {endpoint_name} --identity {user_identity_resource_id} --endpoint-uri {endpoint_uri} --entity-path {entity_path} """ helps[ @@ -728,20 +730,20 @@ def load_iothub_help(): type: command short-summary: Update the properties of an existing Service Bus Topic endpoint for an IoT Hub. long-summary: | - If updating the authentication type from a key-based to identity-based Service Bus Topic endpoint, you must provide the endpoint uri (via --endpoint-uri) and the entity path (via --entity-path). The old connection string will be nulled out. + If updating the authentication type from a key-based to identity-based Service Bus Topic endpoint, you must provide the identity (via --identity), the endpoint uri (via --endpoint-uri) and the entity path (via --entity-path). The old connection string will be nulled out. If updating the authentication type from an identity-based to key-based Service Bus Topic endpoint, you must provide the connection string (via --connection-string). The old endpoint uri and entity path will be nulled out. examples: - - name: Update a Service Bus Topic endpoint for an IoT Hub to use a new specified connection string. + - name: Update a key-based or identity-based Service Bus Topic endpoint for an IoT Hub to use a new specified connection string. text: > az iot hub message-endpoint update servicebus-topic -n {iothub_name} --en {endpoint_name} -c {connection_string} - name: Update a Service Bus Topic endpoint for an IoT Hub to use system assigned identity and a different entity path. text: > az iot hub message-endpoint update servicebus-topic -n {iothub_name} --en {endpoint_name} --entity-path {entity_path} --identity [system] - - name: Update a Service Bus Topic endpoint for an IoT Hub to use user assigned identity. + - name: Update a key-based Service Bus Topic endpoint for an IoT Hub to use user assigned identity (you can omit --endpoint-uri if the endpoint is already identity-based). text: > - az iot hub message-endpoint update servicebus-topic -n {iothub_name} --en {endpoint_name} --identity {user_identity_resource_id} + az iot hub message-endpoint update servicebus-topic -n {iothub_name} --en {endpoint_name} --identity {user_identity_resource_id} --endpoint-uri {endpoint_uri} --entity-path {entity_path} """ helps[ @@ -750,21 +752,21 @@ def load_iothub_help(): type: command short-summary: Update the properties of an existing Storage Container endpoint for an IoT Hub. long-summary: | - If updating the authentication type from a key-based to identity-based Storage Container endpoint, you must provide the endpoint account (via --endpoint-account). The old connection string will be nulled out. + If updating the authentication type from a key-based to identity-based Storage Container endpoint, you must provide the identity (via --identity) and the endpoint uri (via --endpoint-uri). The old connection string will be nulled out. If updating the authentication type from an identity-based to key-based Storage Container endpoint, you must provide the connection string (via --connection-string). - Encoding for the endpoint cannot be changed. + Container name and encoding for the endpoint cannot be changed. Account names can only be changed if containers with the same name exist in both accounts. examples: - - name: Update a Storage Container endpoint for an IoT Hub to use a new specified connection string. + - name: Update a key-based or identity-based Storage Container endpoint for an IoT Hub to use a new specified connection string. text: > az iot hub message-endpoint update storage-container -n {iothub_name} --en {endpoint_name} -c {connection_string} - name: Update a Storage Container endpoint for an IoT Hub to use system assigned identity with the given batch frequency, chunk size, and file name format. text: > az iot hub message-endpoint update storage-container -n {iothub_name} --en {endpoint_name} -b {batch_frequency} -w {chunk_size} --ff {file_format} --identity [system] - - name: Update a Storage Container endpoint for an IoT Hub to use user assigned identity. + - name: Update a key-based Storage Container endpoint for an IoT Hub to use user assigned identity (you can omit --endpoint-uri if the endpoint is already identity-based). text: > - az iot hub message-endpoint update storage-container -n {iothub_name} --en {endpoint_name} --identity {user_identity_resource_id} + az iot hub message-endpoint update storage-container -n {iothub_name} --en {endpoint_name} --identity {user_identity_resource_id} --endpoint-uri {endpoint_uri} """ helps[ diff --git a/azext_iot/iothub/commands_message_endpoint.py b/azext_iot/iothub/commands_message_endpoint.py index 9083b2310..7692c7dff 100644 --- a/azext_iot/iothub/commands_message_endpoint.py +++ b/azext_iot/iothub/commands_message_endpoint.py @@ -265,7 +265,6 @@ def message_endpoint_update_cosmos_db_container( cmd, hub_name: str, endpoint_name: str, - container_name: Optional[str] = None, database_name: Optional[str] = None, endpoint_resource_group: Optional[str] = None, endpoint_subscription_id: Optional[str] = None, @@ -288,7 +287,6 @@ def message_endpoint_update_cosmos_db_container( endpoint_subscription_id=endpoint_subscription_id, connection_string=connection_string, endpoint_uri=endpoint_uri, - container_name=container_name, database_name=database_name, primary_key=primary_key, secondary_key=secondary_key, @@ -302,7 +300,6 @@ def message_endpoint_update_storage_container( cmd, hub_name: str, endpoint_name: str, - container_name: Optional[str] = None, endpoint_resource_group: Optional[str] = None, endpoint_subscription_id: Optional[str] = None, connection_string: Optional[str] = None, @@ -322,7 +319,6 @@ def message_endpoint_update_storage_container( endpoint_resource_group=endpoint_resource_group, endpoint_subscription_id=endpoint_subscription_id, connection_string=connection_string, - container_name=container_name, batch_frequency=batch_frequency, chunk_size_window=chunk_size_window, file_name_format=file_name_format, diff --git a/azext_iot/iothub/params.py b/azext_iot/iothub/params.py index 4185dcbc1..dc79e50ce 100644 --- a/azext_iot/iothub/params.py +++ b/azext_iot/iothub/params.py @@ -490,11 +490,6 @@ def load_iothub_arguments(self, _): ) with self.argument_context(f"iot hub message-endpoint {endpoint_op} storage-container") as context: - context.argument( - "container_name", - options_list=["--container-name", "--container"], - help="Name of the storage container.", - ) context.argument( "batch_frequency", options_list=["--batch-frequency", "-b"], @@ -522,11 +517,6 @@ def load_iothub_arguments(self, _): options_list=["--database-name", "--db"], help="The name of the cosmos DB database in the cosmos DB account.", ) - context.argument( - "container_name", - options_list=["--container-name", "--container"], - help="The name of the Cosmos DB SQL Container in the cosmos DB Database.", - ) context.argument( "primary_key", options_list=["--primary-key", "--pk"], @@ -580,6 +570,18 @@ def load_iothub_arguments(self, _): arg_type=get_enum_type(EncodingFormat), help="Encoding format for the container.", ) + context.argument( + "container_name", + options_list=["--container-name", "--container"], + help="Name of the storage container.", + ) + + with self.argument_context("iot hub message-endpoint create cosmosdb-container") as context: + context.argument( + "container_name", + options_list=["--container-name", "--container"], + help="The name of the Cosmos DB SQL Container in the cosmos DB Database.", + ) with self.argument_context("iot hub message-endpoint update cosmosdb-container") as context: context.argument( diff --git a/azext_iot/iothub/providers/message_endpoint.py b/azext_iot/iothub/providers/message_endpoint.py index 69d68b2cc..45960528d 100644 --- a/azext_iot/iothub/providers/message_endpoint.py +++ b/azext_iot/iothub/providers/message_endpoint.py @@ -226,7 +226,6 @@ def update( endpoint_resource_group: Optional[str] = None, endpoint_subscription_id: Optional[str] = None, connection_string: Optional[str] = None, - container_name: Optional[str] = None, batch_frequency: Optional[int] = None, chunk_size_window: Optional[int] = None, file_name_format: Optional[str] = None, @@ -305,8 +304,6 @@ def update( original_endpoint.entity_path = entity_path if endpoint_type == EndpointType.AzureStorageContainer.value: - if container_name: - original_endpoint.container_name = container_name if file_name_format: original_endpoint.file_name_format = file_name_format if batch_frequency: @@ -325,8 +322,6 @@ def update( original_endpoint.endpoint_uri = parsed_cs["AccountEndpoint"] if database_name: original_endpoint.database_name = database_name - if container_name: - original_endpoint.container_name = container_name if partition_key_name: original_endpoint.partition_key_name = None if partition_key_name == "" else partition_key_name if partition_key_template: diff --git a/azext_iot/tests/iothub/message_endpoint/test_iothub_message_endpoint_int.py b/azext_iot/tests/iothub/message_endpoint/test_iothub_message_endpoint_int.py index 0b92d7a52..14b8788c3 100644 --- a/azext_iot/tests/iothub/message_endpoint/test_iothub_message_endpoint_int.py +++ b/azext_iot/tests/iothub/message_endpoint/test_iothub_message_endpoint_int.py @@ -758,14 +758,13 @@ def test_iot_storage_endpoint_lifecycle(provisioned_storage_with_identity_module # Update # Keybased -> System, change all optional props cli.invoke( - "iot hub message-endpoint update storage-container -n {} -g {} --en {} --erg {} --endpoint-uri {} --container {} " + "iot hub message-endpoint update storage-container -n {} -g {} --en {} --erg {} --endpoint-uri {} " "--identity [system] -b {} -w {} --ff {}".format( iot_hub, iot_rg, endpoint_names[0], iot_rg, endpoint_uri, - container_name, 100, 50, custom_file_format @@ -797,13 +796,13 @@ def test_iot_storage_endpoint_lifecycle(provisioned_storage_with_identity_module # System -> User, change some optional props custom_file_format = default_file_format.replace("/", "_") cli.invoke( - "iot hub message-endpoint update storage-container -n {} -g {} --en {} --erg {} --endpoint-uri {} --container {} " + "iot hub message-endpoint update storage-container -n {} -g {} --en {} --erg {} --endpoint-uri {} " "--identity {} -b {}".format( iot_hub, iot_rg, endpoint_names[1], - iot_rg, endpoint_uri, - container_name, + iot_rg, + endpoint_uri, user_id, 70, ) @@ -833,13 +832,12 @@ def test_iot_storage_endpoint_lifecycle(provisioned_storage_with_identity_module # User -> Keybased, change no optional props cli.invoke( - "iot hub message-endpoint update storage-container -n {} -g {} --en {} --erg {} --container {} " + "iot hub message-endpoint update storage-container -n {} -g {} --en {} --erg {} " "-c {}".format( iot_hub, iot_rg, endpoint_names[2], iot_rg, - container_name, storage_cs, ) ) @@ -1049,14 +1047,13 @@ def test_iot_cosmos_endpoint_lifecycle(provisioned_cosmosdb_with_identity_module # Keybased -> User, add pkn + pkt cli.invoke( "iot hub message-endpoint update cosmosdb-container -n {} -g {} --en {} --erg {} --endpoint-uri {} " - "--identity {} --container {} --db {} --pkn {} --pkt {}".format( + "--identity {} --db {} --pkn {} --pkt {}".format( iot_hub, iot_rg, endpoint_names[0], iot_rg, endpoint_uri, user_id, - container, database, partition_path, partition_template @@ -1086,14 +1083,13 @@ def test_iot_cosmos_endpoint_lifecycle(provisioned_cosmosdb_with_identity_module # System -> Keybased, keep cli.invoke( - "iot hub message-endpoint update cosmosdb-container -n {} -g {} --en {} --erg {} -c {} --container {} " + "iot hub message-endpoint update cosmosdb-container -n {} -g {} --en {} --erg {} -c {} " "--db {}".format( iot_hub, iot_rg, endpoint_names[1], iot_rg, cosmos_cstring, - container, database ) ) @@ -1122,13 +1118,12 @@ def test_iot_cosmos_endpoint_lifecycle(provisioned_cosmosdb_with_identity_module # User -> System, remove pkn, pkt cli.invoke( "iot hub message-endpoint update cosmosdb-container -n {} -g {} --en {} --erg {} --endpoint-uri {} " - "--identity [system] --container {} --db {} --pkn {} --pkt {}".format( + "--identity [system] --db {} --pkn {} --pkt {}".format( iot_hub, iot_rg, endpoint_names[2], iot_rg, endpoint_uri, - container, database, partition_path, partition_template diff --git a/azext_iot/tests/iothub/message_endpoint/test_iothub_message_endpoint_unit.py b/azext_iot/tests/iothub/message_endpoint/test_iothub_message_endpoint_unit.py index 03babf5ec..3b384aee3 100644 --- a/azext_iot/tests/iothub/message_endpoint/test_iothub_message_endpoint_unit.py +++ b/azext_iot/tests/iothub/message_endpoint/test_iothub_message_endpoint_unit.py @@ -482,7 +482,6 @@ def test_message_endpoint_update_service_bus_topic_error(self, fixture_cmd, fixt "endpoint_subscription_id": generate_names(), "connection_string": None, "endpoint_uri": generate_names(), - "container_name": generate_names(), "batch_frequency": 1, "chunk_size_window": 100, "file_name_format": generate_names(), @@ -494,7 +493,6 @@ def test_message_endpoint_update_service_bus_topic_error(self, fixture_cmd, fixt "endpoint_subscription_id": generate_names(), "connection_string": None, "endpoint_uri": generate_names(), - "container_name": generate_names(), "batch_frequency": None, "chunk_size_window": 30, "file_name_format": generate_names(), @@ -506,7 +504,6 @@ def test_message_endpoint_update_service_bus_topic_error(self, fixture_cmd, fixt "endpoint_subscription_id": None, "connection_string": None, "endpoint_uri": None, - "container_name": None, "batch_frequency": None, "chunk_size_window": None, "file_name_format": None, @@ -518,7 +515,6 @@ def test_message_endpoint_update_service_bus_topic_error(self, fixture_cmd, fixt "endpoint_subscription_id": None, "connection_string": generate_names(), "endpoint_uri": generate_names(), - "container_name": None, "batch_frequency": None, "chunk_size_window": None, "file_name_format": None, @@ -559,11 +555,6 @@ def test_message_endpoint_update_storage_container(self, mocker, fixture_cmd, fi else: assert isinstance(endpoint.subscription_id, mock) - if req.get("container_name"): - assert endpoint.container_name == req.get("container_name") - else: - assert isinstance(endpoint.container_name, mock) - if req.get("file_name_format"): assert endpoint.file_name_format == req.get("file_name_format") else: @@ -639,7 +630,6 @@ def test_message_endpoint_update_storage_container_error(self, fixture_cmd, fixt { "endpoint_resource_group": generate_names(), "endpoint_subscription_id": generate_names(), - "container_name": generate_names(), "database_name": generate_names(), "connection_string": generate_names(), "primary_key": None, @@ -653,7 +643,6 @@ def test_message_endpoint_update_storage_container_error(self, fixture_cmd, fixt { "endpoint_resource_group": None, "endpoint_subscription_id": None, - "container_name": None, "database_name": None, "connection_string": None, "primary_key": None, @@ -667,7 +656,6 @@ def test_message_endpoint_update_storage_container_error(self, fixture_cmd, fixt { "endpoint_resource_group": None, "endpoint_subscription_id": None, - "container_name": None, "database_name": None, "connection_string": None, "primary_key": None, @@ -681,7 +669,6 @@ def test_message_endpoint_update_storage_container_error(self, fixture_cmd, fixt { "endpoint_resource_group": None, "endpoint_subscription_id": None, - "container_name": None, "database_name": None, "connection_string": generate_names(), "primary_key": None, @@ -695,7 +682,6 @@ def test_message_endpoint_update_storage_container_error(self, fixture_cmd, fixt { "endpoint_resource_group": generate_names(), "endpoint_subscription_id": None, - "container_name": None, "database_name": None, "connection_string": generate_names(), "primary_key": generate_names(), @@ -709,7 +695,6 @@ def test_message_endpoint_update_storage_container_error(self, fixture_cmd, fixt { "endpoint_resource_group": None, "endpoint_subscription_id": None, - "container_name": generate_names(), "database_name": generate_names(), "connection_string": None, "primary_key": None, @@ -755,11 +740,6 @@ def test_message_endpoint_update_cosmos_db_sql_container(self, mocker, fixture_c else: assert isinstance(endpoint.subscription_id, mock) - if req.get("container_name"): - assert endpoint.container_name == req.get("container_name") - else: - assert isinstance(endpoint.container_name, mock) - if req.get("database_name"): assert endpoint.database_name == req.get("database_name").lower() else: