Skip to content

Commit

Permalink
[EventHub] az eventhubs namespace create: Add MinTls to EventHub cmdl…
Browse files Browse the repository at this point in the history
…ets and SupportsScaling for cluster cmdlets (#23186)
  • Loading branch information
damodaravadhani authored Jul 13, 2022
1 parent cc6e5ce commit 4861021
Show file tree
Hide file tree
Showing 6 changed files with 7,230 additions and 66 deletions.
8 changes: 5 additions & 3 deletions src/azure-cli/azure/cli/command_modules/eventhubs/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def load_arguments_eh(self, _):
from azure.cli.command_modules.eventhubs._validator import validate_storageaccount, validate_partner_namespace, validate_rights
from knack.arguments import CLIArgumentType
from azure.cli.core.profiles import ResourceType
(KeyType, AccessRights, SkuName, KeySource) = self.get_models('KeyType', 'AccessRights', 'SkuName', 'KeySource', resource_type=ResourceType.MGMT_EVENTHUB)
(KeyType, AccessRights, SkuName, KeySource, TlsVersion) = self.get_models('KeyType', 'AccessRights', 'SkuName', 'KeySource', 'TlsVersion', resource_type=ResourceType.MGMT_EVENTHUB)
from azure.cli.command_modules.eventhubs.action import AlertAddEncryption, ConstructPolicy

rights_arg_type = CLIArgumentType(options_list=['--rights'], nargs='+', arg_type=get_enum_type(AccessRights), validator=validate_rights, help='Space-separated list of Authorization rule rights')
Expand Down Expand Up @@ -58,6 +58,7 @@ def load_arguments_eh(self, _):
help='Enable System Assigned Identity')
c.argument('mi_user_assigned', arg_group='Managed Identity', nargs='+', help='List of User Assigned Identity ids.')
c.argument('encryption_config', action=AlertAddEncryption, nargs='+', help='List of KeyVaultProperties objects.')
c.argument('minimum_tls_version', arg_type=get_enum_type(TlsVersion), options_list=['--minimum-tls-version', '--min-tls'], help='The minimum TLS version for the cluster to support, e.g. 1.2')

with self.argument_context('eventhubs namespace create', min_api='2021-06-01-preview') as c:
c.argument('cluster_arm_id', options_list=['--cluster-arm-id'], is_preview=True, help='Cluster ARM ID of the Namespace')
Expand All @@ -79,12 +80,13 @@ def load_arguments_eh(self, _):
c.argument('cluster_name', arg_type=name_type, id_part=None, help='Name of Cluster')

with self.argument_context('eventhubs cluster create') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part=None, help='Location of the Cluster, for locations of available pre-provision clusters, please check az evetnhubs ')
c.argument('capacity', type=int, help='Capacity for Sku, allowed value : 1')
c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part=None, help='Location of the Cluster, for locations of available pre-provision clusters, please check az event hubs ')
c.argument('supports_scaling', arg_type=get_three_state_flag(), help='A value that indicates whether Scaling is Supported.')

for scope in ['eventhubs cluster create', 'eventhubs cluster update']:
with self.argument_context(scope) as c:
c.argument('tags', arg_type=tags_type)
c.argument('capacity', type=int, help='Capacity for Sku, allowed value : 1')

