クイック スタート: Microsoft Purview データ共有 .NET SDK でデータを共有および受信する

重要

この機能は現在プレビューの段階です。 Microsoft Azure プレビューの補足使用条件には、ベータ版、プレビュー版、または一般公開されていない Azure 機能に適用される追加の法的条件が含まれています。

このクイック スタートでは、.NET SDK を使用してデータを共有し、Azure Data Lake Storage (ADLS Gen2) または BLOB ストレージ アカウントから共有を受け取ります。 この記事には、Microsoft Purview データ共有を使用して共有を作成、承認、管理できるコード スニペットが含まれています。

データ共有のしくみの概要については、この短いデモをwatchします。

注:

この機能は 2023 年 2 月に更新され、Microsoft Purview でデータ共有を表示および管理するために必要な SDK とアクセス許可が変更されました。

  • Microsoft Purview で SDK を使用して共有を作成および管理するためのアクセス許可は不要になりました。 (データを共有するために Microsoft Purview ガバナンス ポータルを使用するには、閲覧者のアクセス許可が必要です)。
  • ストレージ アカウントに対するアクセス許可は引き続き必要です。

更新された SDK を使用するには、更新された NuGet パッケージ更新されたコード スニペット を参照してください。

前提条件

Microsoft Purview の前提条件

  • Microsoft Purview アカウント。 また、データ プロバイダー用とデータ コンシューマー用の 2 つの Microsoft Purview アカウントを使用して、両方のシナリオをテストすることもできます。
  • 招待の送信に使用できる受信者の Azure サインインメール アドレス。 受信者のメール エイリアスは機能しません。

Azure Storage アカウントの前提条件

  • Azure サブスクリプションは 、AllowDataSharing プレビュー機能に登録する必要があります。 Azure portalまたは PowerShell を使用して、次の手順に従います。

    1. Azure portalで、ソースとターゲットのストレージ アカウントの作成に使用する Azure サブスクリプションを選択します。
    2. 左側のメニューで、[設定] の [プレビュー機能] を選択します。
    3. [ AllowDataSharing and Register] を 選択します
    4. [プレビュー機能] 画面を更新して、[状態] が [登録済み] であることを確認します。 登録が完了するまでに 15 分から 1 時間かかる場合があります。
    5. さらに、米国東部、米国東部 2、北ヨーロッパ、米国中南部、米国中西部、西ヨーロッパ、米国西部、米国西部 2、米国西部 3 のストレージ アカウントにデータ共有を使用するには、AllowDataSharingInHeroRegion と Register を選択します。

    詳細については、「 プレビュー機能の登録」を参照してください。

    RegistrationState登録する必要があります。 登録が完了するまでに 15 分から 1 時間かかる場合があります。 詳細については、「 プレビュー機能の登録」を参照してください。

    注:

    サポートされているストレージ アカウントの構成を次に示します。

    • Azure リージョン: カナダ中部、カナダ東部、英国南部、英国西部、オーストラリア東部、東日本、韓国南部、南アフリカ北部
    • その他の Azure リージョン: 米国東部、米国東部 2、北ヨーロッパ、米国中南部、米国中西部、西ヨーロッパ、米国西部、米国西部 2、米国西部 3
    • パフォーマンス: 標準
    • 冗長性オプション: LRS
  • 登録手順が完了 した後に作成された ソースとターゲットのストレージ アカウント。 両方のストレージ アカウントは、互いに同じ Azure リージョンに存在する必要があります。 両方のストレージ アカウントは、ADLS Gen2 または Blob Storage アカウントである必要があります。 ストレージ アカウントは、Microsoft Purview アカウントとは異なる Azure リージョンに存在できます。

  • ストレージ SDK、PowerShell、CLI、Azure Storage Explorerの最新バージョン。 Storage REST API のバージョンは、2020 年 2 月以降である必要があります。

  • ストレージ アカウントは、共有を送受信するコレクションに登録する必要があります。 1 つの Microsoft Purview アカウントを使用している場合は、2 つの異なるコレクションまたは同じコレクションを使用できます。 登録手順については、 ADLS Gen2 または Blob Storage のデータ ソース ページを参照してください。

  • ソースまたはターゲット のストレージ アカウントが Microsoft Purview アカウントのサブスクリプションとは異なる Azure サブスクリプションにある場合、Microsoft.Purview リソース プロバイダーは、資産を追加する共有プロバイダーまたは共有コンシューマー マッピング資産の作成時にデータ ストアが配置されている Azure サブスクリプションに自動的に登録されます。ユーザーがリソース プロバイダーの /register/action 操作を実行するアクセス許可を持っている場合 のみです 。 アクセス許可は、共同作成者ロールと所有者ロールに含まれています。

    注:

    この登録は、Azure サブスクリプション内のストレージ アカウントにデータを共有または受信するときに初めて必要になります。

必要な役割

データの共有と共有の受信に必要なロールを次に示します。

Azure Storage アカウント ロール Microsoft Purview コレクション ロール
データ プロバイダー 次のいずれかのロール:
  • Owner
  • ストレージ BLOB データ所有者
データ リーダー
データ コンシューマー 次のいずれかのロール:
  • 共同作成者
  • Owner
  • ストレージ BLOB データ共同作成者
  • ストレージ BLOB データ所有者
データ リーダー

注:

Microsoft Purview アカウントを作成した場合、ルート コレクションにすべてのロールが自動的に割り当てられます。 Microsoft Purview のコレクションとロールの詳細については、「Microsoft Purview のアクセス許可 」を参照してください。

Visual Studio

この記事のチュートリアルでは、Visual Studio 2022 を使用します。 Visual Studio 2013、2015、2017、または 2019 の手順は若干異なる場合があります。

Azure .NET SDK

マシンに Azure .NET SDK をダウンロードしてインストールします。

サービス プリンシパルを使用する

