Skip to content

Commit ebf3f56

Browse files
committed
update
1 parent ef341ab commit ebf3f56

File tree

3 files changed

+36
-38
lines changed

3 files changed

+36
-38
lines changed

src/azure-cli/azure/cli/command_modules/serviceconnector/_params.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,12 @@ def add_connstr_props_argument(context):
191191
validator=validate_connstr_props)
192192

193193

194-
def add_force_create_arguments(context):
195-
context.argument('force', options_list=['--force', '-f'],
194+
def add_no_recreate_arguments(context):
195+
context.argument('no_recreate', options_list=['--no-recreate'],
196196
arg_type=get_three_state_flag(), default=False,
197-
help='Indicates whether to force to execute operation to create \
198-
an existing connection even without any updates.')
197+
help='Indicates whether to skip execute creation operation \
198+
when no updates to an existing connection exists')
199+
199200

200201
def add_target_type_argument(context, source):
201202
TARGET_TYPES = [
@@ -327,7 +328,7 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
327328
add_customized_keys_argument(c)
328329
add_opt_out_argument(c)
329330
add_connstr_props_argument(c)
330-
add_force_create_arguments(c)
331+
add_no_recreate_arguments(c)
331332

332333
with self.argument_context('{} connection update {}'.format(source.value, target.value)) as c:
333334
add_client_type_argument(c, source, target)

src/azure-cli/azure/cli/command_modules/serviceconnector/_utils.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
)
1515
# from azure.cli.core._profile import Profile
1616
from ._resource_config import (
17-
SOURCE_RESOURCES_USERTOKEN,
18-
TARGET_RESOURCES_USERTOKEN,
1917
RESOURCE
2018
)
2119
from azure.cli.core import get_default_cli
@@ -126,8 +124,9 @@ def set_user_token_header(client, cli_ctx):
126124

127125
def set_user_token_by_source_and_target(client, cli_ctx, source, target):
128126
'''Set user token header to work around OBO according to source and target'''
129-
if source in SOURCE_RESOURCES_USERTOKEN or target in TARGET_RESOURCES_USERTOKEN:
130-
return set_user_token_header(client, cli_ctx)
127+
# deprecated
128+
# if source in SOURCE_RESOURCES_USERTOKEN or target in TARGET_RESOURCES_USERTOKEN:
129+
# return set_user_token_header(client, cli_ctx)
131130
return client
132131

133132

@@ -582,44 +581,33 @@ def compare_properties_changed(new_props, existing_props):
582581
Returns True if there are differences that require an update.
583582
"""
584583
def has_meaningful_changes(new_value, existing_value):
585-
if new_value is None:
586-
# If new value is None, no change needed
584+
if new_value is None or new_value == "":
587585
return False
588586

589587
if isinstance(new_value, dict) and isinstance(existing_value, dict):
590-
# For nested dictionaries, check each key recursively
591588
for key, value in new_value.items():
589+
if key == "mysql-identity-id" or key == 'user_object_id':
590+
continue
592591
existing_props_key = key
593592
if '_' in key:
594593
existing_props_key = to_camel_case(key)
595594
existing_nested = existing_value.get(existing_props_key) if existing_value else None
596595
if has_meaningful_changes(value, existing_nested):
597596
return True
598597
return False
599-
elif isinstance(new_value, dict) and existing_value is None:
600-
# If existing is None but new is a dict, check if any values in new dict are meaningful
598+
if isinstance(new_value, dict) and existing_value is None:
601599
for value in new_value.values():
602-
if value is not None:
600+
if value is not None or value != "":
603601
return True
604602
return False
605-
else:
606-
# For primitive values, compare directly
607-
return new_value != existing_value
608-
609-
# Check if any property has meaningful changes
610-
for key, new_value in new_props.items():
611-
existing_props_key = key
612-
if '_' in key:
613-
existing_props_key = to_camel_case(key)
614-
existing_value = existing_props.get(existing_props_key) if existing_props else None
615-
if has_meaningful_changes(new_value, existing_value):
616-
return True
617-
return False
603+
604+
return new_value != existing_value
605+
606+
return has_meaningful_changes(new_props, existing_props)
618607

619608

620609
def to_camel_case(snake_str):
621610
if not snake_str or '_' not in snake_str:
622611
return snake_str
623612
components = snake_str.split('_')
624613
return components[0] + ''.join(word.capitalize() for word in components[1:])
625-

src/azure-cli/azure/cli/command_modules/serviceconnector/custom.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
get_secret_type_for_update
4545
)
4646
from ._credential_free import is_passwordless_command
47-
# pylint: disable=unused-argument,unsubscriptable-object,unsupported-membership-test,too-many-statements,too-many-locals
47+
# pylint: disable=unused-argument,unsubscriptable-object,unsupported-membership-test,too-many-statements,too-many-locals,broad-exception-caught
4848

4949

5050
logger = get_logger(__name__)
@@ -319,7 +319,7 @@ def connection_create(cmd, client, # pylint: disable=too-many-locals,too-many-s
319319
connstr_props=None, # Resource.FabricSql
320320
fabric_workspace_uuid=None,
321321
fabric_sql_db_uuid=None,
322-
force=False,
322+
no_recreate=False,
323323
):
324324
auth_action = 'optOutAllAuth' if (opt_out_list is not None and
325325
OPT_OUT_OPTION.AUTHENTICATION.value in opt_out_list) else None
@@ -373,12 +373,12 @@ def connection_create(cmd, client, # pylint: disable=too-many-locals,too-many-s
373373
enable_appconfig_extension=enable_appconfig_extension,
374374
server=server, database=database,
375375
connstr_props=connstr_props,
376-
force=force,
376+
no_recreate=no_recreate,
377377
)
378378

379379

380380
# The function is used in extension, new feature must be added in the end for backward compatibility
381-
def connection_create_func(cmd, client, # pylint: disable=too-many-locals,too-many-statements
381+
def connection_create_func(cmd, client, # pylint: disable=too-many-locals,too-many-statements,too-many-branches
382382
connection_name=None, client_type=None,
383383
source_resource_group=None, source_id=None,
384384
target_resource_group=None, target_id=None,
@@ -409,7 +409,7 @@ def connection_create_func(cmd, client, # pylint: disable=too-many-locals,too-m
409409
target_app_name=None, # Resource.ContainerApp
410410
enable_appconfig_extension=False,
411411
connstr_props=None, # Resource.FabricSql
412-
force=False,
412+
no_recreate=False,
413413
**kwargs,
414414
):
415415
if not source_id:
@@ -534,10 +534,19 @@ def connection_create_func(cmd, client, # pylint: disable=too-many-locals,too-m
534534
'manually and then create the connection.'.format(str(e)))
535535

536536
validate_service_state(parameters)
537-
linker = todict(client.get(resource_uri=source_id, linker_name=connection_name))
538-
if (linker is not None and not compare_properties_changed(parameters, linker) and force is False):
539-
logger.warning('Connection exists and no property to be updated, skip the update operation. Use --force to force the connection recreation')
540-
return linker
537+
try:
538+
linker = todict(client.get(resource_uri=source_id, linker_name=connection_name))
539+
logger.warning('provisioningState of existing connection: %s', linker.get('provisioningState'))
540+
if linker is not None and linker.get('provisioningState') == 'Accepted':
541+
logger.warning('Connection provisioningState is Accepted, please retry later to avoid conflict.')
542+
return linker
543+
if linker is not None and linker.get('provisioningState') == 'Succeeded' and \
544+
not compare_properties_changed(parameters, linker) and no_recreate is True:
545+
logger.warning(
546+
'Connection exists and no property to be updated, skip the update operation.')
547+
return linker
548+
except Exception as e:
549+
logger.debug('No existing connection, start creating a new one. Error: %s', e)
541550

542551
if enable_mi_for_db_linker and auth_action != 'optOutAllAuth':
543552
new_auth_info = enable_mi_for_db_linker(

0 commit comments

Comments
 (0)