# region Namespace Authorizationrule
with self.argument_context('eventhubs namespace authorization-rule list') as c:
Expand Down
37 changes: 27 additions & 10 deletions src/azure-cli/azure/cli/command_modules/eventhubs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def cli_namespace_create(cmd, client, resource_group_name, namespace_name, location=None, tags=None, sku='Standard', capacity=None,
is_auto_inflate_enabled=None, maximum_throughput_units=None, is_kafka_enabled=None,
default_action=None, identity=None, zone_redundant=None, cluster_arm_id=None, trusted_service_access_enabled=None,
disable_local_auth=None, mi_system_assigned=None, mi_user_assigned=None, encryption_config=None):
disable_local_auth=None, mi_system_assigned=None, mi_user_assigned=None, encryption_config=None, minimum_tls_version=None):
EHNamespace = cmd.get_models('EHNamespace', resource_type=ResourceType.MGMT_EVENTHUB)
Sku = cmd.get_models('Sku', resource_type=ResourceType.MGMT_EVENTHUB)
Identity = cmd.get_models('Identity', resource_type=ResourceType.MGMT_EVENTHUB)
Expand All @@ -35,6 +35,7 @@ def cli_namespace_create(cmd, client, resource_group_name, namespace_name, locat
ehparam.zone_redundant = zone_redundant
ehparam.disable_local_auth = disable_local_auth
ehparam.cluster_arm_id = cluster_arm_id
ehparam.minimum_tls_version = minimum_tls_version

if identity or mi_system_assigned:
ehparam.identity = Identity(type=IdentityType.SYSTEM_ASSIGNED)
Expand Down Expand Up @@ -72,7 +73,7 @@ def cli_namespace_create(cmd, client, resource_group_name, namespace_name, locat
def cli_namespace_update(cmd, client, instance, tags=None, sku=None, capacity=None, is_auto_inflate_enabled=None,
maximum_throughput_units=None, is_kafka_enabled=None, default_action=None,
identity=None, key_source=None, key_name=None, key_vault_uri=None, key_version=None, trusted_service_access_enabled=None,
disable_local_auth=None, require_infrastructure_encryption=None):
disable_local_auth=None, require_infrastructure_encryption=None, minimum_tls_version=None):
Encryption = cmd.get_models('Encryption', resource_type=ResourceType.MGMT_EVENTHUB)
KeyVaultProperties = cmd.get_models('KeyVaultProperties', resource_type=ResourceType.MGMT_EVENTHUB)
Identity = cmd.get_models('Identity', resource_type=ResourceType.MGMT_EVENTHUB)
Expand All @@ -92,15 +93,18 @@ def cli_namespace_update(cmd, client, instance, tags=None, sku=None, capacity=No
if is_auto_inflate_enabled is not None:
instance.is_auto_inflate_enabled = is_auto_inflate_enabled

if maximum_throughput_units:
if maximum_throughput_units is not None:
instance.maximum_throughput_units = maximum_throughput_units

if is_kafka_enabled:
if is_kafka_enabled is not None:
instance.kafka_enabled = is_kafka_enabled

if minimum_tls_version:
instance.minimum_tls_version = minimum_tls_version

if identity is True and instance.identity is None:
instance.identity = Identity(type=IdentityType.SYSTEM_ASSIGNED)
elif instance.identity and instance.encryption is None:
elif instance.identity and (key_name or key_vault_uri or key_version or key_source):
instance.encryption = Encryption()
if key_source:
instance.encryption.key_source = key_source
Expand All @@ -118,7 +122,7 @@ def cli_namespace_update(cmd, client, instance, tags=None, sku=None, capacity=No
netwrokruleset.trusted_service_access_enabled = trusted_service_access_enabled
client.create_or_update_network_rule_set(resourcegroup, instance.name, netwrokruleset)

if disable_local_auth:
if disable_local_auth is not None:
instance.disable_local_auth = disable_local_auth

return instance
Expand All @@ -138,17 +142,25 @@ def cli_namespace_exists(client, name):


# Cluster region
def cli_cluster_create(cmd, client, resource_group_name, cluster_name, location=None, tags=None, capacity=None):
def cli_cluster_create(cmd, client, resource_group_name, cluster_name, location=None, tags=None, capacity=None, supports_scaling=None):
Cluster = cmd.get_models('Cluster', resource_type=ResourceType.MGMT_EVENTHUB)
ClusterSku = cmd.get_models('ClusterSku', resource_type=ResourceType.MGMT_EVENTHUB)

if cmd.supported_api_version(resource_type=ResourceType.MGMT_EVENTHUB, min_api='2016-06-01-preview'):
ehparam = Cluster()
ehparam.sku = ClusterSku(name='Dedicated')
ehparam.location = location
if not capacity:

if capacity:
ehparam.sku.capacity = capacity
else:
ehparam.sku.capacity = 1

if supports_scaling is not None:
ehparam.supports_scaling = supports_scaling

ehparam.tags = tags

cluster_result = client.begin_create_or_update(
resource_group_name=resource_group_name,
cluster_name=cluster_name,
Expand All @@ -157,10 +169,15 @@ def cli_cluster_create(cmd, client, resource_group_name, cluster_name, location=
return cluster_result


def cli_cluster_update(cmd, instance, tags=None):
def cli_cluster_update(cmd, instance, tags=None, capacity=None):
if cmd.supported_api_version(resource_type=ResourceType.MGMT_EVENTHUB, min_api='2016-06-01-preview'):

if tags:
instance.tags = tags

if capacity:
instance.sku.capacity = capacity

return instance


Expand Down Expand Up @@ -212,7 +229,7 @@ def cli_eheventhub_create(cmd, client, resource_group_name, namespace_name, even
if status:
eventhubparameter1.status = status

if enabled and enabled is True:
if enabled is not None and enabled is True:
eventhubparameter1.capture_description = CaptureDescription(
enabled=enabled,
skip_empty_archives=skip_empty_archives,
Expand Down
Loading

0 comments on commit 4861021

Please sign in to comment.