このチュートリアルのコード スニペットでは、独自の資格情報を使用するか、サービス プリンシパルを使用して認証できます。 サービス プリンシパルを設定するには、次の手順に従います。

  1. [ Azure Active Directory アプリケーションの作成] で、このチュートリアルで作成する .NET アプリケーションを表すアプリケーションを作成します。 サインオン URL には、記事 (https://contoso.org/exampleapp) に示すようにダミー URL を指定できます。

  2. [ サインインの値を取得する] で、 アプリケーション IDテナント IDおよびオブジェクト ID を取得し、このチュートリアルの後半で使用するこれらの値をメモします。

  3. [ 証明書とシークレット]認証キーを取得し、このチュートリアルの後半で使用するこの値をメモします。

  4. アプリケーションを次のロールに割り当てます。

    User Azure Storage アカウント ロール Microsoft Purview コレクション ロール
    データ プロバイダー 次のいずれかのロール:
    • Owner
    • Blob Storage データ所有者
    Data Share共同作成者
    データ コンシューマー 次のいずれかのロール:
    • 共同作成者
    • Owner
    • ストレージ BLOB データ共同作成者
    • Blob Storage データ所有者
    Data Share共同作成者

Visual Studio プロジェクトを作成する

次に、Visual Studio で C# .NET コンソール アプリケーションを作成します。

  1. Visual Studio を起動します
  2. [スタート] ウィンドウで、[ 新しいプロジェクト>の作成] [コンソール アプリ] を選択します。 .NET バージョン 6.0 以降が必要です。
  3. [ プロジェクト名] に「 PurviewDataSharingQuickStart」と入力します。
  4. [ 作成] を 選択してプロジェクトを作成します。

NuGet パッケージをインストールする

  1. [ツール]>[NuGet パッケージ マネージャー パッケージ マネージャー> コンソール] の順に選択します

  2. パッケージ管理コンソールで、このページに表示されている .NET cli add package コマンドを実行して、NuGet パッケージ Microsoft.Azure.Analytics.Purview.Sharing NuGet パッケージを追加します。

  3. [ パッケージ マネージャー コンソール ] ウィンドウで、次のコマンドを実行してパッケージをインストールします。

    Install-Package Azure.Analytics.Purview.Sharing -IncludePrerelease
    Install-Package Azure.Identity
    

    ヒント

    "プロジェクトが見つかりませんでした.." というエラーが発生した場合。これらのコマンドを試みると、プロジェクト内のフォルダー レベルを下に移動するだけで済む場合があります。 コマンドdirを試してディレクトリ内のフォルダーを一覧表示し、'プロジェクト フォルダー>の cd <名' を使用して、レベルを下げてプロジェクト フォルダーに移動します。 次に、もう一度やり直してください。

送信された共有を作成する

このスクリプトは、内部ユーザーまたは外部ユーザーに送信できるデータ共有を作成します。 これを使用するには、次の変数を必ず入力してください。

  • SenderTenantId - 送信者の ID の Azure テナント ID
  • SenderPurviewAccountName - データの送信元となる Microsoft Purview アカウントの名前。
  • ShareName - 送信された共有の表示名。
  • ShareDescription - (省略可能) 送信された共有の説明。
  • SenderStorageKind - BlobAccount または AdlsGen2Account のいずれか。
  • SenderStorageResourceId - データの送信元となる ストレージ アカウントのリソース ID
  • SenderStorageContainer - 共有するデータが格納されるコンテナーの名前。
  • SenderPathToShare - 共有するデータへのファイル/フォルダー パス。
  • UseServiceTokenCredentials - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、これを true に設定 します
  • SenderClientId - (省略可能) サービス プリンシパルを使用して共有を作成する場合、これはサービス プリンシパルのアプリケーション (クライアント) ID です。
  • SenderClientSecret - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、クライアント シークレット/認証キーを追加します。
  • SentShareID - (省略可能) このオプションは GUID である必要があり、現在の値によって生成されますが、必要に応じて別の値に置き換えることができます。
  • ReceiverVisiblePath - (省略可能) 受信者に表示される共有の名前。 現在、GUID に設定されていますが、GUID は必要ありません。
  • SenderPurviewEndPoint - 従来の Microsoft purview エクスペリエンスを使用している場合は、 を使用 $"https://{SenderPurviewAccountName}.purview.azure.com"します。 新しい Microsoft Purview エクスペリエンスを使用している場合は、 https://api.purview-service.microsoft.com/
using Azure;
using Azure.Analytics.Purview.Sharing;
using Azure.Core;
using Azure.Identity;
using System.ComponentModel;

public static class PurviewDataSharingQuickStart
{
    // [REQUIRED INPUTS] Set To Actual Values.
    private static string SenderTenantId = "<Sender Identity's Tenant ID>";
    private static string SenderPurviewAccountName = "<Sender Purview Account Name>";

    private static string ShareName = "<Share Display Name>";
    private static string ShareDescription = "Share created using the SDK.";
    private static string SenderStorageKind = "<Sender Storage Account Kind (BlobAccount / AdlsGen2Account)>";
    private static string SenderStorageResourceId = "<Sender Storage Account Resource Id>";
    private static string SenderStorageContainer = "<Share Data Container Name>";
    private static string SenderPathToShare = "<File/Folder Path To Share>";

    // Set if using Service principal to create shares
    private static bool UseServiceTokenCredentials = false;
    private static string SenderClientId = "<Sender Application (Client) Id>";
    private static string SenderClientSecret = "<Sender Application (Client) Secret>";

    // [OPTIONAL INPUTS] Override Value If Desired.
    private static string SentShareId = Guid.NewGuid().ToString();
    private static string ReceiverVisiblePath = Guid.NewGuid().ToString();

    // General Configs
    private static string SenderPurviewEndPoint = $"https://{SenderPurviewAccountName}.purview.azure.com";
    private static string SenderShareEndPoint = $"{SenderPurviewEndPoint}/share";

    private static async Task Main(string[] args)
    {
        try
        {
            /// Replace all placeholder inputs above with actual values before running this program.
            /// This updated Share experience API will create Shares based on callers RBAC role on the storage account.
            /// To view/manage Shares via UX in Purview Studio. Storage accounts need to be registered (one time action) in Purview account with DSA permissions.

            Console.WriteLine($"{DateTime.Now.ToShortTimeString()}: CreateShare - START");
            await Sender_CreateSentShare();
            Console.WriteLine($"{DateTime.Now.ToShortTimeString()}: CreateShare - FINISH");
        }
        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(ex);
            Console.ForegroundColor = Console.ForegroundColor;
        }
    }

    private static async Task<BinaryData> Sender_CreateSentShare()
    {

        TokenCredential senderCredentials = UseServiceTokenCredentials
                ? new ClientSecretCredential(SenderTenantId, SenderClientId, SenderClientSecret)
                : new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = new Uri("https://login.windows.net"), TenantId = SenderTenantId });

        SentSharesClient? sentSharesClient = new SentSharesClient(SenderShareEndPoint, senderCredentials);

        if (sentSharesClient == null)
        {
            throw new InvalidEnumArgumentException("Invalid Sent Shares Client.");
        }

        // Create sent share
        var inPlaceSentShareDto = new
        {
            shareKind = "InPlace",
            properties = new
            {
                displayName = ShareName,
                description = ShareDescription,
                artifact = new
                {
                    storeKind = SenderStorageKind,
                    storeReference = new
                    {
                        referenceName = SenderStorageResourceId,
                        type = "ArmResourceReference"
                    },
                    properties = new
                    {
                        paths = new[]
                        {
                            new
                            {
                                receiverPath = ReceiverVisiblePath,
                                containerName = SenderStorageContainer,
                                senderPath = SenderPathToShare
                            }
                        }
                    }
                }
            },
        };

        Operation<BinaryData> sentShare = await sentSharesClient.CreateOrReplaceSentShareAsync(WaitUntil.Completed, SentShareId, RequestContent.Create(inPlaceSentShareDto));
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine(sentShare.Value);
        Console.ForegroundColor = Console.ForegroundColor;
        return sentShare.Value;
    }
}

ユーザーに招待を送信する

このスクリプトは、共有の招待メールをユーザーに送信します。 サービス プリンシパルに招待を送信する場合は、 次のコード例を参照してください。 これを使用するには、次の変数を必ず入力してください。

  • RecipientUserEmailId - 招待を送信するユーザーのアドレスをEmailします。
  • SenderTenantId - 共有送信者の ID の Azure テナント ID。
  • SenderPurviewAccountName - データの送信元となる Microsoft Purview アカウントの名前。
  • SenderStorageResourceId - データの送信元となる ストレージ アカウントのリソース ID
  • SentShareDisplayName - 招待を送信する送信済み共有の名前。
  • UseServiceTokenCredentials - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、これを true に設定 します
  • SenderClientId - (省略可能) サービス プリンシパルを使用して共有を作成する場合、これはサービス プリンシパルのアプリケーション (クライアント) ID です。
  • SenderClientSecret - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、クライアント シークレット/認証キーを追加します。
  • InvitationId - (省略可能) このオプションは GUID である必要があり、現在の値によって生成されますが、必要に応じて別の値に置き換えることができます。
  • SenderPurviewEndPoint - 従来の Microsoft purview エクスペリエンスを使用している場合は、 を使用 $"https://{SenderPurviewAccountName}.purview.azure.com"します。 新しい Microsoft Purview エクスペリエンスを使用している場合は、 https://api.purview-service.microsoft.com/
