diff --git a/src/azure-cli/azure/cli/command_modules/serviceconnector/_params.py b/src/azure-cli/azure/cli/command_modules/serviceconnector/_params.py index 5deff4c218b..d261968fd49 100644 --- a/src/azure-cli/azure/cli/command_modules/serviceconnector/_params.py +++ b/src/azure-cli/azure/cli/command_modules/serviceconnector/_params.py @@ -15,6 +15,7 @@ from ._resource_config import ( RESOURCE, SOURCE_RESOURCES_PARAMS, + SOURCE_RESOURCES_CREATE_PARAMS, TARGET_RESOURCES_PARAMS, AUTH_TYPE_PARAMS, SUPPORTED_AUTH_TYPE, @@ -63,9 +64,8 @@ def add_source_resource_block(context, source, enable_id=True, validate_source_i help="Use keyvault as a secrets store via a CSI volume. " "If specified, AuthType Arguments are not needed.") elif source == RESOURCE.ContainerApp: - context.argument('scope', options_list=['-c', '--container'], type=str, - help="The container where the connection information " - "will be saved (as environment variables).") + for arg, content in SOURCE_RESOURCES_CREATE_PARAMS.get(source).items(): + context.argument(arg, options_list=content.get('options'), type=str, help=content.get('help')) context.ignore('enable_csi') else: context.ignore('scope') diff --git a/src/azure-cli/azure/cli/command_modules/serviceconnector/_resource_config.py b/src/azure-cli/azure/cli/command_modules/serviceconnector/_resource_config.py index 57f40e10d0e..e329bc48aaa 100644 --- a/src/azure-cli/azure/cli/command_modules/serviceconnector/_resource_config.py +++ b/src/azure-cli/azure/cli/command_modules/serviceconnector/_resource_config.py @@ -183,6 +183,18 @@ class CLIENT_TYPE(Enum): } +# The dict defines the required parameters used in the source resources for creation. +SOURCE_RESOURCES_CREATE_PARAMS = { + RESOURCE.ContainerApp: { + 'scope': { + 'options': ['--container', '-c'], + 'help': 'The container where the connection information will be saved (as environment variables).', + 'placeholder': 'MyContainer' + }, + }, +} + + # The dict defines the parameters used to position the target resources. # The parmaters should include all variables defined in target resource id expect # for 'subscription', which will be dealt by CLI core as a default parameter. diff --git a/src/azure-cli/azure/cli/command_modules/serviceconnector/_validators.py b/src/azure-cli/azure/cli/command_modules/serviceconnector/_validators.py index c20742142fc..caac3082785 100644 --- a/src/azure-cli/azure/cli/command_modules/serviceconnector/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/serviceconnector/_validators.py @@ -30,6 +30,7 @@ SOURCE_RESOURCES, TARGET_RESOURCES, SOURCE_RESOURCES_PARAMS, + SOURCE_RESOURCES_CREATE_PARAMS, TARGET_RESOURCES_PARAMS, AUTH_TYPE_PARAMS, SUPPORTED_AUTH_TYPE @@ -175,7 +176,7 @@ def _infer_springcloud(source_id): return client_type - # fallback to use Dotnet as client type + # fallback to use None as client type client_type = None if 'webapp' in cmd.name: client_type = _infer_webapp(namespace.source_id) @@ -184,7 +185,7 @@ def _infer_springcloud(source_id): method = 'detected' if client_type is None: - client_type = CLIENT_TYPE.Dotnet + client_type = CLIENT_TYPE.Blank method = 'default' logger.warning('Client type is not specified, use %s one: --client-type %s', method, client_type.value) @@ -385,6 +386,21 @@ def get_missing_source_args(cmd): return missing_args +def get_missing_source_create_args(cmd, namespace): + '''Get source resource related args in create + ''' + source = get_source_resource_name(cmd) + missing_args = dict() + + args = SOURCE_RESOURCES_CREATE_PARAMS.get(source) + if args: + for arg, content in args.items(): + if not getattr(namespace, arg, None): + missing_args[arg] = content + + return missing_args + + def get_missing_target_args(cmd): '''Get target resource related args ''' @@ -471,6 +487,7 @@ def validate_create_params(cmd, namespace): missing_args = dict() if not validate_source_resource_id(namespace): missing_args.update(get_missing_source_args(cmd)) + missing_args.update(get_missing_source_create_args(cmd, namespace)) if not validate_target_resource_id(namespace): missing_args.update(get_missing_target_args(cmd)) missing_args.update(get_missing_auth_args(cmd, namespace)) @@ -519,6 +536,15 @@ def apply_source_args(cmd, namespace, arg_values): ) +def apply_source_create_args(cmd, namespace, arg_values): + '''Set source resource related args in create by arg_values + ''' + source = get_source_resource_name(cmd) + for arg in SOURCE_RESOURCES_CREATE_PARAMS.get(source, {}): + if arg in arg_values: + setattr(namespace, arg, arg_values.get(arg, None)) + + def apply_target_args(cmd, namespace, arg_values): '''Set target resource id by arg_values ''' @@ -568,6 +594,7 @@ def apply_create_params(cmd, namespace, arg_values): '''Set create command missing args ''' apply_source_args(cmd, namespace, arg_values) + apply_source_create_args(cmd, namespace, arg_values) apply_target_args(cmd, namespace, arg_values) apply_auth_args(cmd, namespace, arg_values) diff --git a/src/azure-cli/azure/cli/command_modules/serviceconnector/custom.py b/src/azure-cli/azure/cli/command_modules/serviceconnector/custom.py index a5cc4c273ea..baccc550f93 100644 --- a/src/azure-cli/azure/cli/command_modules/serviceconnector/custom.py +++ b/src/azure-cli/azure/cli/command_modules/serviceconnector/custom.py @@ -261,6 +261,7 @@ def connection_update(cmd, client, # pylint: disable=too-many-locals key_vault_id=None, service_endpoint=None, no_wait=False, + scope=None, cluster=None, enable_csi=False, # Resource.Kubernetes site=None, # Resource.WebApp spring=None, app=None, deployment='default'): # Resource.SpringCloud @@ -306,8 +307,8 @@ def connection_update(cmd, client, # pylint: disable=too-many-locals 'key_vault_id': key_vault_id, }, 'client_type': client_type or linker.get('clientType'), - # scope does not support update due to aks solution's limitation - 'scope': linker.get('scope') + # scope can be updated in container app while cannot be updated in aks due to some limitations + 'scope': scope or linker.get('scope') } # HACK: set user token to work around OBO