Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/spring/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Release History
===============
1.14.0
---
* Add new command `az spring application-configuration-service create --generation` to support creating Application Configuration Service with different generation
* Add new command `az spring application-configuration-service update --generation` to support updating Application Configuration Service to different generation
* Add new command `az spring application-configuration-service git repo add --ca-cert-name` to support binding certificate to Application Configuration Service Gen2

1.13.3
---
* Add arguments `--allowed-origin-patterns`, `--addon-configs-json` and `--addon-configs-file` in `az spring gateway update`.
Expand Down
8 changes: 8 additions & 0 deletions src/spring/azext_spring/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,14 @@
text: az spring application-configuration-service create -s MyService -g MyResourceGroup
"""

helps['spring application-configuration-service update'] = """
type: command
short-summary: Update Application Configuration Service.
examples:
- name: Update Application Configuration Service.
text: az spring application-configuration-service update -s MyService -g MyResourceGroup --generation Gen2
"""

helps['spring application-configuration-service delete'] = """
type: command
short-summary: Delete Application Configuration Service.
Expand Down
16 changes: 14 additions & 2 deletions src/spring/azext_spring/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
validate_acs_ssh_or_warn, validate_apm_properties, validate_apm_secrets,
validate_apm_not_exist, validate_apm_update, validate_apm_reference,
validate_apm_reference_and_enterprise_tier, validate_cert_reference,
validate_build_cert_reference)
validate_build_cert_reference, validate_acs_create)
from ._app_validator import (fulfill_deployment_param, active_deployment_exist,
ensure_not_active_deployment, validate_deloy_path, validate_deloyment_create_path,
validate_cpu, validate_build_cpu, validate_memory, validate_build_memory,
Expand All @@ -41,7 +41,7 @@
validate_app_force_set_system_identity_or_warning,
validate_app_force_set_user_identity_or_warning)
from ._utils import ApiType
from .vendored_sdks.appplatform.v2023_05_01_preview.models._app_platform_management_client_enums import (SupportedRuntimeValue, TestKeyType, BackendProtocol, SessionAffinity, ApmType, BindingType)
from .vendored_sdks.appplatform.v2023_05_01_preview.models._app_platform_management_client_enums import (ConfigurationServiceGeneration, SupportedRuntimeValue, TestKeyType, BackendProtocol, SessionAffinity, ApmType, BindingType)