using Azure;
using Azure.Analytics.Purview.Sharing;
using Azure.Core;
using Azure.Identity;
using System.ComponentModel;
using System.Text.Json;

public static class PurviewDataSharingQuickStart
{
    // [REQUIRED INPUTS] Set To Actual Values.
    private static string RecipientUserEmailId = "<Target User's Email Id>";

    private static string SenderTenantId = "<Sender Indentity's Tenant ID>";
    private static string SenderPurviewAccountName = "<Sender Purview Account Name>";
    private static string SenderStorageResourceId = "<Sender Storage Account Resource Id>";

    // Set if using Service principal to send invitation
    private static bool UseServiceTokenCredentials = false;
    private static string SenderClientId = "<Sender Application (Client) Id>";
    private static string SenderClientSecret = "<Sender Application (Client) Secret>";

    private static string SentShareDisplayName = "<Name of share you're sending an invite for.>";
    private static string InvitationId = Guid.NewGuid().ToString();

    // General Configs
    private static string SenderPurviewEndPoint = $"https://{SenderPurviewAccountName}.purview.azure.com";
    private static string SenderShareEndPoint = $"{SenderPurviewEndPoint}/share";
    private static int StepCounter = 0;

    private static async Task Main(string[] args)
    {
        try
        {

            Console.WriteLine($"{DateTime.Now.ToShortTimeString()}: SendtoUser - START");
            await Sender_CreateUserRecipient();
            Console.WriteLine($"{DateTime.Now.ToShortTimeString()}: SendtoUser - FINISH");
        }
        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(ex);
            Console.ForegroundColor = Console.ForegroundColor;
        }
    }

    public static async Task<List<T>> ToResultList<T>(this AsyncPageable<T> asyncPageable)
    {
        List<T> list = new List<T>();

        await foreach (T item in asyncPageable)
        {
            list.Add(item);
        }

        return list;
    }

    private static async Task<BinaryData> Sender_CreateUserRecipient()
    {

        TokenCredential senderCredentials = UseServiceTokenCredentials
                ? new ClientSecretCredential(SenderTenantId, SenderClientId, SenderClientSecret)
                : new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = new Uri("https://login.windows.net"), TenantId = SenderTenantId });

        SentSharesClient? sentSharesClient = new SentSharesClient(SenderShareEndPoint, senderCredentials);

        if (string.IsNullOrEmpty(RecipientUserEmailId))
        {
            throw new InvalidEnumArgumentException("Invalid Recipient User Email Id.");
        }

        // Create user recipient and invite
        var invitationData = new
        {
            invitationKind = "User",
            properties = new
            {
                expirationDate = DateTime.Now.AddDays(7).ToString(),
                notify = true, // Send invitation email
                targetEmail = RecipientUserEmailId
            }
        };

        var allSentShares = await sentSharesClient.GetAllSentSharesAsync(SenderStorageResourceId).ToResultList();

        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine("{0}. {1}...", ++StepCounter, "Get a Specific Sent Share");
        Console.ForegroundColor = Console.ForegroundColor;

        var mySentShare = allSentShares.First(sentShareDoc =>
        {
            var doc = JsonDocument.Parse(sentShareDoc).RootElement;
            var props = doc.GetProperty("properties");
            return props.GetProperty("displayName").ToString() == SentShareDisplayName;
        });

        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("My Sent Share Id: " + JsonDocument.Parse(mySentShare).RootElement.GetProperty("id").ToString());
        Console.ForegroundColor = Console.ForegroundColor;

        var SentShareId = JsonDocument.Parse(mySentShare).RootElement.GetProperty("id").ToString();

        var sentInvitation = await sentSharesClient.CreateSentShareInvitationAsync(SentShareId, InvitationId, RequestContent.Create(invitationData));

        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine(sentInvitation.Content);
        Console.ForegroundColor = Console.ForegroundColor;

        return sentInvitation.Content;
    }
}

サービスへの招待の送信

このスクリプトは、共有の招待メールをサービス プリンシパルに送信します。 ユーザーに招待を送信する場合は、 前のサンプルを参照してください。 これを使用するには、次の変数を必ず入力してください。

  • RecipientApplicationTenantId - 受信サービス プリンシパルの Azure テナント ID。
  • RecipientApplicationObjectId - 受信サービス プリンシパルのオブジェクト ID。
  • SenderTenantId - 共有送信者の ID の Azure テナント ID。
  • SenderPurviewAccountName - データの送信元となる Microsoft Purview アカウントの名前。
  • SenderStorageResourceId - データの送信元となる ストレージ アカウントのリソース ID
  • SentShareDisplayName - 招待を送信する送信済み共有の名前。
  • UseServiceTokenCredentials - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、これを true に設定 します
  • SenderClientId - (省略可能) サービス プリンシパルを使用して共有を作成する場合、これはサービス プリンシパルのアプリケーション (クライアント) ID です。
  • SenderClientSecret - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、クライアント シークレット/認証キーを追加します。
  • InvitationId - (省略可能) このオプションは GUID である必要があり、現在の値によって生成されますが、必要に応じて別の値に置き換えることができます。
  • SenderPurviewEndPoint - 従来の Microsoft purview エクスペリエンスを使用している場合は、 を使用 $"https://{SenderPurviewAccountName}.purview.azure.com"します。 新しい Microsoft Purview エクスペリエンスを使用している場合は、 https://api.purview-service.microsoft.com/
using Azure;
using Azure.Analytics.Purview.Sharing;
using Azure.Core;
using Azure.Identity;
using System.ComponentModel;
using System.Text.Json;

public static class PurviewDataSharingQuickStart
{
    // [REQUIRED INPUTS] Set To Actual Values.
    private static string RecipientApplicationTenantId = "<Target Application's Tenant Id>";
    private static string RecipientApplicationObjectId = "<Target Application's Object Id>";

    private static string SentShareDisplayName = "<Name of share you're sending an invite for.>";
    private static string InvitationId = Guid.NewGuid().ToString();

    private static string SenderTenantId = "<Sender Indentity's Tenant ID>";
    private static string SenderPurviewAccountName = "<Sender Purview Account Name>";

    private static string SenderStorageResourceId = "<Resource ID for storage account that has been shared>";

    // Set if using Service principal to send invitation
    private static bool UseServiceTokenCredentials = false;
    private static string SenderClientId = "<Sender Application (Client) Id>";
    private static string SenderClientSecret = "<Sender Application (Client) Secret>";

    // General Configs
    private static string SenderPurviewEndPoint = $"https://{SenderPurviewAccountName}.purview.azure.com";
    private static string SenderShareEndPoint = $"{SenderPurviewEndPoint}/share";

