Skip to content

Commit

Permalink
spring cloud - custom domain - cli (#1419)
Browse files Browse the repository at this point in the history
  • Loading branch information
1openwindow authored May 8, 2020
1 parent 3d46998 commit cf586cc
Show file tree
Hide file tree
Showing 22 changed files with 2,454 additions and 47 deletions.
154 changes: 154 additions & 0 deletions azure-cli-extensions.pyproj

Large diffs are not rendered by default.

56 changes: 29 additions & 27 deletions src/spring-cloud/HISTORY.rst → src/spring-cloud/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
.. :changelog:
Release History
===============

0.2.2
++++++
* Remove the limitation of max compatible cli core version

0.2.1
++++++
* Add command "az spring-cloud app logs" to replace "az spring-cloud app log tail" for log streaming.
* "az spring-cloud app log tail" will be deprecated in a future release
* Fix Python 3 and Python 2 compatible issues.

0.2.0
++++++
* Support the log streaming feature.
* Add command for log streaming: az spring-cloud app log tail.

0.1.1
++++++
* Improve the verbosity for the long running commands.
* Refine the descriptions and error messages for the command.

0.1.0
++++++
Release History
===============

0.2.3
-----
* Add command "az spring-cloud app custom-domain" and "az spring-cloud certificate" to support Custom Domain feature.

0.2.2
-----
* Remove the limitation of max compatible cli core version

0.2.1
-----
* Add command "az spring-cloud app logs" to replace "az spring-cloud app log tail" for log streaming.
* "az spring-cloud app log tail" will be deprecated in a future release
* Fix Python 3 and Python 2 compatible issues.

0.2.0
-----
* Support the log streaming feature.
* Add command for log streaming: az spring-cloud app log tail.

0.1.1
-----
* Improve the verbosity for the long running commands.
* Refine the descriptions and error messages for the command.

0.1.0
-----
* Initial release.
21 changes: 21 additions & 0 deletions src/spring-cloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Microsoft Azure CLI 'spring-cloud' Extension
==========================================

This package is for the 'spring-cloud' extension.
i.e. 'az spring-cloud'

### How to use ###
Install this extension using the below CLI command
```
az extension add --name spring-cloud
```

### Sample Commands ###
Create a service and not wait
```
az spring-cloud create -n <service name> --no-wait
```
Create a green deployment with default configuration
```
az spring-cloud app deployment create --app <app name> -n <deployment name> --jar-path <jar path>
```
5 changes: 0 additions & 5 deletions src/spring-cloud/README.rst

This file was deleted.

8 changes: 8 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ def cf_deployments(cli_ctx, *_):

def cf_bindings(cli_ctx, *_):
return cf_spring_cloud(cli_ctx).bindings


def cf_certificates(cli_ctx, *_):
return cf_spring_cloud(cli_ctx).certificates


def cf_custom_domains(cli_ctx, *_):
return cf_spring_cloud(cli_ctx).custom_domains
70 changes: 70 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,73 @@
type: command
short-summary: Update an Azure Cache for Redis service binding of the app.
"""

helps['spring-cloud certificate'] = """
type: group
short-summary: Commands to manage certificates.
"""

helps['spring-cloud certificate add'] = """
type: command
short-summary: Add a certificate in Azure Spring Cloud.
examples:
- name: Import certificate from key vault.
text: az spring-cloud certificate add --name MyCertName --vault-uri MyKeyVaultUri --vault-certificate-name MyKeyVaultCertName --service MyCluster --resource-group MyResourceGroup
"""

helps['spring-cloud certificate show'] = """
type: command
short-summary: Show a certificate in Azure Spring Cloud.
"""

helps['spring-cloud certificate list'] = """
type: command
short-summary: List all certificates in Azure Spring Cloud.
examples:
- name: List all certificates in spring cloud service.
text: az spring-cloud certificate list --service MyCluster --resource-group MyResourceGroup -o table
"""

helps['spring-cloud certificate remove'] = """
type: command
short-summary: Remove a certificate in Azure Spring Cloud.
"""

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

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

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

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

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

helps['spring-cloud app custom-domain unbind'] = """
type: command
short-summary: Unbind a custom-domain of the app.
"""
23 changes: 21 additions & 2 deletions src/spring-cloud/azext_spring_cloud/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def load_arguments(self, _):
'is_public', arg_type=get_three_state_flag(), help='If true, assign public domain', default=False)

with self.argument_context('spring-cloud app update') as c:
c.argument('is_public', arg_type=get_three_state_flag(),
help='If true, assign public domain')
c.argument('is_public', arg_type=get_three_state_flag(), help='If true, assign endpoint')
c.argument('https_only', arg_type=get_three_state_flag(), help='If true, access app via https', default=False)

for scope in ['spring-cloud app update', 'spring-cloud app start', 'spring-cloud app stop', 'spring-cloud app restart', 'spring-cloud app deploy', 'spring-cloud app scale', 'spring-cloud app set-deployment', 'spring-cloud app show-deploy-log']:
with self.argument_context(scope) as c:
Expand Down Expand Up @@ -190,3 +190,22 @@ def load_arguments(self, _):
validator=validate_app_name)
c.argument('deployment', options_list=[
'--deployment', '-d'], help='Name of an existing deployment of the app. Default to the production deployment if not specified.', validator=validate_deployment_name)

with self.argument_context('spring-cloud certificate') as c:
c.argument('service', service_name_type)
c.argument('name', name_type, help='Name of certificate.')

with self.argument_context('spring-cloud certificate add') as c:
c.argument('vault_uri', help='The key vault uri where store the certificate')
c.argument('vault_certificate_name', help='The certificate name in key vault')

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

with self.argument_context('spring-cloud app custom-domain bind') as c:
c.argument('certificate', type=str, help='Certificate name in Azure Spring Cloud.')

with self.argument_context('spring-cloud app custom-domain update') as c:
c.argument('certificate', help='Certificate name in Azure Spring Cloud.')
32 changes: 32 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,35 @@ def transform_spring_cloud_deployment_output(result):
item['Registered Instance'] = "{}/{}".format(up_number, instance_count) if isStarted else "Stopped"

return result if is_list else result[0]


def transform_spring_cloud_certificate_output(result):
is_list = isinstance(result, list)

if not is_list:
result = [result]

for item in result:
item['Certificate Name'] = item['properties']['keyVaultCertName']
item['Thumbprint'] = item['properties']['thumbprint']
item['Activate Date'] = item['properties']['activateDate'].split("T")[0]
item['Certificate Version'] = item['properties']['certVersion']
item['DNS Names'] = item['properties']['dnsNames']
item['Expiration Date'] = item['properties']['expirationDate'].split("T")[0]
item['Key Vault Uri'] = item['properties']['vaultUri']

return result if is_list else result[0]


def transform_spring_cloud_custom_domain_output(result):
is_list = isinstance(result, list)

if not is_list:
result = [result]

for item in result:
item['App Name'] = item['properties']["appName"]
item['Certificate Name'] = item['properties']['certName']
item['Thumbprint'] = item['properties']['thumbprint']

return result if is_list else result[0]
18 changes: 17 additions & 1 deletion src/spring-cloud/azext_spring_cloud/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
# pylint: disable=line-too-long
from ._client_factory import (cf_app_services, cf_spring_cloud, cf_bindings)
from ._transformers import (transform_spring_cloud_table_output,
transform_app_table_output, transform_spring_cloud_deployment_output)
transform_app_table_output,
transform_spring_cloud_deployment_output,
transform_spring_cloud_certificate_output,
transform_spring_cloud_custom_domain_output)


# pylint: disable=too-many-statements
Expand Down Expand Up @@ -81,5 +84,18 @@ def load_command_table(self, _):
g.custom_command('redis update', 'binding_redis_update')
g.custom_show_command('remove', 'binding_remove')

with self.command_group('spring-cloud certificate', client_factory=cf_spring_cloud) as g:
g.custom_command('add', 'certificate_add')
g.custom_show_command('show', 'certificate_show', table_transformer=transform_spring_cloud_certificate_output)
g.custom_command('list', 'certificate_list', table_transformer=transform_spring_cloud_certificate_output)
g.custom_command('remove', 'certificate_remove')

with self.command_group('spring-cloud app custom-domain', client_factory=cf_spring_cloud) as g:
g.custom_command('bind', 'domain_bind')
g.custom_show_command('show', 'domain_show', table_transformer=transform_spring_cloud_custom_domain_output)
g.custom_command('list', 'domain_list', table_transformer=transform_spring_cloud_custom_domain_output)
g.custom_command('update', 'domain_update')
g.custom_command('unbind', 'domain_unbind')

with self.command_group('spring-cloud', is_preview=True):
pass
65 changes: 63 additions & 2 deletions src/spring-cloud/azext_spring_cloud/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ def app_update(cmd, client, resource_group, service, name,
runtime_version=None,
jvm_options=None,
env=None,
enable_persistent_storage=None):
properties = models.AppResourceProperties(public=is_public)
enable_persistent_storage=None,
https_only=None):
properties = models.AppResourceProperties(public=is_public, https_only=https_only)
if enable_persistent_storage is True:
properties.persistent_disk = models.PersistentDisk(
size_in_gb=50, mount_path="/persistent")
Expand Down Expand Up @@ -1087,3 +1088,63 @@ def stream(self, amt=2 ** 16, decode_content=None):
response.release_conn()
except CLIError as e:
exceptions.append(e)


def certificate_add(cmd, client, resource_group, service, name, vault_uri, vault_certificate_name):
properties = models.CertificateProperties(
vault_uri=vault_uri,
key_vault_cert_name=vault_certificate_name
)
return client.certificates.create_or_update(resource_group, service, name, properties)


def certificate_show(cmd, client, resource_group, service, name):
return client.certificates.get(resource_group, service, name)


def certificate_list(cmd, client, resource_group, service):
return client.certificates.list(resource_group, service)


def certificate_remove(cmd, client, resource_group, service, name):
client.certificates.get(resource_group, service, name)
return client.certificates.delete(resource_group, service, name)


def domain_bind(cmd, client, resource_group, service, app,
domain_name,
certificate=None):
properties = models.CustomDomainProperties()
if certificate is not None:
certificate_response = client.certificates.get(resource_group, service, certificate)
properties = models.CustomDomainProperties(
thumbprint=certificate_response.properties.thumbprint,
cert_name=certificate
)
return client.custom_domains.create_or_update(resource_group, service, app, domain_name, properties)


def domain_show(cmd, client, resource_group, service, app, domain_name):
return client.custom_domains.get(resource_group, service, app, domain_name)


def domain_list(cmd, client, resource_group, service, app):
return client.custom_domains.list(resource_group, service, app)


def domain_update(cmd, client, resource_group, service, app,
domain_name,
certificate=None):
properties = models.CustomDomainProperties()
if certificate is not None:
certificate_response = client.certificates.get(resource_group, service, certificate)
properties = models.CustomDomainProperties(
thumbprint=certificate_response.properties.thumbprint,
cert_name=certificate
)
return client.custom_domains.create_or_update(resource_group, service, app, domain_name, properties)


def domain_unbind(cmd, client, resource_group, service, app, domain_name):
client.custom_domains.get(resource_group, service, app, domain_name)
return client.custom_domains.delete(resource_group, service, app, domain_name)
Loading

0 comments on commit cf586cc

Please sign in to comment.