新增適用于 Azure Data Explorer 的叢集主體

Azure 資料總管是一項快速又可高度調整的資料探索服務,可用於處理記錄和遙測資料。 在本文中,您將瞭解如何使用 C#、Python 或 Azure Resource Manager (ARM) 範本,為 Azure Data Explorer新增叢集主體。

如需以舊版 SDK 為基礎的程式碼範例,請參閱 封存文章

必要條件

必要條件會根據用來新增主體的方法而有所不同。 選擇您慣用方法的相關索引標籤。

下列清單概述使用 C# 新增叢集主體的必要條件。

新增叢集主體

執行下列程式碼以新增叢集主體:

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 您叢集的名稱。
clusterPrincipalAssignmentName mykustoclusterprincipalassignment 叢集主體資源的名稱。
principalId xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx 主體識別碼,可以是使用者電子郵件、應用程式識別碼或安全性群組名稱。
角色 (role) AllDatabasesAdmin 叢集主體的角色,可以是 'AllDatabasesAdmin'、'AllDatabasesMonitor'或 'AllDatabasesViewer'。
tenantIdForPrincipal xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx 主體的租使用者識別碼。
principalType App 主體的類型,可以是 'User'、'App' 或 'Group'