    private static async Task Main(string[] args)
    {
        try
        {

            Console.WriteLine($"{DateTime.Now.ToShortTimeString()}: SendtoService - START");
            await Sender_CreateServiceRecipient();
            Console.WriteLine($"{DateTime.Now.ToShortTimeString()}: SendtoService - FINISH");
        }
        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(ex);
            Console.ForegroundColor = Console.ForegroundColor;
        }
    }

    public static async Task<List<T>> ToResultList<T>(this AsyncPageable<T> asyncPageable)
    {
        List<T> list = new List<T>();

        await foreach (T item in asyncPageable)
        {
            list.Add(item);
        }

        return list;
    }

    private static async Task<BinaryData> Sender_CreateServiceRecipient()
    {

        TokenCredential senderCredentials = UseServiceTokenCredentials
                ? new ClientSecretCredential(SenderTenantId, SenderClientId, SenderClientSecret)
                : new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = new Uri("https://login.windows.net"), TenantId = SenderTenantId });

        SentSharesClient? sentSharesClient = new SentSharesClient(SenderShareEndPoint, senderCredentials);

        if (!Guid.TryParse(RecipientApplicationTenantId, out Guid _))
        {
            throw new InvalidEnumArgumentException("Invalid Recipient Service Tenant Id.");
        }

        if (!Guid.TryParse(RecipientApplicationObjectId, out Guid _))
        {
            throw new InvalidEnumArgumentException("Invalid Recipient Service Object Id.");
        }

        // Create service recipient
        var invitationData = new
        {
            invitationKind = "Service",
            properties = new
            {
                expirationDate = DateTime.Now.AddDays(5).ToString(),
                targetActiveDirectoryId = RecipientApplicationTenantId,
                targetObjectId = RecipientApplicationObjectId
            }
        };


        var allSentShares = await sentSharesClient.GetAllSentSharesAsync(SenderStorageResourceId).ToResultList();
        var mySentShare = allSentShares.First(sentShareDoc =>
        {
            var doc = JsonDocument.Parse(sentShareDoc).RootElement;
            var props = doc.GetProperty("properties");
            return props.GetProperty("displayName").ToString() == SentShareDisplayName;
        });

        var SentShareId = JsonDocument.Parse(mySentShare).RootElement.GetProperty("id").ToString();

        var sentInvitation = await sentSharesClient.CreateSentShareInvitationAsync(SentShareId, InvitationId, RequestContent.Create(invitationData));
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine(sentInvitation.Content);
        Console.ForegroundColor = Console.ForegroundColor;
        return sentInvitation.Content;
    }

}

送信された共有を一覧表示する

このスクリプトは、特定のストレージ リソースに対して送信されたすべての共有を一覧表示します。 これを使用するには、次の変数を必ず入力してください。

  • SenderTenantId - 共有送信者の ID の Azure テナント ID。
  • SenderPurviewAccountName - データが送信された Microsoft Purview アカウントの名前。
  • SenderStorageResourceId - 共有が送信された ストレージ アカウントのリソース ID
  • UseServiceTokenCredentials - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、これを true に設定 します
  • SenderClientId - (省略可能) サービス プリンシパルを使用して共有を作成する場合、これはサービス プリンシパルのアプリケーション (クライアント) ID です。
  • SenderClientSecret - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、クライアント シークレット/認証キーを追加します。
  • SenderPurviewEndPoint - 従来の Microsoft purview エクスペリエンスを使用している場合は、 を使用 $"https://{SenderPurviewAccountName}.purview.azure.com"します。 新しい Microsoft Purview エクスペリエンスを使用している場合は、 https://api.purview-service.microsoft.com/
using Azure;
using Azure.Analytics.Purview.Sharing;
using Azure.Core;
using Azure.Identity;

public static class PurviewDataSharingQuickStart
{
    // [REQUIRED INPUTS] Set To Actual Values.
    private static string SenderTenantId = "<Sender Tenant ID>";
    private static string SenderPurviewAccountName = "<Name of the Microsoft Purview account>";
    private static string SenderStorageResourceId = "<Sender Storage Account Resource Id>";

    // Set if using Service principal to list shares
    private static bool UseServiceTokenCredentials = false;
    private static string SenderClientId = "<Sender Application (Client) Id>";
    private static string SenderClientSecret = "<Sender Application (Client) Secret>";

    // General Configs
    private static string SenderPurviewEndPoint = $"https://{SenderPurviewAccountName}.purview.azure.com";
    private static string SenderShareEndPoint = $"{SenderPurviewEndPoint}/share";

    private static async Task Main(string[] args)
    {


        try
        {
            TokenCredential senderCredentials = UseServiceTokenCredentials
                ? new ClientSecretCredential(SenderTenantId, SenderClientId, SenderClientSecret)
                : new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = new Uri("https://login.windows.net"), TenantId = SenderTenantId });

            SentSharesClient? sentSharesClient = new SentSharesClient(SenderShareEndPoint, senderCredentials);

            var allSentShares = await sentSharesClient.GetAllSentSharesAsync(SenderStorageResourceId).ToResultList();
            Console.WriteLine(allSentShares);
        }
        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(ex);
            Console.ForegroundColor = Console.ForegroundColor;
        }
    }

    public static async Task<List<T>> ToResultList<T>(this AsyncPageable<T> asyncPageable)
    {
        List<T> list = new List<T>();

        await foreach (T item in asyncPageable)
        {
            list.Add(item);
        }

        return list;
    }
}

すべての共有受信者を一覧表示する

このスクリプトは、特定の共有のすべての受信者を一覧表示します。 これを使用するには、次の変数を必ず入力してください。

  • SenderTenantId - 共有送信者の ID の Azure テナント ID。
  • SenderPurviewAccountName - データが送信された Microsoft Purview アカウントの名前。
  • SentShareDisplayName - 受信者を一覧表示する送信済み共有の名前。
  • SenderStorageResourceId - データの送信元となる ストレージ アカウントのリソース ID
  • UseServiceTokenCredentials - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、これを true に設定 します
  • SenderClientId - (省略可能) サービス プリンシパルを使用して共有を作成する場合、これはサービス プリンシパルのアプリケーション (クライアント) ID です。
  • SenderClientSecret - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、クライアント シークレット/認証キーを追加します。
  • SenderPurviewEndPoint - 従来の Microsoft purview エクスペリエンスを使用している場合は、 を使用 $"https://{SenderPurviewAccountName}.purview.azure.com"します。 新しい Microsoft Purview エクスペリエンスを使用している場合は、 https://api.purview-service.microsoft.com/
using Azure;
using Azure.Analytics.Purview.Sharing;
using Azure.Core;
using Azure.Identity;
using System.Text.Json;

public static class PurviewDataSharingQuickStart
{
    // [REQUIRED INPUTS] Set To Actual Values.
    private static string SentShareDisplayName = "<Name of share you're listing recipients for.>";
    private static string SenderTenantId = "<Sender Tenant ID>";
    private static string SenderPurviewAccountName = "<Name of the Microsoft Purview account>";

    private static string SenderStorageResourceId = "<Sender Storage Account Resource Id>";

    // Set if using Service principal to list recipients
    private static bool UseServiceTokenCredentials = false;
    private static string SenderClientId = "<Sender Application (Client) Id>";
    private static string SenderClientSecret = "<Sender Application (Client) Secret>";

    // General Configs
    private static string SenderPurviewEndPoint = $"https://{SenderPurviewAccountName}.purview.azure.com";
    private static string SenderShareEndPoint = $"{SenderPurviewEndPoint}/share";

    private static async Task Main(string[] args)
    {
        try
        {
            TokenCredential senderCredentials = UseServiceTokenCredentials
                ? new ClientSecretCredential(SenderTenantId, SenderClientId, SenderClientSecret)
                : new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = new Uri("https://login.windows.net"), TenantId = SenderTenantId });

