def add_network_rule(client, resource_group_name, account_name, subnet=None, vnet_name=None, ip_address=None): # pylint: disable=unused-argument sa = client.get_properties(resource_group_name, account_name) rules = sa.properties.network_acls if rules is None: rules = default_network_acls() if subnet: from msrestazure.tools import is_valid_resource_id if not is_valid_resource_id(subnet): raise CLIError( "Expected fully qualified resource ID: got '{}'".format( subnet)) if not rules.virtual_network_rules: rules.virtual_network_rules = [] rules.virtual_network_rules.append( VirtualNetworkRule(id=subnet, ignore_missing_vnet_service_endpoint=True)) if ip_address: if not rules.ip_rules: rules.ip_rules = [] rules.ip_rules.append(IpRule(value=ip_address)) properties = CognitiveServicesAccountProperties() properties.network_acls = rules params = CognitiveServicesAccount(properties=properties) return client.update(resource_group_name, account_name, params)
def update(client, resource_group_name, account_name, sku_name=None, custom_domain=None, tags=None, api_properties=None, storage=None, encryption=None): if sku_name is None: sa = client.get_properties(resource_group_name, account_name) sku_name = sa.sku.name sku = Sku(name=sku_name) properties = CognitiveServicesAccountProperties() if api_properties is not None: api_properties = CognitiveServicesAccountApiProperties.deserialize( api_properties) properties.api_properties = api_properties if custom_domain: properties.custom_sub_domain_name = custom_domain params = CognitiveServicesAccount(sku=sku, properties=properties, tags=tags) if storage is not None: params.properties.user_owned_storage = json.loads(storage) if encryption is not None: params.properties.encryption = json.loads(encryption) return client.update(resource_group_name, account_name, params)
def create( client, resource_group_name, account_name, sku_name, kind, location, custom_domain=None, tags=None, api_properties=None, assign_identity=False, storage=None, encryption=None, yes=None): terms = 'Notice\nMicrosoft will use data you send to Bing Search Services'\ ' to improve Microsoft products and services.'\ 'Where you send personal data to these Cognitive Services, you are responsible '\ 'for obtaining sufficient consent from the data subjects.'\ 'The General Privacy and Security Terms in the Online Services Terms '\ 'do not apply to these Cognitive Services.'\ 'Please refer to the Microsoft Cognitive Services section in the Online '\ 'Services Terms'\ ' (https://www.microsoft.com/Licensing/product-licensing/products.aspx)'\ ' for details.'\ 'Microsoft offers policy controls that may be used to disable new Cognitive'\ ' Services deployments (https://docs.microsoft.com/azure/cognitive-servic'\ 'es/cognitive-services-apis-create-account).' hint = '\nPlease select' import re pattern = re.compile("^[Bb]ing\\..*$") if pattern.match(kind): if yes: logger.warning(terms) else: logger.warning(terms) option = prompt_y_n(hint) if not option: raise CLIError('Operation cancelled.') sku = Sku(name=sku_name) properties = CognitiveServicesAccountProperties() if api_properties is not None: api_properties = CognitiveServicesAccountApiProperties.deserialize(api_properties) properties.api_properties = api_properties if custom_domain: properties.custom_sub_domain_name = custom_domain params = CognitiveServicesAccount(sku=sku, kind=kind, location=location, properties=properties, tags=tags) if assign_identity: params.identity = Identity(type=IdentityType.system_assigned) if storage is not None: params.properties.user_owned_storage = json.loads(storage) if encryption is not None: params.properties.encryption = json.loads(encryption) return client.create(resource_group_name, account_name, params)
def recover(client, location, resource_group_name, account_name): properties = CognitiveServicesAccountProperties() properties.restore = True params = CognitiveServicesAccount(properties=properties) params.location = location return client.begin_create(resource_group_name, account_name, params)
def remove_network_rule(client, resource_group_name, account_name, ip_address=None, subnet=None, vnet_name=None): # pylint: disable=unused-argument """ Remove a network rule for Azure Cognitive Services account. """ sa = client.get(resource_group_name, account_name) rules = sa.properties.network_acls if rules is None: # nothing to update, but return the object return client.update(resource_group_name, account_name) if subnet: rules.virtual_network_rules = [ x for x in rules.virtual_network_rules if not x.id.endswith(subnet) ] if ip_address: rules.ip_rules = [x for x in rules.ip_rules if x.value != ip_address] properties = CognitiveServicesAccountProperties() properties.network_acls = rules params = CognitiveServicesAccount(properties=properties) return client.begin_update(resource_group_name, account_name, params)