Exemplo n.º 1
0
def iot_dps_access_policy_create(client,
                                 dps_name,
                                 resource_group_name,
                                 access_policy_name,
                                 rights,
                                 primary_key=None,
                                 secondary_key=None):
    dps_access_policies = []
    dps_access_policies.extend(
        iot_dps_access_policy_list(client, dps_name, resource_group_name))
    if _is_policy_existed(dps_access_policies, access_policy_name):
        raise CLIError(
            "Access policy {0} already existed.".format(access_policy_name))

    access_policy_rights = _convert_rights_to_access_rights(rights)
    dps_access_policies.append(
        SharedAccessSignatureAuthorizationRuleAccessRightsDescription(
            access_policy_name, access_policy_rights, primary_key,
            secondary_key))

    dps = iot_dps_get(client, dps_name, resource_group_name)
    dps_property = IotDpsPropertiesDescription(
        None, None, dps.properties.iot_hubs, dps.properties.allocation_policy,
        dps_access_policies)
    dps_description = ProvisioningServiceDescription(dps.location,
                                                     dps_property, dps.sku)

    client.iot_dps_resource.create_or_update(resource_group_name, dps_name,
                                             dps_description)
    return iot_dps_access_policy_get(client, dps_name, resource_group_name,
                                     access_policy_name)
Exemplo n.º 2
0
def iot_dps_access_policy_create(cmd, client, dps_name, resource_group_name, access_policy_name, rights, primary_key=None, secondary_key=None, no_wait=False):
    dps_access_policies = []
    dps_access_policies.extend(iot_dps_access_policy_list(client, dps_name, resource_group_name))
    if _is_policy_existed(dps_access_policies, access_policy_name):
        raise CLIError("Access policy {0} already existed.".format(access_policy_name))

    access_policy_rights = _convert_rights_to_access_rights(rights)
    dps_access_policies.append(SharedAccessSignatureAuthorizationRuleAccessRightsDescription(
        key_name=access_policy_name, rights=access_policy_rights, primary_key=primary_key, secondary_key=secondary_key))

    dps = iot_dps_get(client, dps_name, resource_group_name)
    dps_property = IotDpsPropertiesDescription(iot_hubs=dps.properties.iot_hubs,
                                               allocation_policy=dps.properties.allocation_policy,
                                               authorization_policies=dps_access_policies)
    dps_description = ProvisioningServiceDescription(location=dps.location, properties=dps_property, sku=dps.sku)

    if no_wait:
        return client.iot_dps_resource.create_or_update(resource_group_name, dps_name, dps_description)
    LongRunningOperation(cmd.cli_ctx)(client.iot_dps_resource.create_or_update(resource_group_name, dps_name, dps_description))
    return iot_dps_access_policy_get(client, dps_name, resource_group_name, access_policy_name)