Azure Purview Share client library for .NET - version 1.0.0-beta.3
Microsoft Purview Data Sharing allows data to be shared in-place from Azure Data Lake Storage Gen2 and Azure Storage accounts, both within and across organizations.
Data providers may use Microsoft Purview Data Sharing to share their data directly with other users and partners (known as data consumers) without data duplication, while centrally managing their sharing activities from within Microsoft Purview.
For data consumers, Microsoft Purview Data Sharing provides near real-time access to data shared with them by a provider.
Key capabilities delivered by Microsoft Purview Data Sharing include:
- Share data within the organization or with partners and customers outside of the organization (within the same Azure tenant or across different Azure tenants).
- Share data from ADLS Gen2 or Blob storage in-place without data duplication.
- Share data with multiple recipients.
- Access shared data in near real time.
- Manage sharing relationships and keep track of who the data is shared with/from, for each ADLSGen2 or Blob Storage account.
- Terminate share access at any time.
- Flexible experience through Microsoft Purview governance portal or via REST APIs.
Please visit the following resources to learn more about this product.
Source code | Package (NuGet) | Product documentation
Getting started
Install the package
Install the Microsoft Purview Share client library for .NET with NuGet:
dotnet add package Azure.Analytics.Purview.Sharing --prerelease
Prerequisites
- You must have an Azure subscription and a Purview resource to use this package.
Authenticate the client
Using Azure Active Directory
This example demonstrates using DefaultAzureCredential to authenticate via Azure Active Directory. However, any of the credentials offered by the Azure.Identity will be accepted. See the Azure.Identity documentation for more information about other credentials.
Once you have chosen and configured your credential, you can create instances of the SentSharesClient
.
Key concepts
Data Provider: A data provider is the individual who creates a share by selecting a data source, choosing which files and folders to share, and who to share them with. Microsoft Purview then sends an invitation to each data consumer.
Data Consumer: A data consumer is the individual who accepts the invitation by specifying a target storage account in their own Azure subscription that they'll use to access the shared data.
Protocol Methods
Operations exposed by the Purview Share client library for .NET use protocol methods to expose the underlying REST operations. You can learn more about how to use Azure SDK clients which use protocol methods in our documentation.
Thread safety
We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing client instances is always safe, even across threads.
Additional concepts
Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime
##Examples
Data Provider Examples
The following code examples demonstrate how data providers can use the Microsoft Azure Java SDK for Purview Sharing to manage their sharing activity.
Create a Sent Share Client
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var sentShareClient = new SentSharesClient(endPoint, credential);
Create a Sent Share
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var sentShareClient = new SentSharesClient(endPoint, credential);
var data = new
{
shareKind = "InPlace",
properties = new
{
artifact = new
{
storeKind = "AdlsGen2Account",
storeReference = new
{
referenceName = "/subscriptions/subscriptionId/resourceGroups/resourceGroup/providers/Microsoft.Storage/storageAccounts/sharerStorageAccount",
type = "ArmResourceReference"
},
properties = new
{
paths = new[]
{
new
{
containerName = "containerName",
senderPath = "senderPath",
receiverPath = "receiverPath"
}
}
}
},
displayName = "displayName",
description = "description",
}
};
Operation<BinaryData> createResponse = await sentShareClient.CreateOrReplaceSentShareAsync(WaitUntil.Completed, "sentShareId", RequestContent.Create(data));
Get a Sent Share
After creating a sent share, data providers can retrieve it.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var sentShareClient = new SentSharesClient(endPoint, credential);
Response response = await sentShareClient.GetSentShareAsync("sentShareId");
List Sent Shares
Data providers can also retrieve a list of the sent shares they have created.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var sentShareClient = new SentSharesClient(endPoint, credential);
List<BinaryData> response = await sentShareClient.GetAllSentSharesAsync("referenceName").ToEnumerableAsync();
Create a Share Invitation to a User
After creating a sent share, the data provider can extend invitations to consumers who may then view the shared data. In this example, an invitation is extended to an individual by specifying their email address.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var sentShareClient = new SentSharesClient(endPoint, credential);
var data = new
{
invitationKind = "User",
properties = new
{
TargetEmail = "receiver@microsoft.com",
Notify = true,
}
};
Response response = await sentShareClient.CreateSentShareInvitationAsync("sentShareId", "sentShareInvitationId", RequestContent.Create(data));
Create a Share Invitation to a Service
Data providers can also extend invitations to services or applications by specifying the tenant id and object id of the service. The object id used for sending an invitation to a service must be the object id associated with the Enterprise Application (not the application registration).
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var sentShareClient = new SentSharesClient(endPoint, credential);
var data = new
{
invitationKind = "Service",
properties = new
{
TargetActiveDirectoryId = "targetActiveDirectoryId",
TargetObjectId = "targetObjectId",
}
};
Response response = await sentShareClient.CreateSentShareInvitationAsync("sentShareId", "sentShareInvitationId", RequestContent.Create(data));
Get a sent share invitation
After creating a sent share invitation, data providers can retrieve it.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var sentShareClient = new SentSharesClient(endPoint, credential);
Response response = await sentShareClient.GetSentShareInvitationAsync("sentShareId", "sentShareInvitationId");
List sent share invitations
Data providers can also retrieve a list of the sent share invitations they have created.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var sentShareClient = new SentSharesClient(endPoint, credential);
List<BinaryData> sentShareInvitations = await sentShareClient.GetAllSentShareInvitationsAsync("sentShareId").ToEnumerableAsync();
Delete a sent share invitation
Data providers can also retrieve a list of the sent share invitations they have created.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var sentShareClient = new SentSharesClient(endPoint, credential);
Operation operation = await sentShareClient.DeleteSentShareInvitationAsync(WaitUntil.Completed, "sentShareId", "sentShareInvitationId");
Delete a sent share
A sent share can be deleted by the data provider to stop sharing their data with all data consumers.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var sentShareClient = new SentSharesClient(endPoint, credential);
Operation operation = await sentShareClient.DeleteSentShareAsync(WaitUntil.Completed, "sentShareId");
Data Consumer Examples
The following code examples demonstrate how data consumers can use the Microsoft Azure Java SDK for Purview Sharing to manage their sharing activity.
Create a Receive Share Client
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var receivedSharesClient = new ReceivedSharesClient(endPoint, credential);
List detached received shares
To begin viewing data shared with them, a data consumer must first retrieve a list of detached received shares. Within this list, they can identify a detached received share to attach.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var receivedSharesClient = new ReceivedSharesClient(endPoint, credential);
List<BinaryData> createResponse = await receivedSharesClient.GetAllDetachedReceivedSharesAsync().ToEnumerableAsync();
Attach a received share
Once the data consumer has identified a received share, they can attach the received share to a location where they can access the shared data. If the received share is already attached, the shared data will be made accessible at the new location specified.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var receivedSharesClient = new ReceivedSharesClient(endPoint, credential);
var data = new
{
shareKind = "InPlace",
properties = new
{
sink = new
{
storeKind = "AdlsGen2Account",
storeReference = new
{
referenceName = "/subscriptions/suscriptionId/resourceGroups/resourceGroup/providers/Microsoft.Storage/storageAccounts/receiverStorageAccount",
type = "ArmResourceReference"
},
properties = new
{
containerName = "containerName",
folder = "folder",
mountPath = "mountPath",
}
},
displayName = "displayName",
}
};
Operation<BinaryData> createResponse = await receivedSharesClient.CreateOrReplaceReceivedShareAsync(WaitUntil.Completed, "receivedShareId", RequestContent.Create(data));
Get a received share
A data consumer can retrieve an individual received share.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var receivedSharesClient = new ReceivedSharesClient(endPoint, credential);
Response operation = await receivedSharesClient.GetReceivedShareAsync("receivedShareId");
List attached received shares
Data consumers can also retrieve a list of their attached received shares.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var receivedSharesClient = new ReceivedSharesClient(endPoint, credential);
List<BinaryData> createResponse = await receivedSharesClient.GetAllAttachedReceivedSharesAsync("referenceName").ToEnumerableAsync();
Delete a received share
Data consumers can also retrieve a list of their attached received shares.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var receivedSharesClient = new ReceivedSharesClient(endPoint, credential);
Operation operation = await receivedSharesClient.DeleteReceivedShareAsync(WaitUntil.Completed, "receivedShareId");
Share Resouce Examples
The following code examples demonstrate how to use the Microsoft Azure Java SDK for Purview Sharing to view share resources. A share resource is the underlying resource from which a provider shares data or the destination where a consumer attaches data shared with them.
List share resources
A list of share resources can be retrieved to view all resources within an account where sharing activities have taken place.
var credential = new DefaultAzureCredential();
var endPoint = new Uri("https://my-account-name.purview.azure.com/share");
var shareResourcesClient = new ShareResourcesClient(endPoint, credential);
List<BinaryData> createResponse = await shareResourcesClient.GetAllShareResourcesAsync().ToEnumerableAsync();
Troubleshooting
Setting up console logging
The simplest way to see the logs is to enable the console logging. To create an Azure SDK log listener that outputs messages to console use AzureEventSourceListener.CreateConsoleLogger method.
// Setup a listener to monitor logged events.
using AzureEventSourceListener listener = AzureEventSourceListener.CreateConsoleLogger();
To learn more about other logging mechanisms see here.
Next steps
This client SDK exposes operations using protocol methods, you can learn more about how to use SDK Clients which use protocol methods in our documentation.
Contributing
See the CONTRIBUTING.md for details on building, testing, and contributing to this library.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Azure SDK for .NET