66from knack .prompting import prompt_pass , NoTTYException
77from knack .util import CLIError
88from azure .cli .core .util import sdk_no_wait , user_confirmation
9- from azure .cli .core .azclierror import RequiredArgumentMissingError
9+ from azure .cli .core .azclierror import RequiredArgumentMissingError , MutuallyExclusiveArgumentError
1010
1111logger = get_logger (__name__ )
1212
@@ -20,7 +20,7 @@ def create_cluster(cmd, client, cluster_name, resource_group_name, cluster_type,
2020 kafka_client_group_id = None , kafka_client_group_name = None ,
2121 workernode_count = 3 , workernode_data_disks_per_node = None ,
2222 workernode_data_disk_storage_account_type = None , workernode_data_disk_size = None ,
23- http_username = None , http_password = None ,
23+ http_username = None , http_password = None , entra_user_identity = None , entra_user_full_info = None ,
2424 ssh_username = 'sshuser' , ssh_password = None , ssh_public_key = None ,
2525 storage_account = None , storage_account_key = None ,
2626 storage_default_container = None , storage_default_filesystem = None ,
@@ -41,7 +41,8 @@ def create_cluster(cmd, client, cluster_name, resource_group_name, cluster_type,
4141 enable_compute_isolation = None , host_sku = None , zones = None , private_link_configurations = None ,
4242 no_validation_timeout = False , outbound_dependencies_managed_type = None ):
4343 from .util import build_identities_info , build_virtual_network_profile , parse_domain_name , \
44- get_storage_account_endpoint , validate_esp_cluster_create_params , set_vm_size
44+ get_storage_account_endpoint , validate_esp_cluster_create_params , set_vm_size , \
45+ is_wasb_storage_account , get_entra_user_info
4546 from azure .mgmt .hdinsight .models import ClusterCreateParametersExtended , ClusterCreateProperties , OSType , \
4647 ClusterDefinition , ComputeProfile , HardwareProfile , Role , OsProfile , LinuxOperatingSystemProfile , \
4748 StorageProfile , StorageAccount , DataDisksGroups , SecurityProfile , \
@@ -84,17 +85,25 @@ def create_cluster(cmd, client, cluster_name, resource_group_name, cluster_type,
8485 if not http_username :
8586 http_username = 'admin' # Implement default logic here, in case a user specifies the username in configurations
8687
87- if not http_password :
88+ if not http_password and not entra_user_identity and not entra_user_full_info :
8889 try :
8990 http_password = prompt_pass ('HTTP password for the cluster:' , confirm = True )
9091 except NoTTYException :
9192 raise CLIError ('Please specify --http-password in non-interactive mode.' )
9293
9394 # Update the cluster config with the HTTP credentials
94- gateway_config ['restAuthCredential.isEnabled' ] = 'true' # HTTP credentials are required
95- http_username = http_username or gateway_config ['restAuthCredential.username' ]
96- gateway_config ['restAuthCredential.username' ] = http_username
97- gateway_config ['restAuthCredential.password' ] = http_password
95+ if not entra_user_identity and not entra_user_full_info :
96+ gateway_config ['restAuthCredential.isEnabled' ] = 'true' # HTTP credentials are required
97+ http_username = http_username or gateway_config ['restAuthCredential.username' ]
98+ gateway_config ['restAuthCredential.username' ] = http_username
99+ gateway_config ['restAuthCredential.password' ] = http_password
100+ else :
101+ if entra_user_identity and entra_user_full_info :
102+ raise MutuallyExclusiveArgumentError (
103+ 'Cannot provide both --entra-user-identity and'
104+ ' --entra-user-full-info parameters.' )
105+ gateway_config ['restAuthCredential.isEnabled' ] = 'false'
106+ gateway_config ['restAuthEntraUsers' ] = get_entra_user_info (cmd , entra_user_identity , entra_user_full_info )
98107 cluster_configurations ['gateway' ] = gateway_config
99108
100109 # Validate whether SSH credentials were provided
@@ -107,13 +116,19 @@ def create_cluster(cmd, client, cluster_name, resource_group_name, cluster_type,
107116 raise CLIError ('Either the default container or the default filesystem can be specified, but not both.' )
108117
109118 # Retrieve primary blob service endpoint
110- is_wasb = not storage_account_managed_identity
119+ is_wasb = None
120+ if storage_default_container :
121+ is_wasb = True
122+ elif storage_default_filesystem :
123+ is_wasb = False
124+ else :
125+ is_wasb = is_wasb_storage_account (cmd , storage_account )
111126 storage_account_endpoint = None
112127 if storage_account :
113128 storage_account_endpoint = get_storage_account_endpoint (cmd , storage_account , is_wasb )
114129
115130 # Attempt to infer the storage account key from the endpoint
116- if not storage_account_key and storage_account and is_wasb :
131+ if not storage_account_key and storage_account and not storage_account_managed_identity and is_wasb :
117132 from .util import get_key_for_storage_account
118133 logger .info ('Storage account key not specified. Attempting to retrieve key...' )
119134 key = get_key_for_storage_account (cmd , storage_account )
@@ -130,8 +145,8 @@ def create_cluster(cmd, client, cluster_name, resource_group_name, cluster_type,
130145 logger .warning ('Default ADLS file system not specified, using "%s".' , storage_default_filesystem )
131146
132147 # Validate storage info parameters
133- if is_wasb and not _all_or_none (storage_account , storage_account_key , storage_default_container ):
134- raise CLIError ('If storage details are specified, the storage account, storage account key, '
148+ if is_wasb and not _all_or_none (storage_account , storage_default_container ):
149+ raise CLIError ('If storage details are specified, the storage account, '
135150 'and the default container must be specified.' )
136151 if not is_wasb and not _all_or_none (storage_account , storage_default_filesystem ):
137152 raise CLIError ('If storage details are specified, the storage account, '
@@ -903,3 +918,34 @@ def _extract_and_validate_autoscale_configuration(cluster):
903918def _validate_schedule_configuration (autoscale_configuration ):
904919 if not autoscale_configuration .recurrence :
905920 raise CLIError ('The cluster has not enabled Schedule-based autoscale.' )
921+
922+
923+ def update_gateway_settings (cmd , client , cluster_name , resource_group_name , http_username = None ,
924+ http_password = None , entra_user_identity = None , entra_user_full_info = None , no_wait = False ):
925+ from azure .mgmt .hdinsight .models import UpdateGatewaySettingsParameters
926+ from .util import get_entra_user_info
927+ if not http_password and not entra_user_identity and not entra_user_full_info :
928+ try :
929+ http_password = prompt_pass ('HTTP password for the cluster:' , confirm = True )
930+ except NoTTYException :
931+ raise CLIError ('Please specify --http-password in non-interactive mode.' )
932+ if http_password and not http_username :
933+ http_username = 'admin'
934+ if entra_user_identity and entra_user_full_info :
935+ raise MutuallyExclusiveArgumentError (
936+ 'Cannot provide both --entra-user-identity and'
937+ ' --entra-user-full-info parameters.' )
938+ rest_auth_entra_users_data = None
939+ if entra_user_identity or entra_user_full_info :
940+ rest_auth_entra_users_data = get_entra_user_info (cmd , entra_user_identity , entra_user_full_info , False )
941+ update_gateway_settings_parameters = UpdateGatewaySettingsParameters (
942+ is_credential_enabled = bool (http_password ),
943+ user_name = http_username ,
944+ password = http_password ,
945+ rest_auth_entra_users = rest_auth_entra_users_data
946+ )
947+ try :
948+ return sdk_no_wait (no_wait , client .begin_update_gateway_settings , resource_group_name ,
949+ cluster_name , update_gateway_settings_parameters )
950+ except Exception as ex :
951+ raise CLIError (str (ex ))
0 commit comments