Azure 資料總管是快速及可調整的資料探索服務,以取得記錄和遙測資料。 在本文中,您將瞭解如何使用 C#、Python 或 Azure Resource Manager (ARM) 範本,為 Azure 資料總管新增叢集主體。
執行下列程式碼以新增叢集主體:
var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Directory (tenant) ID
var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Application ID
var clientSecret = "PlaceholderClientSecret"; //Client Secret
var subscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
var credentials = new ClientSecretCredential(tenantId, clientId, clientSecret);
var resourceManagementClient = new ArmClient(credentials, subscriptionId);
var resourceGroupName = "testrg";
//The cluster that is created as part of the Prerequisites
var clusterName = "mykustocluster";
var subscription = await resourceManagementClient.GetDefaultSubscriptionAsync();
var resourceGroup = (await subscription.GetResourceGroupAsync(resourceGroupName)).Value;
var cluster = (await resourceGroup.GetKustoClusterAsync(clusterName)).Value;
var clusterPrincipalAssignments = cluster.GetKustoClusterPrincipalAssignments();
var clusterPrincipalAssignmentName = "mykustoclusterprincipalassignment";
var principalId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //User email, application ID, or security group name
var role = KustoClusterPrincipalRole.AllDatabasesAdmin; //AllDatabasesAdmin or AllDatabasesViewer
var tenantIdForPrincipal = new Guid("xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx");
var principalType = KustoPrincipalAssignmentType.App; //User, App, or Group
var clusterPrincipalAssignmentData = new KustoClusterPrincipalAssignmentData
{
ClusterPrincipalId = principalId, Role = role, PrincipalType = principalType, TenantId = tenantIdForPrincipal
};
await clusterPrincipalAssignments.CreateOrUpdateAsync(
WaitUntil.Completed, clusterPrincipalAssignmentName, clusterPrincipalAssignmentData
);
|
設定 |
建議的值 |
欄位描述 |
| tenantId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
您的租用戶識別碼。 也稱為目錄標識碼。 |
| subscriptionId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
您用來建立資源的訂用帳戶標識碼。 |
| clientId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
應用程式可存取租戶內資源的客戶端識別碼。 |
| clientSecret |
PlaceholderClientSecret |
應用程式的用戶端密碼,可以存取您租用戶中的資源。 |
| resourceGroupName |
testrg |
包含叢集的資源群組名稱。 |
| 叢集名稱 (clusterName) |
mykustocluster |
您叢集的名稱。 |
| 叢集主體分配名稱 |
mykustoclusterprincipal指派 |
叢集主體資源的名稱。 |
| principalId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
主體識別碼,可以是使用者電子郵件、應用程式識別碼或安全性群組名稱。 |
| 角色 |
AllDatabasesAdmin |
叢集主體的角色,可以是 'AllDatabasesAdmin'、'AllDatabasesMonitor' 或 'AllDatabasesViewer'。 |
| tenantIdForPrincipal |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
主體的租用戶識別碼。 |
| 主要類型 |
應用程式 |
主體的類型,可以是「使用者」、「應用程式」或「群組」 |
執行下列程式碼以新增叢集主體:
from azure.mgmt.kusto import KustoManagementClient
from azure.mgmt.kusto.models import ClusterPrincipalAssignment
from azure.common.credentials import ServicePrincipalCredentials
#Directory (tenant) ID
tenant_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
#Application ID
client_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
#Client Secret
client_secret = "xxxxxxxxxxxxxx"
subscription_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
credentials = ServicePrincipalCredentials(
client_id=client_id,
secret=client_secret,
tenant=tenant_id
)
kusto_management_client = KustoManagementClient(credentials, subscription_id)
resource_group_name = "testrg"
#The cluster that is created as part of the Prerequisites
cluster_name = "mykustocluster"
principal_assignment_name = "clusterPrincipalAssignment1"
#User email, application ID, or security group name
principal_id = "xxxxxxxx"
#AllDatabasesAdmin, AllDatabasesMonitor or AllDatabasesViewer
role = "AllDatabasesAdmin"
tenant_id_for_principal = tenantId
#User, App, or Group
principal_type = "App"
#Returns an instance of LROPoller, check https://learn.microsoft.com/python/api/msrest/msrest.polling.lropoller?view=azure-python
poller = kusto_management_client.cluster_principal_assignments.create_or_update(resource_group_name=resource_group_name, cluster_name=cluster_name, principal_assignment_name= principal_assignment_name, parameters=ClusterPrincipalAssignment(principal_id=principal_id, role=role, tenant_id=tenant_id_for_principal, principal_type=principal_type))
|
設定 |
建議的值 |
欄位描述 |
| 租戶 ID |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
您的租用戶識別碼。 也稱為目錄標識碼。 |
| subscription_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
您用來建立資源的訂用帳戶標識碼。 |
| client_id (客戶識別碼) |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
應用程式可存取租戶內資源的客戶端識別碼。 |
| client_secret |
xxxxxxxxxxxxxx |
應用程式的用戶端密碼,可以存取您租用戶中的資源。 |
| 資源組名稱 |
testrg |
包含叢集的資源群組名稱。 |
| 群集名稱 |
mykustocluster |
您叢集的名稱。 |
| principal_assignment_name |
clusterPrincipalAssignment1 |
叢集主體資源的名稱。 |
| principal_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
主體識別碼,可以是使用者電子郵件、應用程式識別碼或安全性群組名稱。 |
| 角色 |
AllDatabasesAdmin |
叢集主體的角色,可以是 'AllDatabasesAdmin'、'AllDatabasesMonitor' 或 'AllDatabasesViewer'。 |
| 主體的租戶識別碼 |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
主體的租用戶識別碼。 |
| 主體類型 |
應用程式 |
主體的類型,可以是「使用者」、「應用程式」或「群組」 |
下列範例顯示用於新增叢集主體的 Azure Resource Manager 範本。 您可以使用表單,在 Azure 入口網站 中編輯和部署範本。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterPrincipalAssignmentName": {
"type": "string",
"defaultValue": "principalAssignment1",
"metadata": {
"description": "Specifies the name of the principal assignment"
}
},
"clusterName": {
"type": "string",
"defaultValue": "mykustocluster",
"metadata": {
"description": "Specifies the name of the cluster"
}
},
"principalIdForCluster": {
"type": "string",
"metadata": {
"description": "Specifies the principal id. It can be user email, application (client) ID, security group name"
}
},
"roleForClusterPrincipal": {
"type": "string",
"defaultValue": "AllDatabasesViewer",
"metadata": {
"description": "Specifies the cluster principal role. It can be 'AllDatabasesAdmin', 'AllDatabasesMonitor' or 'AllDatabasesViewer'"
}
},
"tenantIdForClusterPrincipal": {
"type": "string",
"metadata": {
"description": "Specifies the tenantId of the principal"
}
},
"principalTypeForCluster": {
"type": "string",
"defaultValue": "User",
"metadata": {
"description": "Specifies the principal type. It can be 'User', 'App', 'Group'"
}
}
},
"variables": {
},
"resources": [{
"type": "Microsoft.Kusto/Clusters/principalAssignments",
"apiVersion": "2019-11-09",
"name": "[concat(parameters('clusterName'), '/', parameters('clusterPrincipalAssignmentName'))]",
"properties": {
"principalId": "[parameters('principalIdForCluster')]",
"role": "[parameters('roleForClusterPrincipal')]",
"tenantId": "[parameters('tenantIdForClusterPrincipal')]",
"principalType": "[parameters('principalTypeForCluster')]"
}
}
]
}