Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gateway APM support #5652

Merged
merged 5 commits into from
Jan 6, 2023
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
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.6.2
---
* Add new arguments `--apm-types`, `--properties` and `--secrets` for command `az spring gateway update`.

1.6.1
---
* Add type check for argument `--artifact-path`.
Expand Down
12 changes: 9 additions & 3 deletions src/spring/azext_spring/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@


from .vendored_sdks.appplatform.v2020_07_01.models import RuntimeVersion, TestKeyType
from .vendored_sdks.appplatform.v2022_01_01_preview.models \
import _app_platform_management_client_enums as v20220101_preview_AppPlatformEnums
from .vendored_sdks.appplatform.v2022_01_01_preview.models._app_platform_management_client_enums import SupportedRuntimeValue, TestKeyType
from .vendored_sdks.appplatform.v2022_09_01_preview.models._app_platform_management_client_enums import BackendProtocol, SessionAffinity
from .vendored_sdks.appplatform.v2022_11_01_preview.models._app_platform_management_client_enums import ApmType, BindingType

name_type = CLIArgumentType(options_list=[
'--name', '-n'], help='The primary resource name', validator=validate_name)
Expand Down Expand Up @@ -718,6 +717,13 @@ def prepare_logs_argument(c):
c.argument('api_doc_location', arg_group='API metadata', help="Location of additional documentation for the APIs available on the Gateway instance.")
c.argument('api_version', arg_group='API metadata', help="Version of APIs available on this Gateway instance.")
c.argument('server_url', arg_group='API metadata', help="Base URL that API consumers will use to access APIs on the Gateway instance.")
c.argument('apm_types', nargs='*',
help="Space-separated list of APM integrated with Gateway. Allowed values are: " + ', '.join(list(ApmType)))
c.argument('properties', nargs='*',
help='Non-sensitive properties for environment variables. Format "key[=value]" and separated by space.')
c.argument('secrets', nargs='*',
help='Sensitive properties for environment variables. Once put, it will be encrypted and not returned.'
'Format "key[=value]" and separated by space.')
c.argument('allowed_origins', arg_group='Cross-origin Resource Sharing (CORS)', help="Comma-separated list of allowed origins to make cross-site requests. The special value `*` allows all domains.")
c.argument('allowed_methods', arg_group='Cross-origin Resource Sharing (CORS)', help="Comma-separated list of allowed HTTP methods on cross-site requests. The special value `*` allows all methods.")
c.argument('allowed_headers', arg_group='Cross-origin Resource Sharing (CORS)', help="Comma-separated list of allowed headers in cross-site requests. The special value `*` allows actual requests to send any header.")
Expand Down Expand Up @@ -756,7 +762,7 @@ def prepare_logs_argument(c):
'spring build-service builder buildpack-binding set']:
with self.argument_context(scope) as c:
c.argument('type',
arg_type=get_enum_type(v20220101_preview_AppPlatformEnums.BindingType),
arg_type=get_enum_type(BindingType),
help='Required type for buildpack binding.')
c.argument('properties',
help='Non-sensitive properties for launchProperties. Format "key[=value]".',
Expand Down
30 changes: 30 additions & 0 deletions src/spring/azext_spring/_validators_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
MutuallyExclusiveArgumentError)
from azure.core.exceptions import ResourceNotFoundError
from knack.log import get_logger
from .vendored_sdks.appplatform.v2022_11_01_preview.models._app_platform_management_client_enums import ApmType

from ._resource_quantity import validate_cpu as validate_and_normalize_cpu
from ._resource_quantity import \
Expand Down Expand Up @@ -191,6 +192,9 @@ def validate_gateway_update(namespace):
validate_cpu(namespace)
validate_memory(namespace)
validate_instance_count(namespace)
_validate_gateway_apm_types(namespace)
_validate_gateway_envs(namespace)
_validate_gateway_secrets(namespace)


def validate_api_portal_update(namespace):
Expand All @@ -215,6 +219,32 @@ def _validate_sso(namespace):
namespace.scope = namespace.scope.split(",") if namespace.scope else []


def _validate_gateway_apm_types(namespace):
if namespace.apm_types is None:
return
for type in namespace.apm_types:
if (type not in list(ApmType)):
raise InvalidArgumentValueError("Allowed APM types are: " + ', '.join(list(ApmType)))


def _validate_gateway_envs(namespace):
""" Extracts multiple space-separated properties in key[=value] format """
if isinstance(namespace.properties, list):
properties_dict = {}
for item in namespace.properties:
properties_dict.update(validate_tag(item))
namespace.properties = properties_dict


def _validate_gateway_secrets(namespace):
""" Extracts multiple space-separated secrets in key[=value] format """
if isinstance(namespace.secrets, list):
secrets_dict = {}
for item in namespace.secrets:
secrets_dict.update(validate_tag(item))
namespace.secrets = secrets_dict


def validate_routes(namespace):
if namespace.routes_json is not None and namespace.routes_file is not None:
raise MutuallyExclusiveArgumentError("You can only specify either --routes-json or --routes-file.")
Expand Down
2 changes: 1 addition & 1 deletion src/spring/azext_spring/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def load_command_table(self, _):

gateway_cmd_group = CliCommandType(
operations_tmpl='azext_spring.gateway#{}',
client_factory=cf_spring_20220101preview
client_factory=cf_spring_20221101preview
)

gateway_custom_domain_cmd_group = CliCommandType(
Expand Down
23 changes: 21 additions & 2 deletions src/spring/azext_spring/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def gateway_update(cmd, client, resource_group, service,
api_doc_location=None,
api_version=None,
server_url=None,
apm_types=None,
properties=None,
secrets=None,
allowed_origins=None,
allowed_methods=None,
allowed_headers=None,
Expand Down Expand Up @@ -66,18 +69,23 @@ def gateway_update(cmd, client, resource_group, service,
memory=memory or gateway.properties.resource_requests.memory
)

properties = models.GatewayProperties(
update_apm_types = apm_types if apm_types is not None else gateway.properties.apm_types
environment_variables = _update_envs(gateway.properties.environment_variables, properties, secrets)

model_properties = models.GatewayProperties(
public=assign_endpoint if assign_endpoint is not None else gateway.properties.public,
https_only=https_only if https_only is not None else gateway.properties.https_only,
sso_properties=sso_properties,
api_metadata_properties=api_metadata_properties,
cors_properties=cors_properties,
apm_types=update_apm_types,
environment_variables=environment_variables,
resource_requests=resource_requests)

sku = models.Sku(name=gateway.sku.name, tier=gateway.sku.tier,
capacity=instance_count or gateway.sku.capacity)

gateway_resource = models.GatewayResource(properties=properties, sku=sku)
gateway_resource = models.GatewayResource(properties=model_properties, sku=sku)

logger.warning(LOG_RUNNING_PROMPT)
return sdk_no_wait(no_wait, client.gateways.begin_create_or_update,
Expand Down Expand Up @@ -197,6 +205,17 @@ def _update_cors(existing, allowed_origins, allowed_methods, allowed_headers, ma
return cors


def _update_envs(existing, envs_dict, secrets_dict):
if envs_dict is None and secrets_dict is None:
return existing
envs = existing if existing is not None else models.GatewayPropertiesEnvironmentVariables()
if envs_dict is not None:
envs.properties = envs_dict
if secrets_dict is not None:
envs.secrets = secrets_dict
return envs


def _validate_route_config_not_exist(client, resource_group, service, name):
route_configs = client.gateway_route_configs.list(
resource_group, service, DEFAULT_NAME)
Expand Down
Loading