Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def __init__(self, cli_ctx=None):
hardware_security_modules_custom = CliCommandType(
operations_tmpl='azext_hardware_security_modules.custom#{}',
client_factory=cf_hardware_security_modules)
super(AzureDedicatedHSMResourceProviderCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=hardware_security_modules_custom)
parent = super(AzureDedicatedHSMResourceProviderCommandsLoader, self)
parent.__init__(cli_ctx=cli_ctx, custom_command_type=hardware_security_modules_custom)

def load_command_table(self, args):
from azext_hardware_security_modules.generated.commands import load_command_table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,29 @@
helps['hardware-security-modules dedicated-hsm create'] = """
type: command
short-summary: Create or Update a dedicated HSM in the specified subscription.
parameters:
- name: --network-profile-subnet
short-summary: Specifies the identifier of the subnet.
long-summary: |
Usage: --network-profile-subnet id=XX

id: The ARM resource id in the form of /subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/.\
..
- name: --network-profile-network-interfaces
short-summary: Specifies the list of resource Ids for the network interfaces associated with the dedicated HSM.
long-summary: |
Usage: --network-profile-network-interfaces private-ip-address=XX

private-ip-address: Private Ip address of the interface

Multiple actions can be specified by using more than one --network-profile-network-interfaces argument.
examples:
- name: Create a new or update an existing dedicated HSM
text: |-
az hardware-security-modules dedicated-hsm create --name "hsm1" --location "westus" --network-profile-ne\
twork-interfaces private-ip-address="1.0.0.1" --network-profile-subnet id="/subscriptions/00000000-0000-0000-0000-00000\
0000000/resourceGroups/hsm-group/providers/Microsoft.Network/virtualNetworks/stamp01/subnets/stamp01" --stamp-id "stamp\
01" --sku name="SafeNet Luna Network HSM A790" --tags Dept="hsm" Environment="dogfood" --resource-group "hsm-group"
01" --tags Dept="hsm" Environment="dogfood" --resource-group "hsm-group"
"""

helps['hardware-security-modules dedicated-hsm update'] = """
Expand All @@ -65,3 +81,22 @@
text: |-
az hardware-security-modules dedicated-hsm delete --name "hsm1" --resource-group "hsm-group"
"""