            SentSharesClient? sentSharesClient = new SentSharesClient(SenderShareEndPoint, senderCredentials);

            var allSentShares = await sentSharesClient.GetAllSentSharesAsync(SenderStorageResourceId).ToResultList();
            var mySentShare = allSentShares.First(sentShareDoc =>
            {
                var doc = JsonDocument.Parse(sentShareDoc).RootElement;
                var props = doc.GetProperty("properties");
                return props.GetProperty("displayName").ToString() == SentShareDisplayName;
            });

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("My Sent Share Id: " + JsonDocument.Parse(mySentShare).RootElement.GetProperty("id").ToString());
            Console.ForegroundColor = Console.ForegroundColor;

            var SentShareId = JsonDocument.Parse(mySentShare).RootElement.GetProperty("id").ToString();

            var allRecipients = await sentSharesClient.GetAllSentShareInvitationsAsync(SentShareId).ToResultList();
            Console.WriteLine(allRecipients);

        }
        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(ex);
            Console.ForegroundColor = Console.ForegroundColor;
        }
    }

    public static async Task<List<T>> ToResultList<T>(this AsyncPageable<T> asyncPageable)
    {
        List<T> list = new List<T>();

        await foreach (T item in asyncPageable)
        {
            list.Add(item);
        }

        return list;
    }
}

受信者を削除する

このスクリプトは、受信者の共有への招待と共有を削除します。 これを使用するには、次の変数を必ず入力してください。

  • SenderTenantId - 共有送信者の ID の Azure テナント ID。
  • SenderPurviewAccountName - データが送信された Microsoft Purview アカウントの名前。
  • SentShareDisplayName - 受信者を削除する送信済み共有の名前。
  • SenderStorageResourceId - データの送信元となる ストレージ アカウントのリソース ID
  • RecipientUserEmailId - 削除するユーザーのアドレスをEmailします。
  • UseServiceTokenCredentials - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、これを true に設定 します
  • SenderClientId - (省略可能) サービス プリンシパルを使用して共有を作成する場合、これはサービス プリンシパルのアプリケーション (クライアント) ID です。
  • SenderClientSecret - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、クライアント シークレット/認証キーを追加します。
  • SenderPurviewEndPoint - 従来の Microsoft purview エクスペリエンスを使用している場合は、 を使用 $"https://{SenderPurviewAccountName}.purview.azure.com"します。 新しい Microsoft Purview エクスペリエンスを使用している場合は、 https://api.purview-service.microsoft.com/
using Azure;
using Azure.Analytics.Purview.Sharing;
using Azure.Core;
using Azure.Identity;
using System.Text.Json;

public static class PurviewDataSharingQuickStart
{
    // [REQUIRED INPUTS] Set To Actual Values.
    private static string SentShareDisplayName = "<Name of share you're removing a recipient for.>";
    private static string SenderTenantId = "<Sender Tenant ID>";
    private static string SenderPurviewAccountName = "<Name of the Microsoft Purview account>";
    private static string RecipientUserEmailId = "<Target User's Email Id>";

    private static string SenderStorageResourceId = "<Sender Storage Account Resource Id>";

    // Set if using Service principal to delete recipients
    private static bool UseServiceTokenCredentials = false;
    private static string SenderClientId = "<Sender Application (Client) Id>";
    private static string SenderClientSecret = "<Sender Application (Client) Secret>";

    // General Configs
    private static string SenderPurviewEndPoint = $"https://{SenderPurviewAccountName}.purview.azure.com";
    private static string SenderShareEndPoint = $"{SenderPurviewEndPoint}/share";

    private static async Task Main(string[] args)
    {
        try
        {
            TokenCredential senderCredentials = UseServiceTokenCredentials
                ? new ClientSecretCredential(SenderTenantId, SenderClientId, SenderClientSecret)
                : new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = new Uri("https://login.windows.net"), TenantId = SenderTenantId });

            SentSharesClient? sentSharesClient = new SentSharesClient(SenderShareEndPoint, senderCredentials);

            var allSentShares = await sentSharesClient.GetAllSentSharesAsync(SenderStorageResourceId).ToResultList();

            var mySentShare = allSentShares.First(sentShareDoc =>
            {
                var doc = JsonDocument.Parse(sentShareDoc).RootElement;
                var props = doc.GetProperty("properties");
                return props.GetProperty("displayName").ToString() == SentShareDisplayName;
            });

            var SentShareId = JsonDocument.Parse(mySentShare).RootElement.GetProperty("id").ToString();

            var allRecipients = await sentSharesClient.GetAllSentShareInvitationsAsync(SentShareId).ToResultList();

            var recipient = allRecipients.First(recipient =>
            {
                var doc = JsonDocument.Parse(recipient).RootElement;
                var props = doc.GetProperty("properties");
                return props.TryGetProperty("targetEmail", out JsonElement rcpt) && rcpt.ToString() == RecipientUserEmailId;
            });

            var recipientId = JsonDocument.Parse(recipient).RootElement.GetProperty("id").ToString();

            await sentSharesClient.DeleteSentShareInvitationAsync(WaitUntil.Completed, SentShareId, recipientId);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Remove Id: " + JsonDocument.Parse(recipient).RootElement.GetProperty("id").ToString());
            Console.WriteLine("Complete");
            Console.ForegroundColor = Console.ForegroundColor;

        }

        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(ex);
            Console.ForegroundColor = Console.ForegroundColor;
        }
    }

    public static async Task<List<T>> ToResultList<T>(this AsyncPageable<T> asyncPageable)
    {
        List<T> list = new List<T>();

        await foreach (T item in asyncPageable)
        {
            list.Add(item);
        }

        return list;
    }
}

送信された共有を削除する

このスクリプトは、送信された共有を削除します。 これを使用するには、次の変数を必ず入力してください。

  • SenderTenantId - 共有送信者の ID の Azure テナント ID。
  • SenderPurviewAccountName - データが送信された Microsoft Purview アカウントの名前。
  • SentShareDisplayName - 受信者を一覧表示する送信済み共有の名前。
  • SenderStorageResourceId - データの送信元となる ストレージ アカウントのリソース ID
  • UseServiceTokenCredentials - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、これを true に設定 します
  • SenderClientId - (省略可能) サービス プリンシパルを使用して共有を作成する場合、これはサービス プリンシパルのアプリケーション (クライアント) ID です。
  • SenderClientSecret - (省略可能) サービス プリンシパルを使用して共有を作成する場合は、クライアント シークレット/認証キーを追加します。
  • SenderPurviewEndPoint - 従来の Microsoft purview エクスペリエンスを使用している場合は、 を使用 $"https://{SenderPurviewAccountName}.purview.azure.com"します。 新しい Microsoft Purview エクスペリエンスを使用している場合は、 https://api.purview-service.microsoft.com/
using Azure;
using Azure.Analytics.Purview.Sharing;
using Azure.Core;
using Azure.Identity;
using System.Text.Json;

public static class PurviewDataSharingQuickStart
{
    // [REQUIRED INPUTS] Set To Actual Values.
    private static string SenderTenantId = "<Sender Tenant ID>";
    private static string SenderPurviewAccountName = "<Name of the Microsoft Purview account>";
    private static string SentShareDisplayName = "<Name of share you're removing.>";

    private static string SenderStorageResourceId = "<Sender Storage Account Resource Id>";

