Skip to content

Commit

Permalink
[containerapp] az containerapp create/update: Support --customized-…
Browse files Browse the repository at this point in the history
…keys and clientType in --bind for dev service (#6939)

* add test and add clientType and customized keys

* fix test

* fix

* fix test

* add test for yaml

* fix

* add more tests

* fix conflict

* fix customizedKey for yaml

* address comments

* add more comments

* add test cases

* fix test

* Update src/containerapp/azext_containerapp/_params.py

Co-authored-by: Xing Zhou <Zhou.Xing@microsoft.com>

* Update src/containerapp/azext_containerapp/_params.py

Co-authored-by: Xing Zhou <Zhou.Xing@microsoft.com>

---------

Co-authored-by: Xing Zhou <Zhou.Xing@microsoft.com>
  • Loading branch information
Greedygre and zhoxing-ms committed Nov 10, 2023
1 parent 6eb01fb commit 7fc0f72
Show file tree
Hide file tree
Showing 11 changed files with 15,605 additions and 554 deletions.
1 change: 1 addition & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ upcoming
* 'az containerapp env create/update': Support --logs-dynamic-json-columns/-j to configure whether to parse json string log into dynamic json columns
* 'az containerapp create/update/up': Remove the region check for the Cloud Build feature
* 'az containerapp create/update/up': Improve logs on the local buildpack source to cloud flow
* 'az containerapp create/update': Support --customized-keys and clientType in --bind for dev service

0.3.43
++++++
Expand Down
7 changes: 5 additions & 2 deletions src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
file_type,
get_three_state_flag, get_enum_type, tags_type)

from .action import AddCustomizedKeys
from ._validators import (validate_env_name_or_id,
validate_custom_location_name_or_id)
from ._constants import MAXIMUM_CONTAINER_APP_NAME_LENGTH
Expand All @@ -24,8 +25,9 @@ def load_arguments(self, _):
c.argument('artifact', help="Local path to the application artifact for building the container image. See the supported artifacts here: https://aka.ms/SourceToCloudSupportedArtifacts.", is_preview=True)

# Springboard
with self.argument_context('containerapp create', arg_group='Service Binding') as c:
with self.argument_context('containerapp create', arg_group='Service Binding', is_preview=True) as c:
c.argument('service_bindings', nargs='*', options_list=['--bind'], help="Space separated list of services(bindings) to be connected to this app. e.g. SVC_NAME1[:BIND_NAME1] SVC_NAME2[:BIND_NAME2]...")
c.argument('customized_keys', action=AddCustomizedKeys, nargs='*', help='The customized keys used to change default configuration names. Key is the original name, value is the customized name.')
c.argument('service_type', help="The service information for dev services.")
c.ignore('service_type')

Expand All @@ -44,8 +46,9 @@ def load_arguments(self, _):
c.argument('artifact', help="Local path to the application artifact for building the container image. See the supported artifacts here: https://aka.ms/SourceToCloudSupportedArtifacts.", is_preview=True)

# Springboard
with self.argument_context('containerapp update', arg_group='Service Binding') as c:
with self.argument_context('containerapp update', arg_group='Service Binding', is_preview=True) as c:
c.argument('service_bindings', nargs='*', options_list=['--bind'], help="Space separated list of services(bindings) to be connected to this app. e.g. SVC_NAME1[:BIND_NAME1] SVC_NAME2[:BIND_NAME2]...")
c.argument('customized_keys', action=AddCustomizedKeys, nargs='*', help='The customized keys used to change default configuration names. Key is the original name, value is the customized name.')
c.argument('unbind_service_bindings', nargs='*', options_list=['--unbind'], help="Space separated list of services(bindings) to be removed from this app. e.g. BIND_NAME1...")

with self.argument_context('containerapp env', arg_group='Virtual Network') as c:
Expand Down
17 changes: 10 additions & 7 deletions src/containerapp/azext_containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


def process_service(cmd, resource_list, service_name, arg_dict, subscription_id, resource_group_name, name,
binding_name, service_connector_def_list, service_bindings_def_list):
binding_name, service_connector_def_list, service_bindings_def_list, customized_keys=None):
# Check if the service exists in the list of dict
for service in resource_list:
if service["name"] == service_name:
Expand Down Expand Up @@ -74,11 +74,14 @@ def process_service(cmd, resource_list, service_name, arg_dict, subscription_id,

if service_type is None or service_type not in DEV_SERVICE_LIST:
raise ResourceNotFoundError(f"The service '{service_name}' does not exist")

service_bindings_def_list.append({
service_bind = {
"serviceId": containerapp_def["id"],
"name": binding_name
})
"name": binding_name,
"clientType": arg_dict.get("clientType")
}
if customized_keys:
service_bind["customizedKeys"] = customized_keys
service_bindings_def_list.append(service_bind)

else:
raise ValidationError("Service not supported")
Expand Down Expand Up @@ -140,7 +143,7 @@ def check_unique_bindings(cmd, service_connectors_def_list, service_bindings_def
return True


def parse_service_bindings(cmd, service_bindings_list, resource_group_name, name):
def parse_service_bindings(cmd, service_bindings_list, resource_group_name, name, customized_keys=None):
# Make it return both managed and dev bindings
service_bindings_def_list = []
service_connector_def_list = []
Expand Down Expand Up @@ -194,7 +197,7 @@ def parse_service_bindings(cmd, service_bindings_list, resource_group_name, name

# Will work for both create and update
process_service(cmd, resource_list, service_name, arg_dict, subscription_id, resource_group_name,
name, binding_name, service_connector_def_list, service_bindings_def_list)
name, binding_name, service_connector_def_list, service_bindings_def_list, customized_keys)

return service_connector_def_list, service_bindings_def_list

Expand Down
24 changes: 24 additions & 0 deletions src/containerapp/azext_containerapp/action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import argparse
from collections import defaultdict
from azure.cli.core.azclierror import ValidationError


class AddCustomizedKeys(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.customized_keys = action

def get_action(self, values, option_string): # pylint: disable=no-self-use
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k] = v
properties = dict(properties)
return properties
except ValueError:
raise ValidationError('Usage error: {} [DesiredKey=DefaultKey ...]'.format(option_string))
Loading

0 comments on commit 7fc0f72

Please sign in to comment.