helps['hardware-security-modules dedicated-hsm wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of the hardware-security-modules dedicated-hsm is\
met.
examples:
- name: Pause executing next line of CLI script until the hardware-security-modules dedicated-hsm is successfully\
created.
text: |-
az hardware-security-modules dedicated-hsm wait --name "hsm1" --resource-group "hsm-group" --created
- name: Pause executing next line of CLI script until the hardware-security-modules dedicated-hsm is successfully\
updated.
text: |-
az hardware-security-modules dedicated-hsm wait --name "hsm1" --resource-group "hsm-group" --updated
- name: Pause executing next line of CLI script until the hardware-security-modules dedicated-hsm is successfully\
deleted.
text: |-
az hardware-security-modules dedicated-hsm wait --name "hsm1" --resource-group "hsm-group" --deleted
"""
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
# pylint: disable=too-many-lines
# pylint: disable=too-many-statements

from knack.arguments import CLIArgumentType
from azure.cli.core.commands.parameters import (
tags_type,
resource_group_name_type,
get_location_type
)
from azure.cli.core.commands.validators import get_default_location_from_resource_group
from azext_hardware_security_modules.action import (
AddSku,
AddNetworkProfileSubnet,
AddNetworkProfileNetworkInterfaces
)
Expand All @@ -32,28 +30,30 @@ def load_arguments(self, _):

with self.argument_context('hardware-security-modules dedicated-hsm show') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('name', help='The name of the dedicated HSM.')
c.argument('name', help='The name of the dedicated HSM.', id_part='name')

with self.argument_context('hardware-security-modules dedicated-hsm create') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('name', help='Name of the dedicated Hsm')
c.argument('location', arg_type=get_location_type(self.cli_ctx),
validator=get_default_location_from_resource_group)
c.argument('sku', action=AddSku, nargs='+', help='SKU details Expect value: KEY1=VALUE1 KEY2=VALUE2 ...')
c.argument('zones', nargs='+', help='The Dedicated Hsm zones. Expected value: json-string/@json-file.')
c.argument('zones', nargs='+', help='The Dedicated Hsm zones.')
c.argument('tags', tags_type)
c.argument('stamp_id', help='This field will be used when RP does not support Availability zones.')
c.argument('network_profile_subnet', action=AddNetworkProfileSubnet, nargs='+', help='Specifies the identifier '
'of the subnet. Expect value: id=xx.')
'of the subnet.')
c.argument('network_profile_network_interfaces', action=AddNetworkProfileNetworkInterfaces, nargs='+', help='Sp'
'ecifies the list of resource Ids for the network interfaces associated with the dedicated HSM. Expe'
'ct value: private-ip-address=xx.')
'ecifies the list of resource Ids for the network interfaces associated with the dedicated HSM.')

with self.argument_context('hardware-security-modules dedicated-hsm update') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('name', help='Name of the dedicated HSM')
c.argument('name', help='Name of the dedicated HSM', id_part='name')
c.argument('tags', tags_type)

with self.argument_context('hardware-security-modules dedicated-hsm delete') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('name', help='The name of the dedicated HSM to delete')
c.argument('name', help='The name of the dedicated HSM to delete', id_part='name')

with self.argument_context('hardware-security-modules dedicated-hsm wait') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('name', help='The name of the dedicated HSM.', id_part='name')
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

VERSION = "2019-05-01T00:00:00.000Z"
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,11 @@
from collections import defaultdict


class AddSku(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.sku = action


def get_action(self, values, option_string): # pylint: disable=no-self-use
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
return d


class AddNetworkProfileSubnet(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.network_profile_subnet = action


def get_action(self, values, option_string): # pylint: disable=no-self-use
try:
properties = defaultdict(list)
Expand All @@ -63,7 +41,6 @@ def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
super(AddNetworkProfileNetworkInterfaces, self).__call__(parser, namespace, action, option_string)


def get_action(self, values, option_string): # pylint: disable=no-self-use
try:
properties = defaultdict(list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ def load_command_table(self, _):
g.custom_command('create', 'hardware_security_modules_dedicated_hsm_create', supports_no_wait=True)
g.custom_command('update', 'hardware_security_modules_dedicated_hsm_update', supports_no_wait=True)
g.custom_command('delete', 'hardware_security_modules_dedicated_hsm_delete', supports_no_wait=True)
g.wait_command('wait')
g.custom_wait_command('wait', 'hardware_security_modules_dedicated_hsm_show')
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,65 @@
# pylint: disable=too-many-lines

import json
from azure.cli.core.util import sdk_no_wait


def hardware_security_modules_dedicated_hsm_list(cmd, client,
def hardware_security_modules_dedicated_hsm_list(client,
resource_group_name=None,
top=None):
if resource_group_name is not None:
if resource_group_name:
return client.list_by_resource_group(resource_group_name=resource_group_name,
top=top)
return client.list_by_subscription(top=top)


def hardware_security_modules_dedicated_hsm_show(cmd, client,
def hardware_security_modules_dedicated_hsm_show(client,
resource_group_name,
name):
return client.get(resource_group_name=resource_group_name,
name=name)


def hardware_security_modules_dedicated_hsm_create(cmd, client,
def hardware_security_modules_dedicated_hsm_create(client,
resource_group_name,
name,
location,
sku=None,
zones=None,
tags=None,
stamp_id=None,
network_profile_subnet=None,
network_profile_network_interfaces=None):
if isinstance(zones, str):
zones = json.loads(zones)
return client.begin_create_or_update(resource_group_name=resource_group_name,
name=name,
location=location,
sku=sku,
zones=zones,
tags=tags,
stamp_id=stamp_id,
subnet=network_profile_subnet,
network_interfaces=network_profile_network_interfaces)
network_profile_network_interfaces=None,
no_wait=False):
return sdk_no_wait(no_wait,
client.begin_create_or_update,
resource_group_name=resource_group_name,
name=name,
location=location,
sku=json.loads("{\"name\": \"SafeNet Luna Network HSM A790\"}"),
zones=zones,
tags=tags,
stamp_id=stamp_id,
subnet=network_profile_subnet,
network_interfaces=network_profile_network_interfaces)


def hardware_security_modules_dedicated_hsm_update(cmd, client,
def hardware_security_modules_dedicated_hsm_update(client,
resource_group_name,
name,
tags=None):
return client.begin_update(resource_group_name=resource_group_name,
name=name,
tags=tags)
tags=None,
no_wait=False):
return sdk_no_wait(no_wait,
client.begin_update,
resource_group_name=resource_group_name,
name=name,
tags=tags)


def hardware_security_modules_dedicated_hsm_delete(cmd, client,
def hardware_security_modules_dedicated_hsm_delete(client,
resource_group_name,
name):
return client.begin_delete(resource_group_name=resource_group_name,
name=name)
name,
no_wait=False):
return sdk_no_wait(no_wait,
client.begin_delete,
resource_group_name=resource_group_name,
name=name)
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
# --------------------------------------------------------------------------
import inspect
import os
import sys
import traceback
from azure.core.exceptions import AzureError
from azure.cli.testsdk.exceptions import CliTestError, CliExecutionError, JMESPathCheckAssertionError


__path__ = __import__('pkgutil').extend_path(__path__, __name__)
exceptions = []


def try_manual(func):
Expand All @@ -34,16 +39,33 @@ def get_func_to_call():
func_to_call = func
try:
func_to_call = import_manual_function(func)
print("Found manual override for {}(...)".format(func.__name__))
except (ImportError, AttributeError):
pass
return func_to_call

def wrapper(*args, **kwargs):
func_to_call = get_func_to_call()
print("running {}()...".format(func.__name__))
return func_to_call(*args, **kwargs)
try:
return func_to_call(*args, **kwargs)
except (AssertionError, AzureError, CliTestError, CliExecutionError, JMESPathCheckAssertionError) as e:
print("--------------------------------------")
print("step exception: ", e)
print("--------------------------------------", file=sys.stderr)
print("step exception in {}: {}".format(func.__name__, e), file=sys.stderr)
traceback.print_exc()
exceptions.append((func.__name__, sys.exc_info()))

if inspect.isclass(func):
return get_func_to_call()
else:
return wrapper
return wrapper


def raise_if():
if exceptions:
if len(exceptions) <= 1:
raise exceptions[0][1][1]
message = "{}\nFollowed with exceptions in other steps:\n".format(str(exceptions[0][1][1]))
message += "\n".join(["{}: {}".format(h[0], h[1][1]) for h in exceptions[1:]])
raise exceptions[0][1][0](message).with_traceback(exceptions[0][1][2])
Loading