    // Set if using Service principal to delete share
    private static bool UseServiceTokenCredentials = false;
    private static string SenderClientId = "<Sender Application (Client) Id>";
    private static string SenderClientSecret = "<Sender Application (Client) Secret>";

    // General Configs
    private static string SenderPurviewEndPoint = $"https://{SenderPurviewAccountName}.purview.azure.com";
    private static string SenderShareEndPoint = $"{SenderPurviewEndPoint}/share";

    private static async Task Main(string[] args)
    {
        try
        {
            TokenCredential senderCredentials = UseServiceTokenCredentials
                ? new ClientSecretCredential(SenderTenantId, SenderClientId, SenderClientSecret)
                : new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = new Uri("https://login.windows.net"), TenantId = SenderTenantId });

            SentSharesClient? sentSharesClient = new SentSharesClient(SenderShareEndPoint, senderCredentials);

            var allSentShares = await sentSharesClient.GetAllSentSharesAsync(SenderStorageResourceId).ToResultList();

            var mySentShare = allSentShares.First(sentShareDoc =>
            {
                var doc = JsonDocument.Parse(sentShareDoc).RootElement;
                var props = doc.GetProperty("properties");
                return props.GetProperty("displayName").ToString() == SentShareDisplayName;
            });

            var SentShareId = JsonDocument.Parse(mySentShare).RootElement.GetProperty("id").ToString();

            await sentSharesClient.DeleteSentShareAsync(WaitUntil.Completed, SentShareId);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Remove Id: " + SentShareId);
            Console.WriteLine("Complete");
            Console.ForegroundColor = Console.ForegroundColor;

        }
        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(ex);
            Console.ForegroundColor = Console.ForegroundColor;
        }
    }

    public static async Task<List<T>> ToResultList<T>(this AsyncPageable<T> asyncPageable)
    {
        List<T> list = new List<T>();

        await foreach (T item in asyncPageable)
        {
            list.Add(item);
        }

        return list;
    }
}

受信した共有を作成する

このスクリプトを使用すると、データ共有を受け取ることができます。 これを使用するには、次の変数を必ず入力してください。

  • ReceiverTenantId - 共有データを受信しているユーザー/サービスの Azure テナント ID。
  • ReceiverPurviewAccountName - データを受信する Microsoft Purview アカウントの名前。
  • ReceiverStorageKind - BlobAccount または AdlsGen2Account のいずれか。
  • ReceiverStorageResourceId - データ を受信するストレージ アカウントのリソース ID
  • ReceiverStorageContainer - 共有データが格納されるコンテナーの名前。
  • ReceiverTargetFolderName - 共有データが格納されるフォルダー パス。
  • ReceiverTargetMountPath - フォルダーにデータを格納するために使用するマウント パス。
  • UseServiceTokenCredentials - (省略可能) サービス プリンシパルを使用して共有を受信する場合は、これを true に設定 します
  • ReceiverClientId - (省略可能) サービス プリンシパルを使用して共有を受信する場合、これはサービス プリンシパルのアプリケーション (クライアント) ID です。
  • ReceiverClientSecret - (省略可能) サービス プリンシパルを使用して共有を受信する場合は、クライアント シークレット/認証キーを追加します。
  • ReceivedShareId - (省略可能) このオプションは GUID である必要があり、現在の値によって生成されますが、必要に応じて別の値に置き換えることができます。
  • ReceiverVisiblePath - (省略可能) 受信した共有のパスに使用する名前。
  • ReceivedShareDisplayName - (省略可能) 受信した共有の表示名。
  • ReceiverPurviewEndPoint - 従来の Microsoft purview エクスペリエンスを使用している場合は、 を使用 $"https://{ReceiverPurviewAccountName}.purview.azure.com"します。 新しい Microsoft Purview エクスペリエンスを使用している場合は、 https://api.purview-service.microsoft.com/
using Azure;
using Azure.Analytics.Purview.Sharing;
using Azure.Core;
using Azure.Identity;
using System.ComponentModel;
using System.Text.Json;

public static class PurviewDataSharingQuickStart
{
    // [REQUIRED INPUTS] Set To Actual Values.
    private static string ReceiverTenantId = "<Receiver Indentity's Tenant ID>";
    private static string ReceiverPurviewAccountName = "<Receiver Purview Account Name>";

    private static string ReceiverStorageKind = "<Receiver Storage Account Kind (BlobAccount / AdlsGen2Account)>";
    private static string ReceiverStorageResourceId = "<Receiver Storage Account Resource Id>";
    private static string ReceiverStorageContainer = "<Container Name To Receive Data Under>";
    private static string ReceiverTargetFolderName = "<Folder Name to Received Data Under>";
    private static string ReceiverTargetMountPath = "<Mount Path to store Received Data Under>";

    //Use if using a service principal to receive a share
    private static bool UseServiceTokenCredentials = false;
    private static string ReceiverClientId = "<Receiver Caller Application (Client) Id>";
    private static string ReceiverClientSecret = "<Receiver Caller Application (Client) Secret>";

    // [OPTIONAL INPUTS] Override Values If Desired.
    private static string ReceivedShareId = Guid.NewGuid().ToString();
    private static string ReceiverVisiblePath = "ReceivedSharePath";

    private static string ReceivedShareDisplayName = "ReceivedShare";

    // General Configs
    private static string ReceiverPurviewEndPoint = $"https://{ReceiverPurviewAccountName}.purview.azure.com";
    private static string ReceiverShareEndPoint = $"{ReceiverPurviewEndPoint}/share";

    private static async Task Main(string[] args)
    {
        try
        {


            Console.WriteLine($"{DateTime.Now.ToShortTimeString()}: CreateReceivedShare - START");
            await Receiver_CreateReceivedShare();
            Console.WriteLine($"{DateTime.Now.ToShortTimeString()}: CreateReceivedShare - FINISH");
        }
        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(ex);
            Console.ForegroundColor = Console.ForegroundColor;
        }
    }

    private static async Task<BinaryData> Receiver_CreateReceivedShare()
    {

        TokenCredential receiverCredentials = UseServiceTokenCredentials
            ? new ClientSecretCredential(ReceiverTenantId, ReceiverClientId, ReceiverClientSecret)
            : new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = new Uri("https://login.windows.net"), TenantId = ReceiverTenantId });

        ReceivedSharesClient? receivedSharesClient = new ReceivedSharesClient(ReceiverShareEndPoint, receiverCredentials);

        if (receivedSharesClient == null)
        {
            throw new InvalidEnumArgumentException("Invalid Received Shares Client.");
        }

        var results = await receivedSharesClient.GetAllDetachedReceivedSharesAsync().ToResultList();
        var detachedReceivedShare = results;

        if (detachedReceivedShare == null)
        {
            throw new InvalidOperationException("No received shares found.");
        }



        var myReceivedShare = detachedReceivedShare.First(recShareDoc =>
        {
            var doc = JsonDocument.Parse(recShareDoc).RootElement;
            var props = doc.GetProperty("properties");
            return props.GetProperty("displayName").ToString() == ReceivedShareDisplayName;
        });

        var ReceivedShareId = JsonDocument.Parse(myReceivedShare).RootElement.GetProperty("id").ToString();


        var attachedReceivedShareData = new
        {
            shareKind = "InPlace",
            properties = new
            {
                displayName = ReceivedShareDisplayName,
                sink = new
                {
                    storeKind = ReceiverStorageKind,
                    properties = new
                    {
                        containerName = ReceiverStorageContainer,
                        folder = ReceiverTargetFolderName,
                        mountPath = ReceiverTargetMountPath
                    },
                    storeReference = new
                    {
                        referenceName = ReceiverStorageResourceId,
                        type = "ArmResourceReference"
                    }
                }
            }
        };

        var receivedShare = await receivedSharesClient.CreateOrReplaceReceivedShareAsync(WaitUntil.Completed, ReceivedShareId, RequestContent.Create(attachedReceivedShareData));

        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine(receivedShare.Value);
        Console.ForegroundColor = Console.ForegroundColor;

        return receivedShare.Value;
    }

    public static async Task<List<T>> ToResultList<T>(this AsyncPageable<T> asyncPageable)
    {
        List<T> list = new List<T>();

        await foreach (T item in asyncPageable)
        {
            list.Add(item);
        }

        return list;
    }
}

