Skip to content

Commit

Permalink
Add end to end logics for ACS, Service Registry, Gateway and API port…
Browse files Browse the repository at this point in the history
…al (#4282)

* Add end to end logics for ACS, Service Registry, Gateway and API portal

* fix linter

* fix linter

* fix linter

* Add unit tests

* Update scope

Co-authored-by: Xing Zhou <Zhou.Xing@microsoft.com>

* Update scope for ACS git repo

Co-authored-by: Xing Zhou <Zhou.Xing@microsoft.com>

* fix comment

* fix linter

* Update scope

Co-authored-by: Xing Zhou <Zhou.Xing@microsoft.com>

* fix comment

* Update _params.py

Co-authored-by: Xing Zhou <Zhou.Xing@microsoft.com>
  • Loading branch information
ninpan-ms and zhoxing-ms authored Jan 6, 2022
1 parent 07d4ad5 commit 97d7685
Show file tree
Hide file tree
Showing 16 changed files with 8,467 additions and 22 deletions.
239 changes: 239 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,242 @@
- name: Unbind an app from Service Registry.
text: az spring-cloud service-registry unbind --app MyApp -s MyService -g MyResourceGroup
"""

helps['spring-cloud application-configuration-service'] = """
type: group
short-summary: (Support 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.
"""

helps['spring-cloud application-configuration-service clear'] = """
type: command
short-summary: Reset all Application Configuration Service settings.
"""

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

helps['spring-cloud application-configuration-service git repo'] = """
type: group
short-summary: Commands to manage Application Configuration Service git repository in Azure Spring Cloud.
"""

helps['spring-cloud application-configuration-service git repo add'] = """
type: command
short-summary: Add a Git property to the Application Configuration Service settings.
examples:
- name: Add a Git property.
text: az spring-cloud application-configuration-service git repo add -s MyService -g MyResourceGroup --name MyName --patterns MyPattern --uri https://MyURI --label master
"""

helps['spring-cloud application-configuration-service git repo update'] = """
type: command
short-summary: Update an existing Git property in the Application Configuration Service settings.
examples:
- name: Update a Git property.
text: az spring-cloud application-configuration-service git repo update -s MyService -g MyResourceGroup --name MyName --patterns MyPattern
"""

helps['spring-cloud application-configuration-service git repo remove'] = """
type: command
short-summary: Delete an existing Git property from the Application Configuration Service settings.
examples:
- name: Delete a Git property.
text: az spring-cloud application-configuration-service git repo remove -s MyService -g MyResourceGroup --name MyName
"""

helps['spring-cloud application-configuration-service git repo list'] = """
type: command
short-summary: List all Git settings of Application Configuration Service.
"""

helps['spring-cloud application-configuration-service bind'] = """
type: command
short-summary: Bind an app to Application Configuration Service.
examples:
- name: Bind an app to Application Configuration Service.
text: az spring-cloud application-configuration-service bind --app MyApp -s MyService -g MyResourceGroup
"""

helps['spring-cloud application-configuration-service unbind'] = """
type: command
short-summary: Unbind an app from Application Configuration Service.
examples:
- name: Unbind an app from Application Configuration Service.
text: az spring-cloud application-configuration-service unbind --app MyApp -s MyService -g MyResourceGroup
"""

helps['spring-cloud gateway'] = """
type: group
short-summary: (Support 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 --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 remove -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: (Support 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 --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.
"""
90 changes: 82 additions & 8 deletions src/spring-cloud/azext_spring_cloud/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
validate_tracing_parameters_asc_create, validate_tracing_parameters_asc_update,
validate_app_insights_parameters, validate_instance_count, validate_java_agent_parameters,
validate_jar)
from ._validators_enterprise import only_support_enterprise
from ._validators_enterprise import (only_support_enterprise,
validate_git_uri, validate_acs_patterns,
validate_routes)
from ._app_validator import (fulfill_deployment_param, active_deployment_exist, active_deployment_exist_under_app,
ensure_not_active_deployment, validate_deloy_path, validate_deloyment_create_path,
validate_cpu, validate_memory)
Expand Down Expand Up @@ -417,12 +419,84 @@ def prepare_logs_argument(c):
help="Disable Application Insights.",
validator=validate_app_insights_parameters)

for scope in ['spring-cloud service-registry']:
with self.argument_context(scope) as c:
for scope in ['application-configuration-service', 'service-registry',
'gateway', 'api-portal']:
with self.argument_context('spring-cloud {}'.format(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)

with self.argument_context('spring-cloud service-registry unbind') as c:
c.argument('app', app_name_type, help='Name of app.', validator=validate_app_name)
for scope in ['bind', 'unbind']:
with self.argument_context('spring-cloud service-registry {}'.format(scope)) as c:
c.argument('app', app_name_type, help='Name of app.', validator=validate_app_name)

for scope in ['bind', 'unbind']:
with self.argument_context('spring-cloud application-configuration-service {}'.format(scope)) as c:
c.argument('app', app_name_type, help='Name of app.', validator=validate_app_name)

for scope in ['add', 'update']:
with self.argument_context('spring-cloud application-configuration-service git repo {}'.format(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.',
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.')
c.argument('password', help='Password of the added config.')
c.argument('host_key', help='Host key of the added config.')
c.argument('host_key_algorithm', help='Host key algorithm of the added config.')
c.argument('private_key', help='Private_key of the added config.')
c.argument('host_key_check', help='Strict host key checking of the added config which is used in SSH authentication. If false, ignore errors with host key.')

for scope in ['add', 'update', 'remove']:
with self.argument_context('spring-cloud application-configuration-service git repo {}'.format(scope)) as c:
c.argument('name', help="Required unique name to label each item of git configs.")

for scope in ['gateway update', 'api-portal update']:
with self.argument_context('spring-cloud {}'.format(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_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('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 ['gateway custom-domain bind',
'gateway custom-domain update',
'api-portal custom-domain bind',
'api-portal custom-domain update']:
with self.argument_context('spring-cloud {}'.format(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 ['create', 'update']:
with self.argument_context('spring-cloud gateway route-config {}'.format(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)
Loading

0 comments on commit 97d7685

Please sign in to comment.