static async Task RemoveACLsForFile(DataLakeFileClient fileClient, AppSettings settings) { PathAccessControl fileAccessControl = await fileClient.GetAccessControlAsync(); List <PathAccessControlItem> accessControlList = RemoveACLs(fileAccessControl.AccessControlList, settings); await fileClient.SetAccessControlListAsync(accessControlList); }
static async Task ApplyACLsForFile(DataLakeFileClient fileClient, RolePermissions newACLs, AppSettings settings) { PathAccessControl fileAccessControl = await fileClient.GetAccessControlAsync(); List <PathAccessControlItem> accessControlList = UpdateACLs(fileAccessControl.AccessControlList, newACLs, settings); await fileClient.SetAccessControlListAsync(accessControlList); }
public async Task SetGetAclsAsync() { // Make StorageSharedKeyCredential to pass to the serviceClient string storageAccountName = NamespaceStorageAccountName; string storageAccountKey = NamespaceStorageAccountKey; Uri serviceUri = NamespaceBlobUri; StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey); // Create DataLakeServiceClient using StorageSharedKeyCredentials DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential); // Get a reference to a filesystem named "sample-filesystem-aclasync" and then create it DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem-acl")); await filesystem.CreateAsync(); try { // Create a DataLake file so we can set the Access Controls on the files DataLakeFileClient fileClient = filesystem.GetFileClient(Randomize("sample-file")); await fileClient.CreateAsync(); IList <PathAccessControlItem> accessControlList = PathAccessControlExtensions.ParseAccessControlList("user::rwx,group::r--,mask::rwx,other::---"); // Set Access Control List await fileClient.SetAccessControlListAsync(accessControlList); // Get Access Control List PathAccessControl accessControlResponse = await fileClient.GetAccessControlAsync(); // Check Access Control permissions Assert.AreEqual( PathAccessControlExtensions.ToAccessControlListString(accessControlList), PathAccessControlExtensions.ToAccessControlListString(accessControlResponse.AccessControlList.ToList())); } finally { // Clean up after the test when we're finished await filesystem.DeleteAsync(); } }
// </Snippet_ACLDirectory> #endregion #region Get and set file ACLs // --------------------------------------------------------- // Get and set ACLs on files //---------------------------------------------------------- // <Snippet_FileACL> public async Task ManageFileACLs(DataLakeFileSystemClient fileSystemClient) { DataLakeDirectoryClient directoryClient = fileSystemClient.GetDirectoryClient("my-directory"); DataLakeFileClient fileClient = directoryClient.GetFileClient("hello.txt"); PathAccessControl FileAccessControl = await fileClient.GetAccessControlAsync(); foreach (var item in FileAccessControl.AccessControlList) { Console.WriteLine(item.ToString()); } IList <PathAccessControlItem> accessControlList = PathAccessControlExtensions.ParseAccessControlList ("user::rwx,group::r-x,other::rw-"); fileClient.SetAccessControlList(accessControlList); }
public async Task SetPermissionsAsync() { // Make StorageSharedKeyCredential to pass to the serviceClient string storageAccountName = NamespaceStorageAccountName; string storageAccountKey = NamespaceStorageAccountKey; Uri serviceUri = NamespaceBlobUri; StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey); // Create DataLakeServiceClient using StorageSharedKeyCredentials DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential); // Get a reference to a filesystem named "sample-filesystem-aclasync" and then create it DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem-perasync")); await filesystem.CreateAsync(); try { // Create a DataLake file so we can set the Access Controls on the files DataLakeFileClient fileClient = filesystem.GetFileClient(Randomize("sample-file")); await fileClient.CreateAsync(); // Set the Permissions of the file PathPermissions pathPermissions = PathPermissions.ParseSymbolicPermissions("rwxrwxrwx"); await fileClient.SetPermissionsAsync(permissions : pathPermissions); // Get Access Control List PathAccessControl accessControlResponse = await fileClient.GetAccessControlAsync(); // Check Access Control permissions Assert.AreEqual(pathPermissions.ToSymbolicPermissions(), accessControlResponse.Permissions.ToSymbolicPermissions()); Assert.AreEqual(pathPermissions.ToOctalPermissions(), accessControlResponse.Permissions.ToOctalPermissions()); } finally { // Clean up after the test when we're finished await filesystem.DeleteAsync(); } }