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 validators and table output #19

Merged
merged 2 commits into from
Aug 13, 2021
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
12 changes: 9 additions & 3 deletions src/spring-cloud/azext_spring_cloud/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
validate_vnet, validate_vnet_required_parameters, validate_node_resource_group,
validate_tracing_parameters, validate_app_insights_parameters, validate_java_agent_parameters,
validate_instance_count)
from ._validators_enterprise import (validate_config_file_patterns, validate_cpu, validate_memory)
from ._validators_enterprise import (only_support_enterprise, validate_config_file_patterns, validate_cpu, validate_memory,
validate_git_uri, validate_acs_patterns)
from ._utils import ApiType

from .vendored_sdks.appplatform.v2020_07_01.models import RuntimeVersion, TestKeyType
Expand Down Expand Up @@ -283,6 +284,10 @@ def prepare_logs_argument(c):
help="Disable Application Insights.",
validator=validate_app_insights_parameters)

for scope in ['spring-cloud application-configuration-service', 'spring-cloud service-registry']:
with self.argument_context(scope) as c:
c.argument('service', service_name_type, validator=only_support_enterprise)

with self.argument_context('spring-cloud service-registry bind') as c:
c.argument('app', app_name_type, help='Name of app.', validator=validate_app_name)

Expand All @@ -299,8 +304,9 @@ def prepare_logs_argument(c):
'spring-cloud application-configuration-service git repo update']:
with self.argument_context(scope) as c:
c.argument('patterns',
help="Required patterns used to search in Git repositories. For each pattern, use format like {application} or {application}/{profile} instead of {application}-{profile}.yml, and separate them by comma."),
c.argument('uri', help="Required Git URI."),
help="Required patterns used to search in Git repositories. For each pattern, use format like {application} or {application}/{profile} instead of {application}-{profile}.yml, and separate them by comma.",
validator=validate_acs_patterns),
c.argument('uri', help="Required Git URI.", validator=validate_git_uri),
c.argument('label', help="Required branch name to search in the Git repository."),
c.argument('search_paths', help='search_paths of the added config, use , as delimiter for multiple paths.')
c.argument('username', help='Username of the added config.')
Expand Down
5 changes: 5 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def transform_app_table_output(result):
item['Persistent Storage'] = "{}/{} Gb".format(
persistentStorage['usedInGb'], persistentStorage['sizeInGb']) if persistentStorage['sizeInGb'] else "-"

if 'addonConfigs' in item['properties']:
addon = item['properties']['addonConfigs']
item['Bind Service Registry'] = addon['ServiceRegistry']['enabled'] if addon.get('ServiceRegistry') else False
item['Bind Application Configuration Service'] = addon['ApplicationConfigurationService']['enabled'] if addon.get('ApplicationConfigurationService') else False

return result if is_list else result[0]


Expand Down
25 changes: 19 additions & 6 deletions src/spring-cloud/azext_spring_cloud/_validators_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,27 @@ def validate_memory(namespace):
namespace.memory = validate_and_normalize_memory(namespace.memory)


def validate_config_file_patterns(namespace):
if not namespace.config_file_patterns:
def validate_git_uri(namespace):
uri = namespace.uri
if uri and (uri.startswith("https://") or uri.startswith("git@")):
return
pattern_list = namespace.config_file_patterns.split(',')
raise CLIError("Git URI should start with \"https://\" or \"git@\"")


def validate_config_file_patterns(namespace):
_validate_patterns(namespace.config_file_patterns)


def validate_acs_patterns(namespace):
_validate_patterns(namespace.patterns)


def _validate_patterns(patterns):
pattern_list = patterns.split(',')
invalid_list = [p for p in pattern_list if not _is_valid_pattern(p)]
if invalid_list:
logger.warning('Config file patterns "%s" are invalid.', ','.join(invalid_list))
raise CLIError('--config-file-patterns should be the collection of patterns separated by comma, each pattern in the format of \'application\' or \'application/profile\'')
if len(invalid_list) > 0:
logger.warning("Patterns '%s' are invalid.", ','.join(invalid_list))
raise CLIError("Patterns should be the collection of patterns separated by comma, each pattern in the format of 'application' or 'application/profile'")


def _is_valid_pattern(pattern):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def application_configuration_service_git_list(cmd, client, service, resource_gr


def application_configuration_service_bind(cmd, client, service, resource_group, app):
_acs_bind_or_unbind_app(cmd, client, service, resource_group, app, True)
return _acs_bind_or_unbind_app(cmd, client, service, resource_group, app, True)


def application_configuration_service_unbind(cmd, client, service, resource_group, app):
_acs_bind_or_unbind_app(cmd, client, service, resource_group, app, False)
return _acs_bind_or_unbind_app(cmd, client, service, resource_group, app, False)


def _acs_bind_or_unbind_app(cmd, client, service, resource_group, app_name, enabled):
Expand Down