Example #1
0
def identity_remove(client, resource_group_name, account_name):
    """
    Remove the identity for Azure Cognitive Services account.
    """
    params = CognitiveServicesAccount()
    params.identity = Identity(type=IdentityType.none)
    client.begin_update(resource_group_name, account_name, params)
Example #2
0
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)
Example #3
0
def identity_assign(client, resource_group_name, account_name):
    """
    Assign the identity for Azure Cognitive Services account.
    """
    params = CognitiveServicesAccount()
    params.identity = Identity(type=IdentityType.system_assigned)
    sa = client.begin_update(resource_group_name, account_name,
                             params).result()
    return sa.identity if sa.identity else {}
def create_resource(resource_name, kind, sku_name, location):
    print("Creating resource: " + resource_name + "...")

    # NOTE If you do not want to use a custom subdomain name, remove the customSubDomainName
    # property from the properties object.
    parameters = Account(sku=Sku(name=sku_name),
                         kind=kind,
                         location=location,
                         properties={'custom_sub_domain_name': subdomain_name})

    poller = client.accounts.begin_create(resource_group_name, resource_name,
                                          parameters)
    while (False == poller.done()):
        print("Waiting {wait_time} seconds for operation to finish.".format(
            wait_time=wait_time))
        time.sleep(wait_time)
# This will raise an exception if the server responded with an error.
    result = poller.result()

    print("Resource created.")
    print()
    print("ID: " + result.id)
    print("Name: " + result.name)
    print("Type: " + result.type)
    print()
Example #5
0
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).'
    terms_not_police = 'Notice\n' \
                       'I certify that use of this service is not by or for a police department in the United States.'
    hint = 'Please 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.')
    if kind.lower() == 'face' or kind.lower() == 'cognitiveservices':
        if yes:
            logger.warning(terms_not_police)
        else:
            logger.warning(terms_not_police)
            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.begin_create(resource_group_name, account_name, params)