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

spring cloud - custom domain - cli #1419

Merged
merged 33 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bc5f217
spring cloud - custom domain - cli
1openwindow Mar 19, 2020
118c192
add https-only parameter in app update
1openwindow Mar 20, 2020
f65b653
fix bug
1openwindow Mar 20, 2020
48ac1b5
Merge branch 'master' into master
Mar 20, 2020
09a2542
update python sdk
1openwindow Mar 25, 2020
db92af7
update python sdk
1openwindow Mar 25, 2020
783255c
Merge branch 'master' of github.com:1openwindow/azure-cli-extensions
1openwindow Mar 25, 2020
02ffff2
update version and release history
1openwindow Mar 30, 2020
c9acebb
update identity release note
1openwindow Apr 22, 2020
9537bff
uodate wording
1openwindow Apr 22, 2020
bdb656f
Merge remote-tracking branch 'upstream/master'
1openwindow Apr 22, 2020
a0da1b1
fix azdev style
1openwindow Apr 22, 2020
b27c805
fix bug
1openwindow Apr 22, 2020
6b40aed
fix comment
1openwindow Apr 22, 2020
89dc614
add example and readme
1openwindow Apr 24, 2020
ffeb6cf
change readme file extension
1openwindow Apr 24, 2020
efb83eb
add ut
1openwindow Apr 30, 2020
5a5361f
remove mis from release history
1openwindow Apr 30, 2020
a7debce
Merge remote-tracking branch 'upstream/master'
1openwindow Apr 30, 2020
4a565b3
fix conflict
1openwindow Apr 30, 2020
3a89cad
remove test yaml file
1openwindow Apr 30, 2020
34789b4
update ut
1openwindow Apr 30, 2020
a3816b3
update ut
1openwindow Apr 30, 2020
142cd15
import record only
1openwindow Apr 30, 2020
e21633a
fix style
1openwindow May 1, 2020
02560d2
update history format
1openwindow May 1, 2020
ceb5079
test rg issue
1openwindow May 1, 2020
8538feb
add rg and service name
1openwindow May 1, 2020
71a60e4
fix ut
1openwindow May 1, 2020
eec4b40
upload recording file
1openwindow May 8, 2020
a65b487
update recording file
1openwindow May 8, 2020
c6ccdc6
fix miss help
1openwindow May 8, 2020
b312ed3
add rg and service
1openwindow May 8, 2020
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
154 changes: 154 additions & 0 deletions azure-cli-extensions.pyproj

Large diffs are not rendered by default.

58 changes: 31 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,32 @@
.. :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
++++++
.. :changelog:

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
60 changes: 60 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,63 @@
type: command
short-summary: Update an Azure Cache for Redis service binding of the app.
"""

helps['spring-cloud certificate add'] = """
1openwindow marked this conversation as resolved.
Show resolved Hide resolved
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
"""

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 -o table
"""

helps['spring-cloud certificate remove'] = """
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spring-cloud certificate remove
spring-cloud app custom-domain delete

I think the verb should be consistent. I prefer "delele"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use those verbs in pair right? add/remove, create/delete, bind/unbind

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I would suggest:

spring-cloud certificate remove
spring-cloud app custom-domain unbind

type: command
short-summary: Remove a certificate in Azure Spring Cloud.
"""

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
"""

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 -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
"""

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')
1openwindow marked this conversation as resolved.
Show resolved Hide resolved
c.argument('vault_certificate_name', help='The certificate name in key vault')
1openwindow marked this conversation as resolved.
Show resolved Hide resolved

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)
1openwindow marked this conversation as resolved.
Show resolved Hide resolved


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)
1openwindow marked this conversation as resolved.
Show resolved Hide resolved
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