Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_virtual_network_id(cmd, resource_group_name, subnet, virtual_network):
from azure.cli.core.commands.client_factory import get_subscription_id
from msrestazure.tools import is_valid_resource_id, resource_id
if not is_valid_resource_id(subnet):
if virtual_network is None:
raise CLIError("usage error: --subnet ID | --subnet NAME --vnet-name NAME")
subnet = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=resource_group_name,
namespace='Microsoft.Network', type='virtualNetworks',
name=virtual_network, child_type_1='subnets', child_name_1=subnet
)
return subnet
def validate_template_id(cmd, namespace):
from msrestazure.tools import resource_id, is_valid_resource_id
from azure.cli.core.commands.client_factory import get_subscription_id
if not is_valid_resource_id(namespace.arm_template):
if not namespace.artifact_source_name:
raise CLIError("--artifact-source-name is required when name is "
"provided for --arm-template")
namespace.arm_template = resource_id(subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.DevTestLab',
type='labs',
name=namespace.lab_name,
child_type_1='artifactSources',
child_name_1=namespace.artifact_source_name,
child_type_2='armTemplates',
child_name_2=namespace.arm_template)
location=None, sql_image_sku=None, enable_auto_patching=None, sql_management_mode="LightWeight",
day_of_week=None, maintenance_window_starting_hour=None, maintenance_window_duration=None,
enable_auto_backup=None, enable_encryption=False, retention_period=None, storage_account_url=None,
storage_access_key=None, backup_password=None, backup_system_dbs=False, backup_schedule_type=None,
full_backup_frequency=None, full_backup_start_time=None, full_backup_window_hours=None, log_backup_frequency=None,
enable_key_vault_credential=None, credential_name=None, azure_key_vault_url=None, service_principal_name=None,
service_principal_secret=None, connectivity_type=None, port=None, sql_auth_update_username=None,
sql_auth_update_password=None, sql_workload_type=None, enable_r_services=None, tags=None, sql_image_offer=None):
'''
Creates a SQL virtual machine.
'''
from azure.cli.core.commands.client_factory import get_subscription_id
subscription_id = get_subscription_id(cmd.cli_ctx)
virtual_machine_resource_id = resource_id(
subscription=subscription_id, resource_group=resource_group_name,
namespace='Microsoft.Compute', type='virtualMachines', name=sql_virtual_machine_name)
tags = tags or {}
# If customer has provided any auto_patching settings, enabling plugin should be True
if (day_of_week or maintenance_window_duration or maintenance_window_starting_hour):
enable_auto_patching = True
auto_patching_object = AutoPatchingSettings(enable=enable_auto_patching,
day_of_week=day_of_week,
maintenance_window_starting_hour=maintenance_window_starting_hour,
maintenance_window_duration=maintenance_window_duration)
# If customer has provided any auto_backup settings, enabling plugin should be True
if (enable_encryption or retention_period or storage_account_url or storage_access_key or backup_password or
def _validate_vnet_name_or_id(cmd, namespace):
SubResource = cmd.get_models('SubResource')
subscription_id = get_subscription_id(cmd.cli_ctx)
resource_group = namespace.resource_group_name
names_or_ids = getattr(namespace, dest)
ids = []
if names_or_ids == [''] or not names_or_ids:
return
for val in names_or_ids:
if not is_valid_resource_id(val):
val = resource_id(
subscription=subscription_id,
resource_group=resource_group,
namespace='Microsoft.Network', type='virtualNetworks',
name=val
)
ids.append(SubResource(id=val))
setattr(namespace, dest, ids)
usage_error = ValueError('incorrect usage: ( --subnet ID | --subnet NAME --vnet-name NAME)')
# error if vnet-name is provided without subnet
if namespace.virtual_network_name and not namespace.subnet:
raise usage_error
# determine if subnet is name or ID
is_id = is_valid_resource_id(namespace.subnet)
# error if vnet-name is provided along with a subnet ID
if is_id and namespace.virtual_network_name:
raise usage_error
if not is_id and not namespace.virtual_network_name:
raise usage_error
if not is_id:
namespace.subnet = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Network',
type='virtualNetworks',
name=namespace.virtual_network_name,
child_type_1='subnets',
child_name_1=namespace.subnet)
def validate_subnet(cmd, namespace):
from msrestazure.tools import resource_id, is_valid_resource_id
from azure.cli.core.commands.client_factory import get_subscription_id
subnet = namespace.virtual_network_subnet_id
subnet_is_id = is_valid_resource_id(subnet)
vnet = namespace.vnet_name
if (subnet_is_id and not vnet) or (not subnet and not vnet):
pass
elif subnet and not subnet_is_id and vnet:
namespace.virtual_network_subnet_id = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Network',
type='virtualNetworks',
name=vnet,
child_type_1='subnets',
child_name_1=subnet)
else:
raise CLIError('incorrect usage: [--subnet ID | --subnet NAME --vnet-name NAME]')
delattr(namespace, 'vnet_name')
def cli_redis_create_server_link(cmd, client, resource_group_name, name, server_to_link, replication_role):
redis_client = cf_redis(cmd.cli_ctx)
from azure.cli.core.commands.client_factory import get_subscription_id
from msrestazure.tools import is_valid_resource_id, resource_id
if not is_valid_resource_id(server_to_link):
server_to_link = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=resource_group_name,
namespace='Microsoft.Cache', type='Redis',
name=server_to_link
)
cache_to_link = get_cache_from_resource_id(redis_client, server_to_link)
from azure.mgmt.redis.models import RedisLinkedServerCreateParameters
params = RedisLinkedServerCreateParameters(linked_redis_cache_id=cache_to_link.id,
linked_redis_cache_location=cache_to_link.location,
server_role=replication_role)
return client.create(resource_group_name, name, cache_to_link.name, params)
def _build_resource_id(
subscription_id,
resource,
resource_group_name=None,
namespace=None,
resource_type_parent=None,
resource_type=None):
if not is_valid_resource_id(resource):
if resource_type_parent:
resource_type_parent = _remove_leading_and_trailing_slash(resource_type_parent)
resource_type = "{}/{}".format(resource_type_parent, resource_type)
resource = resource_id(
subscription=subscription_id,
resource_group=resource_group_name,
namespace=namespace,
type=resource_type,
name=resource)
return resource
'resource_group': rg,
'namespace': 'Microsoft.Compute',
'type': 'virtualMachines',
'name': namespace.source_resource
}
namespace.source_resource = resource_id(**kwargs)
if namespace.dest_resource and not is_valid_resource_id(namespace.dest_resource):
kwargs = {
'subscription': get_subscription_id(cmd.cli_ctx),
'resource_group': namespace.resource_group_name,
'namespace': 'Microsoft.Compute',
'type': 'virtualMachines',
'name': namespace.dest_resource
}
namespace.dest_resource = resource_id(**kwargs)
if not namespace.storage_account and not namespace.file_path:
raise storage_usage
if namespace.storage_path and not namespace.storage_account:
raise storage_usage
if not is_valid_resource_id(namespace.vm):
namespace.vm = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Compute',
type='virtualMachines',
name=namespace.vm)
if namespace.storage_account and not is_valid_resource_id(namespace.storage_account):
namespace.storage_account = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Storage',
type='storageAccounts',
name=namespace.storage_account)
if namespace.file_path:
file_path = namespace.file_path
if not file_path.endswith('.cap'):
raise CLIError("usage error: --file-path PATH must end with the '*.cap' extension")
file_path = file_path.replace('/', '\\')
namespace.file_path = file_path