Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ninpan-ms committed Jan 5, 2023
1 parent c9c3c3c commit b1bcc01
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 74 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.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
7 changes: 7 additions & 0 deletions src/spring/azext_spring/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,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: [\"ApplicationInsights\", \"AppDynamics\", \"Dynatrace\", \"NewRelic\", \"ElasticAPM\"].")
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
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 @@ -191,6 +191,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 +218,33 @@ 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
allowedApmTypes = ["ApplicationInsights", "AppDynamics", "Dynatrace", "NewRelic", "ElasticAPM"]
for type in namespace.apm_types:
if (type not in allowedApmTypes):
raise InvalidArgumentValueError("Allowed APM types are \"ApplicationInsights\", \"AppDynamics\", \"Dynatrace\", \"NewRelic\", \"ElasticAPM\".")


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

0 comments on commit b1bcc01

Please sign in to comment.