Skip to content

Commit

Permalink
Add scg & api portal commands (Azure#36)
Browse files Browse the repository at this point in the history
* Add scg & api portal commands

* fix comment

Co-authored-by: Yuwei Zhou <yuwzho@microsoft.com>
  • Loading branch information
ninpan-ms and yuwzho authored Dec 16, 2021
1 parent 7600a38 commit 807a275
Show file tree
Hide file tree
Showing 7 changed files with 639 additions and 4 deletions.
179 changes: 179 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@
text: az spring-cloud app-insights update -n MyService -g MyResourceGroup --disable
"""

helps['spring-cloud service-registry'] = """
type: group
short-summary: (Enterprise Tier Only) Commands to manage Service Registry in Azure Spring Cloud.
"""

helps['spring-cloud service-registry show'] = """
type: command
short-summary: Show the provisioning status and runtime status of Service Registry.
Expand All @@ -590,6 +595,11 @@
text: az spring-cloud service-registry unbind --app MyApp -s MyService -g MyResourceGroup
"""

helps['spring-cloud application-configuration-service'] = """
type: group
short-summary: (Enterprise Tier Only) Commands to manage Application Configuration Service in Azure Spring Cloud.
"""

helps['spring-cloud application-configuration-service show'] = """
type: command
short-summary: Show the provisioning status, runtime status, and settings of Application Configuration Service.
Expand Down Expand Up @@ -687,3 +697,172 @@
- name: Delete a buildpacks binding.
text: az spring-cloud build-service buildpacks-binding delete --name first-binding
"""

helps['spring-cloud gateway'] = """
type: group
short-summary: (Enterprise Tier Only) Commands to manage gateway in Azure Spring Cloud.
"""

helps['spring-cloud gateway clear'] = """
type: command
short-summary: Clear all settings of gateway.
"""

helps['spring-cloud gateway show'] = """
type: command
short-summary: Show the settings, provisioning status and runtime status of gateway.
"""

helps['spring-cloud gateway update'] = """
type: command
short-summary: Update an existing gateway properties.
examples:
- name: Update gateway property.
text: az spring-cloud gateway update -s MyService -g MyResourceGroup --name MyName --assign-endpoint true --https-only true
"""

helps['spring-cloud gateway route-config'] = """
type: group
short-summary: Commands to manage gateway route configs in Azure Spring Cloud.
"""

helps['spring-cloud gateway route-config create'] = """
type: command
short-summary: Create a gateway route config with routing rules of Json array format.
examples:
- name: Create a gateway route config targeting the app in Azure Spring Cloud.
text: az spring-cloud gateway route-config create -s MyService -g MyResourceGroup --name MyName --app-name MyApp --routes-file MyJson.json
"""

helps['spring-cloud gateway route-config update'] = """
type: command
short-summary: Update an existing gateway route config with routing rules of Json array format.
examples:
- name: Update an existing gateway route config targeting the app in Azure Spring Cloud.
text: az spring-cloud gateway route-config update -s MyService -g MyResourceGroup --name MyName --app-name MyApp --routes-file MyJson.json
"""

helps['spring-cloud gateway route-config remove'] = """
type: command
short-summary: Delete an existing gateway route config.
examples:
- name: Delete an existing gateway route config.
text: az spring-cloud gateway route-config delete -s MyService -g MyResourceGroup --name MyName
"""

helps['spring-cloud gateway route-config show'] = """
type: command
short-summary: Get an existing gateway route config.
examples:
- name: Get an existing gateway route config.
text: az spring-cloud gateway route-config show -s MyService -g MyResourceGroup --name MyName
"""

helps['spring-cloud gateway route-config list'] = """
type: command
short-summary: List all existing gateway route configs.
examples:
- name: List all existing gateway route configs.
text: az spring-cloud gateway route-config list -s MyService -g MyResourceGroup
"""

helps['spring-cloud gateway custom-domain'] = """
type: group
short-summary: Commands to manage custom domains for gateway.
"""

helps['spring-cloud gateway custom-domain bind'] = """
type: command
short-summary: Bind a custom domain with the gateway.
examples:
- name: Bind a custom domain to gateway.
text: az spring-cloud gateway custom-domain bind --domain-name MyDomainName --certificate MyCertName --service MyCluster --resource-group MyResourceGroup
"""

helps['spring-cloud gateway custom-domain show'] = """
type: command
short-summary: Show details of a custom domain.
"""

helps['spring-cloud gateway custom-domain list'] = """
type: command
short-summary: List all custom domains of the gateway.
examples:
- name: List all custom domains of the gateway.
text: az spring-cloud gateway custom-domain list --service MyCluster --resource-group MyResourceGroup
"""

helps['spring-cloud gateway custom-domain update'] = """
type: command
short-summary: Update a custom domain of the gateway.
examples:
- name: Bind custom domain with a specified certificate.
text: az spring-cloud gateway custom-domain update --domain-name MyDomainName --certificate MCertName --service MyCluster --resource-group MyResourceGroup
"""

helps['spring-cloud gateway custom-domain unbind'] = """
type: command
short-summary: Unbind a custom-domain of the gateway.
"""

helps['spring-cloud api-portal'] = """
type: group
short-summary: (Enterprise Tier Only) Commands to manage API portal in Azure Spring Cloud.
"""

helps['spring-cloud api-portal clear'] = """
type: command
short-summary: Clear all settings of API portal.
"""

helps['spring-cloud api-portal show'] = """
type: command
short-summary: Show the settings, provisioning status and runtime status of API portal.
"""

helps['spring-cloud api-portal update'] = """
type: command
short-summary: Update an existing API portal properties.
examples:
- name: Update API portal property.
text: az spring-cloud api-portal update -s MyService -g MyResourceGroup --name MyName --assign-endpoint true --https-only true
"""

helps['spring-cloud api-portal custom-domain'] = """
type: group
short-summary: Commands to manage custom domains for API portal.
"""

helps['spring-cloud api-portal custom-domain bind'] = """
type: command
short-summary: Bind a custom domain with the API portal.
examples:
- name: Bind a custom domain to API portal.
text: az spring-cloud api-portal custom-domain bind --domain-name MyDomainName --certificate MyCertName --service MyCluster --resource-group MyResourceGroup
"""

helps['spring-cloud api-portal custom-domain show'] = """
type: command
short-summary: Show details of a custom domain.
"""

helps['spring-cloud api-portal custom-domain list'] = """
type: command
short-summary: List all custom domains of the API portal.
examples:
- name: List all custom domains of the API portal.
text: az spring-cloud api-portal custom-domain list --service MyCluster --resource-group MyResourceGroup
"""

helps['spring-cloud api-portal custom-domain update'] = """
type: command
short-summary: Update a custom domain of the API portal.
examples:
- name: Bind custom domain with a specified certificate.
text: az spring-cloud api-portal custom-domain update --domain-name MyDomainName --certificate MCertName --service MyCluster --resource-group MyResourceGroup
"""

helps['spring-cloud api-portal custom-domain unbind'] = """
type: command
short-summary: Unbind a custom-domain of the API portal.
"""
55 changes: 53 additions & 2 deletions src/spring-cloud/azext_spring_cloud/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
validate_buildpacks_binding_properties,
validate_buildpacks_binding_secrets, only_support_enterprise,
validate_buildpacks_binding_not_exist, validate_buildpacks_binding_exist,
validate_git_uri, validate_acs_patterns, validate_builder,
validate_git_uri, validate_acs_patterns, validate_routes, validate_builder,
validate_build_pool_size)
from ._app_validator import (fulfill_deployment_param, active_deployment_exist, active_deployment_exist_under_app, ensure_not_active_deployment)
from ._utils import ApiType
Expand Down Expand Up @@ -412,7 +412,8 @@ 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']:
for scope in ['spring-cloud application-configuration-service', 'spring-cloud service-registry',
'spring-cloud gateway', 'spring-cloud api-portal']:
with self.argument_context(scope) as c:
c.argument('service', service_name_type, validator=only_support_enterprise)

Expand Down Expand Up @@ -450,6 +451,56 @@ def prepare_logs_argument(c):
with self.argument_context(scope) as c:
c.argument('name', help="Required unique name to label each item of git configs.")

for scope in ['spring-cloud gateway update',
'spring-cloud api-portal update']:
with self.argument_context(scope) as c:
c.argument('instance_count', type=int, help='Number of instance.')
c.argument('assign_endpoint', arg_type=get_three_state_flag(), help='If true, assign endpoint URL for direct access.')
c.argument('https_only', arg_type=get_three_state_flag(), help='If true, access endpoint via https')
c.argument('scope', arg_group='Single Sign On (SSO)', help="Comma-separated list of the specific actions applications can be allowed to do on a user's behalf.")
c.argument('client_id', arg_group='Single Sign On (SSO)', help="The public identifier for the application.")
c.argument('client_secret', arg_group='Single Sign On (SSO)', help="The secret known only to the application and the authorization server.")
c.argument('issuer_uri', arg_group='Single Sign On (SSO)', help="The URI of Issuer Identifier.")

with self.argument_context('spring-cloud gateway update') as c:
c.argument('cpu', type=str, help='CPU resource quantity. Should be 500m or number of CPU cores.')
c.argument('memory', type=str, help='Memory resource quantity. Should be 512Mi or #Gi, e.g., 1Gi, 3Gi.')
c.argument('api_title', arg_group='API metadata', help="Title describing the context of the APIs available on the Gateway instance.")
c.argument('api_description', arg_group='API metadata', help="Detailed description of the APIs available on the Gateway instance.")
c.argument('api_documentation_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('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.")
c.argument('max_age', arg_group='Cross-origin Resource Sharing (CORS)', type=int,
help="How long, in seconds, the response from a pre-flight request can be cached by clients.")
c.argument('allow_credentials', arg_group='Cross-origin Resource Sharing (CORS)', arg_type=get_three_state_flag(),
help="Whether user credentials are supported on cross-site requests.")
c.argument('exposed_headers', arg_group='Cross-origin Resource Sharing (CORS)', help="Comma-separated list of HTTP response headers to expose for cross-site requests.")

for scope in ['spring-cloud gateway custom-domain',
'spring-cloud api-portal custom-domain']:
with self.argument_context(scope) as c:
c.argument('domain_name', help='Name of custom domain.')

for scope in ['spring-cloud gateway custom-domain bind',
'spring-cloud gateway custom-domain update',
'spring-cloud api-portal custom-domain bind',
'spring-cloud api-portal custom-domain update']:
with self.argument_context(scope) as c:
c.argument('certificate', type=str, help='Certificate name in Azure Spring Cloud.')

with self.argument_context('spring-cloud gateway route-config') as c:
c.argument('name', help='Name of route config.')

for scope in ['spring-cloud gateway route-config create',
'spring-cloud gateway route-config update']:
with self.argument_context(scope) as c:
c.argument('app_name', type=str, help="The Azure Spring Cloud app name to configure the route.")
c.argument('routes_json', type=str, help="The JSON array of API routes.", validator=validate_routes)
c.argument('routes_file', type=str, help="The file path of JSON array of API routes.", validator=validate_routes)

for scope in ['spring-cloud build-service buildpacks-binding create',
'spring-cloud build-service buildpacks-binding set']:
with self.argument_context(scope) as c:
Expand Down
1 change: 1 addition & 0 deletions src/spring-cloud/azext_spring_cloud/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# pylint: disable=too-few-public-methods, unused-argument, redefined-builtin

from os import name
from re import match
from re import search
from ipaddress import ip_network
Expand Down
29 changes: 28 additions & 1 deletion src/spring-cloud/azext_spring_cloud/_validators_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from ._util_enterprise import (
is_enterprise_tier, get_client
)
from ._validators import (validate_instance_count, _parse_sku_name)
from .vendored_sdks.appplatform.v2022_01_01_preview.models import _app_platform_management_client_enums as AppPlatformEnums
from ._validators import _parse_sku_name


logger = get_logger(__name__)
Expand Down Expand Up @@ -125,6 +125,32 @@ def validate_buildpacks_binding_exist(cmd, namespace):
namespace.name)


def validate_gateway_update(namespace):
_validate_sso(namespace)
validate_cpu(namespace)
validate_memory(namespace)
validate_instance_count(namespace)


def validate_api_portal_update(namespace):
_validate_sso(namespace)
validate_instance_count(namespace)


def _validate_sso(namespace):
all_provided = namespace.scope and namespace.client_id and namespace.client_secret and namespace.issuer_uri
none_provided = namespace.scope is None and namespace.client_id is None and namespace.client_secret is None and namespace.issuer_uri is None
if not all_provided and not none_provided :
raise CLIError("Single Sign On configurations '--scope --client-id --client-secret --issuer-uri' should be all provided or none provided.")
if namespace.scope:
namespace.scope = namespace.scope.split(",")


def validate_routes(namespace):
if namespace.routes_json is not None and namespace.routes_file is not None:
raise CLIError("You can only specify either --routes-json or --routes-file.")


def validate_builder(cmd, namespace):
client = get_client(cmd)
builder = client.build_service_builder.get(namespace.resource_group,
Expand All @@ -135,6 +161,7 @@ def validate_builder(cmd, namespace):
raise CLIError('The provision state of builder {} is not succeeded, please choose a succeeded builder.'
.format(namespace.builder))


def validate_build_pool_size(namespace):
if _parse_sku_name(namespace.sku) != 'enterprise':
namespace.build_pool_size = None
Loading

0 comments on commit 807a275

Please sign in to comment.