Skip to content

Commit

Permalink
Add validator of pricing tier for az spring app-insights update/show …
Browse files Browse the repository at this point in the history
…xxx (#5053)
  • Loading branch information
jiec-msft authored Jul 6, 2022
1 parent 7ffac4d commit 945d0a8
Show file tree
Hide file tree
Showing 13 changed files with 7,361 additions and 6,149 deletions.
4 changes: 4 additions & 0 deletions src/spring/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Release History
===============
1.1.4
---
* Add warning that `az spring app-insights` don't support Enterprise tier.

1.1.3
---
* Enhance Application Insights settings when create service instance.
Expand Down
4 changes: 4 additions & 0 deletions src/spring/azext_spring/_clierror.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
class ConflictRequestError(UserFault):
""" Conflict request: 409 error """
pass


class NotSupportedPricingTierError(UserFault):
pass
13 changes: 7 additions & 6 deletions src/spring/azext_spring/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,20 +563,21 @@ def prepare_logs_argument(c):

with self.argument_context('spring app-insights update') as c:
c.argument('app_insights_key',
arg_group='Application Insights',
help="Connection string (recommended) or Instrumentation key of the existing Application Insights.",
validator=validate_app_insights_parameters)
c.argument('app_insights',
arg_group='Application Insights',
help="Name of the existing Application Insights in the same Resource Group. "
"Or Resource ID of the existing Application Insights in a different Resource Group.",
validator=validate_app_insights_parameters)
"Or Resource ID of the existing Application Insights in a different Resource Group.")
c.argument('sampling_rate',
type=float,
help="Sampling Rate of application insights. Maximum is 100.",
validator=validate_app_insights_parameters)
arg_group='Application Insights',
help="Sampling Rate of application insights. Maximum is 100.")
c.argument('disable',
arg_type=get_three_state_flag(),
help="Disable Application Insights.",
validator=validate_app_insights_parameters)
arg_group='Application Insights',
help="Disable Application Insights.")

with self.argument_context('spring build-service builder') as c:
c.argument('service', service_name_type, validator=only_support_enterprise)
Expand Down
11 changes: 10 additions & 1 deletion src/spring/azext_spring/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
from azure.mgmt.core.tools import parse_resource_id
from azure.mgmt.core.tools import resource_id
from knack.log import get_logger
from ._clierror import NotSupportedPricingTierError
from ._utils import (ApiType, _get_rg_location, _get_file_type, _get_sku_name)
from ._util_enterprise import is_enterprise_tier
from .vendored_sdks.appplatform.v2020_07_01 import models
from ._constant import (MARKETPLACE_OFFER_ID, MARKETPLACE_PLAN_ID, MARKETPLACE_PUBLISHER_ID)

Expand Down Expand Up @@ -239,7 +241,7 @@ def validate_java_agent_parameters(namespace):
"can not be set at the same time.")


def validate_app_insights_parameters(namespace):
def validate_app_insights_parameters(cmd, namespace):
if (namespace.app_insights or namespace.app_insights_key or namespace.sampling_rate is not None) \
and namespace.disable:
raise InvalidArgumentValueError(
Expand All @@ -251,6 +253,7 @@ def validate_app_insights_parameters(namespace):
and not namespace.disable:
raise InvalidArgumentValueError("Invalid value: nothing is updated for application insights.")
_validate_app_insights_parameters(namespace)
validate_app_insights_command_not_supported_tier(cmd, namespace)


def _validate_app_insights_parameters(namespace):
Expand All @@ -265,6 +268,12 @@ def _validate_app_insights_parameters(namespace):
raise InvalidArgumentValueError("Invalid value: Sampling Rate must be in the range [0,100].")


def validate_app_insights_command_not_supported_tier(cmd, namespace):
if is_enterprise_tier(cmd, namespace.resource_group, namespace.name):
raise NotSupportedPricingTierError("Enterprise tier service instance {} in group {} is not supported in this command, ".format(namespace.name, namespace.resource_group) +
"please refer to 'az spring build-service builder buildpack-binding' command group.")


def validate_vnet(cmd, namespace):
if not namespace.vnet and not namespace.app_subnet and \
not namespace.service_runtime_subnet and not namespace.reserved_cidr_range:
Expand Down
4 changes: 3 additions & 1 deletion src/spring/azext_spring/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
transform_service_registry_output,
transform_spring_cloud_gateway_output,
transform_api_portal_output)
from ._validators import validate_app_insights_command_not_supported_tier
from ._validators_enterprise import (validate_gateway_update, validate_api_portal_update)
from ._app_managed_identity_validator import (validate_app_identity_remove_or_warning,
validate_app_identity_assign_or_warning)
Expand Down Expand Up @@ -219,7 +220,8 @@ def load_command_table(self, _):
client_factory=cf_spring_20201101preview,
exception_handler=handle_asc_exception) as g:
g.custom_command('update', 'app_insights_update', supports_no_wait=True)
g.custom_show_command('show', 'app_insights_show')
g.custom_show_command('show', 'app_insights_show',
validator=validate_app_insights_command_not_supported_tier)

with self.command_group('spring service-registry',
custom_command_type=service_registry_cmd_group,
Expand Down
Loading

0 comments on commit 945d0a8

Please sign in to comment.