受信したすべての共有を一覧表示する

このスクリプトは、ストレージ アカウントで受信したすべての共有を一覧表示します。 これを使用するには、次の変数を必ず入力してください。

  • ReceiverTenantId - 共有データを受信しているユーザー/サービスの Azure テナント ID。
  • ReceiverPurviewAccountName - データが受信された Microsoft Purview アカウントの名前。
  • ReceiverStorageResourceId - データが共有されている ストレージ アカウントのリソース ID
  • UseServiceTokenCredentials - (省略可能) サービス プリンシパルを使用して共有を受信する場合は、これを true に設定 します
  • ReceiverClientId - (省略可能) サービス プリンシパルを使用して共有を受信する場合、これはサービス プリンシパルのアプリケーション (クライアント) ID です。
  • ReceiverClientSecret - (省略可能) サービス プリンシパルを使用して共有を受信する場合は、クライアント シークレット/認証キーを追加します。
  • ReceiverPurviewEndPoint - 従来の Microsoft purview エクスペリエンスを使用している場合は、 を使用 $"https://{ReceiverPurviewAccountName}.purview.azure.com"します。 新しい Microsoft Purview エクスペリエンスを使用している場合は、 https://api.purview-service.microsoft.com/
using Azure;
using Azure.Analytics.Purview.Sharing;
using Azure.Core;
using Azure.Identity;

public static class PurviewDataSharingQuickStart
{
    // [REQUIRED INPUTS] Set To Actual Values.
    private static string ReceiverTenantId = "<Receiver Indentity's Tenant ID>";
    private static string ReceiverPurviewAccountName = "<Receiver Purview Account Name>";

    private static string ReceiverStorageResourceId = "<Storage Account Resource Id that is housing shares>";

    //Use if using a service principal to list shares
    private static bool UseServiceTokenCredentials = false;
    private static string ReceiverClientId = "<Receiver Caller Application (Client) Id>";
    private static string ReceiverClientSecret = "<Receiver Caller Application (Client) Secret>";

    // General Configs
    private static string ReceiverPurviewEndPoint = $"https://{ReceiverPurviewAccountName}.purview.azure.com";
    private static string ReceiverShareEndPoint = $"{ReceiverPurviewEndPoint}/share";

    private static async Task Main(string[] args)
    {
        try
        {
            TokenCredential receiverCredentials = UseServiceTokenCredentials
            ? new ClientSecretCredential(ReceiverTenantId, ReceiverClientId, ReceiverClientSecret)
            : new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = new Uri("https://login.windows.net"), TenantId = ReceiverTenantId });

            ReceivedSharesClient? receivedSharesClient = new ReceivedSharesClient(ReceiverShareEndPoint, receiverCredentials);

            var allReceivedShares = await receivedSharesClient.GetAllAttachedReceivedSharesAsync(ReceiverStorageResourceId).ToResultList();
            Console.WriteLine(allReceivedShares);
        }
        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(ex);
            Console.ForegroundColor = Console.ForegroundColor;
        }
    }

    public static async Task<List<T>> ToResultList<T>(this AsyncPageable<T> asyncPageable)
    {
        List<T> list = new List<T>();

        await foreach (T item in asyncPageable)
        {
            list.Add(item);
        }

        return list;
    }
}

受信した共有を更新する

このスクリプトを使用すると、受信した共有のストレージの場所を更新できます。 受信した共有を作成するのと同じように、データを格納するストレージ アカウントの情報を追加します。 これを使用するには、次の変数を必ず入力してください。

  • ReceiverTenantId - 共有データを受信しているユーザー/サービスの Azure テナント ID。
  • ReceiverPurviewAccountName - データを受信する Microsoft Purview アカウントの名前。
  • ReceiverStorageKind - BlobAccount または AdlsGen2Account のいずれか。
  • ReceiverStorageResourceId - データが共有されている ストレージ アカウントのリソース ID
  • ReAttachStorageResourceId - データ を受信するストレージ アカウントのリソース ID
  • ReceiverStorageContainer - 共有データが格納されるコンテナーの名前。
  • ReceiverTargetFolderName - 共有データが格納されるフォルダー パス。
  • ReceiverTargetMountPath - フォルダーにデータを格納するために使用するマウント パス。
  • ReceivedShareDisplayName - 受信した共有の表示名。
  • UseServiceTokenCredentials - (省略可能) サービス プリンシパルを使用して共有を受信する場合は、これを true に設定 します
  • ReceiverClientId - (省略可能) サービス プリンシパルを使用して共有を受信する場合、これはサービス プリンシパルのアプリケーション (クライアント) ID です。
  • ReceiverClientSecret - (省略可能) サービス プリンシパルを使用して共有を受信する場合は、クライアント シークレット/認証キーを追加します。
  • ReceiverPurviewEndPoint - 従来の Microsoft purview エクスペリエンスを使用している場合は、 を使用 $"https://{ReceiverPurviewAccountName}.purview.azure.com"します。 新しい Microsoft Purview エクスペリエンスを使用している場合は、 https://api.purview-service.microsoft.com/
using Azure;
using Azure.Analytics.Purview.Sharing;
using Azure.Core;
using Azure.Identity;
using System.ComponentModel;
using System.Text.Json;

public static class PurviewDataSharingQuickStart
{
    // [REQUIRED INPUTS] Set To Actual Values.
    private static string ReceiverTenantId = "<Receiver Indentity's Tenant ID>";
    private static string ReceiverPurviewAccountName = "<Receiver Purview Account Name>";

    private static string ReceiverStorageKind = "<Receiver Storage Account Kind (BlobAccount / AdlsGen2Account)>";
    private static string ReceiverStorageResourceId = "<Storage Account Resource Id for the account where the share is currently attached.>";
    private static string ReAttachStorageResourceId = "<Storage Account Resource Id For Reattaching Received Share>";
    private static string ReceiverStorageContainer = "<Container Name To Receive Data Under>";
    private static string ReceiverTargetFolderName = "<Folder Name to Received Data Under>";
    private static string ReceiverTargetMountPath = "<Mount Path to Received Data Under>";

    private static string ReceivedShareDisplayName = "<Display name of your received share>";

    //Use if using a service principal to update the share
    private static bool UseServiceTokenCredentials = false;
    private static string ReceiverClientId = "<Receiver Caller Application (Client) Id>";
    private static string ReceiverClientSecret = "<Receiver Caller Application (Client) Secret>";

    // General Configs
    private static string ReceiverPurviewEndPoint = $"https://{ReceiverPurviewAccountName}.purview.azure.com";
    private static string ReceiverShareEndPoint = $"{ReceiverPurviewEndPoint}/share";

