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

[DevTestLabs] Exposing commands to manage secrets in the lab #2691

Merged
merged 9 commits into from
Apr 5, 2017
4 changes: 4 additions & 0 deletions src/command_modules/azure-cli-lab/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

+++++++++++++++++++++

* Adding commands to manage secrets in the Azure DevTest Lab.
Copy link
Member

Choose a reason for hiding this comment

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

Since these are the release notes FOR DevTestLab (instead of the CLI in general), I would recommend something like:

  • Add commands to manage secrets within a lab.


0.0.1 (2017-04-03)
+++++++++++++++++++++

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ def get_devtestlabs_virtual_network_operation(kwargs):

def get_devtestlabs_formula_operation(kwargs):
return get_devtestlabs_management_client(kwargs).formula


def get_devtestlabs_secret_operation(kwargs):
return get_devtestlabs_management_client(kwargs).secret
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
get_devtestlabs_artifact_source_operation,
get_devtestlabs_lab_operation,
get_devtestlabs_virtual_network_operation,
get_devtestlabs_formula_operation)
get_devtestlabs_formula_operation,
get_devtestlabs_secret_operation)
from azure.cli.core.sdk.util import (ServiceGroup, create_service_adapter)


Expand Down Expand Up @@ -123,3 +124,17 @@
c.command('get', 'get_resource')
c.command('list', 'list')
c.command('delete', 'delete_resource')


# Secret Operations Commands
secret_operations = create_service_adapter(
mgmt_operations_path.format('secret_operations'),
'SecretOperations')

with ServiceGroup(__name__, get_devtestlabs_secret_operation,
secret_operations) as s:
with s.group('lab secret') as c:
c.command('set', 'create_or_update_resource')
c.command('show', 'get_resource')
c.command('list', 'list')
c.command('delete', 'delete_resource')
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,18 @@
type: group
short-summary: Commands to manage formulas of a DevTest Lab.
"""
helps['lab secret'] = """
type: group
short-summary: Commands to manage secrets of a DevTest Lab.
"""
helps['lab secret set'] = """
type: command
short-summary: Sets a secret in the DevTest Lab.
parameters:
- name: --lab-name
short-summary: Name of the Lab
- name: --name -n
short-summary: Name of the secret
- name: --value
short-summary: Value of the secret
"""
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import json
from azure.cli.command_modules.lab.validators import (validate_lab_vm_create,
validate_lab_vm_list)
validate_lab_vm_list,
validate_user_name)
from azure.cli.core.commands.parameters import resource_group_name_type
from azure.cli.core.sdk.util import ParametersContext

Expand Down Expand Up @@ -69,3 +70,12 @@

with ParametersContext(command='lab formula') as c:
c.register_alias('name', ('--name', '-n'))


with ParametersContext(command='lab secret') as c:
from .sdk.devtestlabs.models.secret import Secret

c.register_alias('name', ('--name', '-n'))
c.register_alias('secret', ('--value', ), type=lambda x: Secret(value=x))
c.ignore('user_name')
c.argument('lab_name', validator=validate_user_name)
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def validate_lab_vm_list(namespace):
namespace.filters = "Properties/ownerObjectId eq '{}'".format(object_id)


def validate_user_name(namespace):
namespace.user_name = "@me"
Copy link
Member

Choose a reason for hiding this comment

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

What's this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

REST endpoint exposes user_name parameter but from the cli context we are hiding them to enable scenario that it's the user's context. so that default value for that parameter will be @me.

For that reason I've created validator to default. Let me know if that is not the way we should be defaulting.

Copy link
Member

Choose a reason for hiding this comment

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

If this command is reflecting on the SDK, then this is perfectly acceptable. If it calls into a custom command, then you can just omit that parameter in the signature and plug in "@me" where appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup all the secret commands are now just reflecting on SDK



# pylint: disable=no-member
def _validate_location(namespace):
"""
Expand Down