name_type = CLIArgumentType(options_list=[
Expand Down Expand Up @@ -156,7 +156,14 @@ def load_arguments(self, _):
c.argument('enable_application_configuration_service',
action='store_true',
options_list=['--enable-application-configuration-service', '--enable-acs'],
arg_group="Application Configuration Service",
help='(Enterprise Tier Only) Enable Application Configuration Service.')
c.argument('application_configuration_service_generation',
arg_group="Application Configuration Service",
arg_type=get_enum_type(ConfigurationServiceGeneration),
options_list=['--application-configuration-service-generation', '--acs-gen'],
validator=validate_acs_create,
help='(Enterprise Tier Only) Application Configuration Service Generation to enable.')
c.argument('enable_application_live_view',
action='store_true',
options_list=['--enable-application-live-view', '--enable-alv'],
Expand Down Expand Up @@ -810,6 +817,10 @@ def prepare_logs_argument(c):
with self.argument_context('spring application-configuration-service {}'.format(scope)) as c:
c.argument('app', app_name_type, help='Name of app.', validator=validate_app_name)

for scope in ['create', 'update']:
with self.argument_context('spring application-configuration-service {}'.format(scope)) as c:
c.argument('generation', arg_type=get_enum_type(ConfigurationServiceGeneration), help='Generation of Application Configuration Service.')

for scope in ['add', 'update']:
with self.argument_context('spring application-configuration-service git repo {}'.format(scope)) as c:
c.argument('patterns',
Expand All @@ -826,6 +837,7 @@ def prepare_logs_argument(c):
c.argument('host_key_algorithm', help='Host key algorithm of the added config.')
c.argument('private_key', help='Private_key of the added config.', validator=validate_acs_ssh_or_warn)
c.argument('host_key_check', help='Strict host key checking of the added config which is used in SSH authentication. If false, ignore errors with host key.')
c.argument('ca_cert_name', help='CA certificate name.')

for scope in ['add', 'update', 'remove']:
with self.argument_context('spring application-configuration-service git repo {}'.format(scope)) as c:
Expand Down
12 changes: 10 additions & 2 deletions src/spring/azext_spring/_tanzu_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from msrestazure.tools import resource_id
from .application_live_view import create as application_live_view_create
from .dev_tool_portal import create_or_update as dev_tool_portal_create

from .vendored_sdks.appplatform.v2023_05_01_preview.models._app_platform_management_client_enums import ConfigurationServiceGeneration
from .vendored_sdks.appplatform.v2023_05_01_preview import models

GATEWAY_RESOURCE_TYPE = "gateways"
Expand All @@ -32,10 +32,18 @@ def create_application_live_view(cmd, client, resource_group, service, enable_ap
return application_live_view_create(cmd, client, service, resource_group)


def create_application_configuration_service(cmd, client, resource_group, service, enable_application_configuration_service, **_):
def create_application_configuration_service(cmd, client, resource_group, service, enable_application_configuration_service, application_configuration_service_generation, **_):
if enable_application_configuration_service:
logger.warning(" - Creating Application Configuration Service ..")
acs_resource = models.ConfigurationServiceResource()
acs_resource.properties = models.ConfigurationServiceProperties()
if application_configuration_service_generation:
acs_resource.properties.generation = application_configuration_service_generation
logger.warning("Create with generation {}".format(application_configuration_service_generation))
else:
acs_resource.properties.generation = ConfigurationServiceGeneration.GEN1
logger.warning("Default generation will be Gen1")

return client.configuration_services.begin_create_or_update(resource_group, service, DEFAULT_NAME, acs_resource)


Expand Down
2 changes: 2 additions & 0 deletions src/spring/azext_spring/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def _check_tanzu_components_not_enable(cmd, namespace):
raise ArgumentUsageError('--enable-application-live-view {}'.format(suffix))
if namespace.enable_application_accelerator:
raise ArgumentUsageError('--enable-application-accelerator {}'.format(suffix))
if namespace.application_configuration_service_generation:
raise ArgumentUsageError('--application-configuration-service-generation {}'.format(suffix))


def validate_instance_count(namespace):
Expand Down
8 changes: 7 additions & 1 deletion src/spring/azext_spring/_validators_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from azure.core.exceptions import ResourceNotFoundError
from knack.log import get_logger
from .vendored_sdks.appplatform.v2023_05_01_preview.models import (ApmReference, CertificateReference)
from .vendored_sdks.appplatform.v2023_05_01_preview.models._app_platform_management_client_enums import ApmType
from .vendored_sdks.appplatform.v2023_05_01_preview.models._app_platform_management_client_enums import (ApmType, ConfigurationServiceGeneration)

from ._resource_quantity import validate_cpu as validate_and_normalize_cpu
from ._resource_quantity import \
Expand Down Expand Up @@ -345,6 +345,12 @@ def _is_valid_app_and_profile_name(pattern):
return len(parts) == 2 and _is_valid_app_name(parts[0]) and _is_valid_profile_name(parts[1])


def validate_acs_create(namespace):
if namespace.application_configuration_service_generation is not None:
if namespace.enable_application_configuration_service is False:
raise ArgumentUsageError("--application-configuration-service-generation can only be set when enable application configuration service.")


def validate_gateway_update(namespace):
_validate_sso(namespace)
validate_cpu(namespace)
Expand Down
46 changes: 38 additions & 8 deletions src/spring/azext_spring/application_configuration_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from azure.cli.core.util import sdk_no_wait
from knack.log import get_logger
from msrestazure.tools import resource_id

from .vendored_sdks.appplatform.v2023_05_01_preview.models._app_platform_management_client_enums import (GitImplementation, ConfigurationServiceGeneration)
from .vendored_sdks.appplatform.v2023_05_01_preview import models

APPLICATION_CONFIGURATION_SERVICE_NAME = "applicationConfigurationService"
Expand All @@ -23,8 +23,27 @@
logger = get_logger(__name__)


def application_configuration_service_create(cmd, client, service, resource_group):
acs_resource = models.ConfigurationServiceResource()
def application_configuration_service_create(cmd, client, service, resource_group,
generation=None):
if generation is None:
generation = ConfigurationServiceGeneration.GEN1

properties = models.ConfigurationServiceProperties(generation=generation)
acs_resource = models.ConfigurationServiceResource(properties=properties)
logger.warning("Create with generation {}".format(acs_resource.properties.generation))
return client.configuration_services.begin_create_or_update(resource_group, service, DEFAULT_NAME, acs_resource)


def application_configuration_service_update(cmd, client, service, resource_group,
generation=None):
acs_resource = client.configuration_services.get(resource_group, service, DEFAULT_NAME)
if generation is not None:
acs_resource.properties.generation = generation
logger.warning("Updating with generation {}".format(generation))
else:
acs_resource.properties.generation = ConfigurationServiceGeneration.GEN1
logger.warning("Default generation will be Gen1")
logger.warning(acs_resource.properties.generation)
return client.configuration_services.begin_create_or_update(resource_group, service, DEFAULT_NAME, acs_resource)


Expand All @@ -38,8 +57,8 @@ def application_configuration_service_show(cmd, client, service, resource_group)

def application_configuration_service_clear(cmd, client, service, resource_group):
logger.warn("Please make sure no patterns are used in your apps.")
properties = models.ConfigurationServiceGitProperty()
acs_resource = models.ConfigurationServiceResource(properties=properties)
acs_resource = client.configuration_services.get(resource_group, service, DEFAULT_NAME)
acs_resource.properties.settings = models.ConfigurationServiceSettings()
return client.configuration_services.begin_create_or_update(resource_group, service, DEFAULT_NAME, acs_resource)


Expand All @@ -52,9 +71,10 @@ def application_configuration_service_git_add(cmd, client, service, resource_gro
host_key_algorithm=None,
private_key=None,
host_key_check=None,
ca_cert_name=None,
no_wait=False):
repo = models.ConfigurationServiceGitRepository(name=name, patterns=patterns, uri=uri, label=label)
repo = _replace_repo_with_input(repo, patterns, uri, label, search_paths, username, password, host_key, host_key_algorithm, private_key, host_key_check)
repo = _replace_repo_with_input(repo, patterns, uri, label, search_paths, username, password, host_key, host_key_algorithm, private_key, host_key_check, _get_cert_resource_id_by_name(cmd, resource_group, service, ca_cert_name))

acs_resource = _get_or_default_acs_resource(client, resource_group, service)
repos = acs_resource.properties.settings.git_property.repositories
Expand All @@ -80,10 +100,11 @@ def application_configuration_service_git_update(cmd, client, service, resource_
host_key_algorithm=None,
private_key=None,
host_key_check=None,
ca_cert_name=None,
no_wait=False):
acs_resource = _get_or_default_acs_resource(client, resource_group, service)
repo = _get_existing_repo(acs_resource.properties.settings.git_property.repositories, name)
repo = _replace_repo_with_input(repo, patterns, uri, label, search_paths, username, password, host_key, host_key_algorithm, private_key, host_key_check)
repo = _replace_repo_with_input(repo, patterns, uri, label, search_paths, username, password, host_key, host_key_algorithm, private_key, host_key_check, _get_cert_resource_id_by_name(cmd, resource_group, service, ca_cert_name))

_validate_acs_settings(client, resource_group, service, acs_resource.properties.settings)

Expand Down Expand Up @@ -152,7 +173,15 @@ def _get_app_addon_configs_with_acs(addon_configs):
return addon_configs


def _replace_repo_with_input(repo, patterns, uri, label, search_paths, username, password, host_key, host_key_algorithm, private_key, strict_host_key_checking):
def _get_cert_resource_id_by_name(cmd, resource_group, service, ca_cert_name):
ca_cert_resource_id = None
if ca_cert_name:
subscription = get_subscription_id(cmd.cli_ctx)
ca_cert_resource_id = "/subscriptions/{}/resourceGroups/{}/providers/Microsoft.AppPlatform/Spring/{}/certificates/{}".format(subscription, resource_group, service, ca_cert_name)
return ca_cert_resource_id


def _replace_repo_with_input(repo, patterns, uri, label, search_paths, username, password, host_key, host_key_algorithm, private_key, strict_host_key_checking, ca_cert_resource_id):
if patterns:
patterns = patterns.split(",")
if search_paths:
Expand All @@ -170,6 +199,7 @@ def _replace_repo_with_input(repo, patterns, uri, label, search_paths, username,
repo.host_key_algorithm = host_key_algorithm or repo.host_key_algorithm
repo.private_key = private_key or repo.private_key
repo.strict_host_key_checking = strict_host_key_checking or repo.strict_host_key_checking
repo.ca_cert_resource_id = ca_cert_resource_id or repo.ca_cert_resource_id
return repo


Expand Down
1 change: 1 addition & 0 deletions src/spring/azext_spring/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def load_command_table(self, _):
g.custom_command('bind', 'application_configuration_service_bind')
g.custom_command('unbind', 'application_configuration_service_unbind')
g.custom_command('create', 'application_configuration_service_create', table_transformer=transform_application_configuration_service_output)
g.custom_command('update', 'application_configuration_service_update', table_transformer=transform_application_configuration_service_output)
g.custom_command('delete', 'application_configuration_service_delete', confirmation=True)

with self.command_group('spring application-configuration-service git repo',
Expand Down
2 changes: 2 additions & 0 deletions src/spring/azext_spring/spring_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def spring_create(cmd, client, resource_group, name,
registry_username=None,
registry_password=None,
enable_application_configuration_service=False,
application_configuration_service_generation=None,
enable_application_live_view=False,
enable_service_registry=False,
enable_gateway=False,
Expand Down Expand Up @@ -222,6 +223,7 @@ def spring_create(cmd, client, resource_group, name,
'registry_username': registry_username,
'registry_password': registry_password,
'enable_application_configuration_service': enable_application_configuration_service,
'application_configuration_service_generation': application_configuration_service_generation,
'enable_application_live_view': enable_application_live_view,
'enable_service_registry': enable_service_registry,
'enable_gateway': enable_gateway,
Expand Down
Loading