    private static async Task Main(string[] args)
    {
        try
        {

            Console.WriteLine($"{DateTime.Now.ToShortTimeString()}: UpdateReceivedShare - START");
            await Receiver_UpdateReceivedShare();
            Console.WriteLine($"{DateTime.Now.ToShortTimeString()}: UpdateReceivedShare - FINISH");
        }
        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(ex);
            Console.ForegroundColor = Console.ForegroundColor;
        }
    }

    private static async Task<BinaryData> Receiver_UpdateReceivedShare()
    {

        TokenCredential receiverCredentials = UseServiceTokenCredentials
            ? new ClientSecretCredential(ReceiverTenantId, ReceiverClientId, ReceiverClientSecret)
            : new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = new Uri("https://login.windows.net"), TenantId = ReceiverTenantId });

        ReceivedSharesClient? receivedSharesClient = new ReceivedSharesClient(ReceiverShareEndPoint, receiverCredentials);

        if (receivedSharesClient == null)
        {
            throw new InvalidEnumArgumentException("Invalid Received Shares Client.");
        }

        var attachedReceivedShareData = new
        {
            shareKind = "InPlace",
            properties = new
            {
                displayName = ReceivedShareDisplayName,
                sink = new
                {
                    storeKind = ReceiverStorageKind,
                    properties = new
                    {
                        containerName = ReceiverStorageContainer,
                        folder = ReceiverTargetFolderName,
                        mountPath = ReceiverTargetMountPath
                    },
                    storeReference = new
                    {
                        referenceName = ReAttachStorageResourceId,
                        type = "ArmResourceReference"
                    }
                }
            }
        };

        var allReceivedShares = await receivedSharesClient.GetAllAttachedReceivedSharesAsync(ReceiverStorageResourceId).ToResultList();

        var myReceivedShare = allReceivedShares.First(recShareDoc =>
        {
            var doc = JsonDocument.Parse(recShareDoc).RootElement;
            var props = doc.GetProperty("properties");
            return props.GetProperty("displayName").ToString() == ReceivedShareDisplayName;
        });

        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("My Received Share Id: " + JsonDocument.Parse(myReceivedShare).RootElement.GetProperty("id").ToString());
        Console.ForegroundColor = Console.ForegroundColor;


        var ReceivedShareId = JsonDocument.Parse(myReceivedShare).RootElement.GetProperty("id").ToString();

        var receivedShare = await receivedSharesClient.CreateOrReplaceReceivedShareAsync(WaitUntil.Completed, ReceivedShareId, RequestContent.Create(attachedReceivedShareData));

        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine(receivedShare.Value);
        Console.ForegroundColor = Console.ForegroundColor;

        return receivedShare.Value;
    }

    public static async Task<List<T>> ToResultList<T>(this AsyncPageable<T> asyncPageable)
    {
        List<T> list = new List<T>();

        await foreach (T item in asyncPageable)
        {
            list.Add(item);
        }

        return list;
    }
}

受信した共有を削除する

このスクリプトは、受信した共有を削除します。 これを使用するには、次の変数を必ず入力してください。

  • ReceiverTenantId - 共有データを受信しているユーザー/サービスの Azure テナント ID。
  • ReceiverPurviewAccountName - データを受信する Microsoft Purview アカウントの名前。
  • ReceivedShareDisplayName - 受信した共有の表示名。
  • ReceiverStorageResourceId - データが共有されている ストレージ アカウントのリソース ID
  • UseServiceTokenCredentials - (省略可能) サービス プリンシパルを使用して共有を受信する場合は、これを true に設定 します
  • ReceiverClientId - (省略可能) サービス プリンシパルを使用して共有を受信する場合、これはサービス プリンシパルのアプリケーション (クライアント) ID です。
  • ReceiverClientSecret - (省略可能) サービス プリンシパルを使用して共有を受信する場合は、クライアント シークレット/認証キーを追加します。
  • ReceiverPurviewEndPoint - 従来の Microsoft purview エクスペリエンスを使用している場合は、 を使用 $"https://{ReceiverPurviewAccountName}.purview.azure.com"します。 新しい Microsoft Purview エクスペリエンスを使用している場合は、 https://api.purview-service.microsoft.com/
using Azure;
using Azure.Analytics.Purview.Sharing;
using Azure.Core;
using Azure.Identity;
using System.Text.Json;

public static class PurviewDataSharingQuickStart
{
    // [REQUIRED INPUTS] Set To Actual Values.
    private static string ReceiverTenantId = "<Receiver Indentity's Tenant ID>";
    private static string ReceiverPurviewAccountName = "<Receiver Purview Account Name>";

    private static string ReceivedShareDisplayName = "<Display name of your received share>";

    private static string ReceiverStorageResourceId = "<Storage Account Resource Id for the account where the share is currently attached.>";

    //Use if using a service principal to delete share.
    private static bool UseServiceTokenCredentials = false;
    private static string ReceiverClientId = "<Receiver Caller Application (Client) Id>";
    private static string ReceiverClientSecret = "<Receiver Caller Application (Client) Secret>";

    // General Configs
    private static string ReceiverPurviewEndPoint = $"https://{ReceiverPurviewAccountName}.purview.azure.com";
    private static string ReceiverShareEndPoint = $"{ReceiverPurviewEndPoint}/share";

    private static async Task Main(string[] args)
    {
        try
        {
            TokenCredential receiverCredentials = UseServiceTokenCredentials
            ? new ClientSecretCredential(ReceiverTenantId, ReceiverClientId, ReceiverClientSecret)
            : new DefaultAzureCredential(new DefaultAzureCredentialOptions { AuthorityHost = new Uri("https://login.windows.net"), TenantId = ReceiverTenantId });

            ReceivedSharesClient? receivedSharesClient = new ReceivedSharesClient(ReceiverShareEndPoint, receiverCredentials);

            var allReceivedShares = await receivedSharesClient.GetAllAttachedReceivedSharesAsync(ReceiverStorageResourceId).ToResultList();

            var myReceivedShare = allReceivedShares.First(recShareDoc =>
            {
                var doc = JsonDocument.Parse(recShareDoc).RootElement;
                var props = doc.GetProperty("properties");
                return props.GetProperty("displayName").ToString() == ReceivedShareDisplayName;
            });

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("My Received Share Id: " + JsonDocument.Parse(myReceivedShare).RootElement.GetProperty("id").ToString());
            Console.ForegroundColor = Console.ForegroundColor;

            var ReceivedShareId = JsonDocument.Parse(myReceivedShare).RootElement.GetProperty("id").ToString();

            await receivedSharesClient.DeleteReceivedShareAsync(WaitUntil.Completed, ReceivedShareId);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Delete Complete");
            Console.ForegroundColor = Console.ForegroundColor;
        }
        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(ex);
            Console.ForegroundColor = Console.ForegroundColor;
        }
    }
    public static async Task<List<T>> ToResultList<T>(this AsyncPageable<T> asyncPageable)
    {
        List<T> list = new List<T>();

        await foreach (T item in asyncPageable)
        {
            list.Add(item);
        }

        return list;
    }
}

リソースをクリーンアップする

クイック スタート用に作成されたリソースをクリーンするには、次のガイドラインを使用します。

  1. Microsoft Purview ポータル内で、 送信された共有を削除します
  2. また、受信した共有も削除します
  3. 共有が正常に削除されたら、共有データを受信したときにターゲット ストレージ アカウントに作成されたターゲット コンテナーとフォルダー Microsoft Purview を削除します。

次の手順