Esempio n. 1
0
        // </Snippet_RemoveACLRecursively>

        #endregion

        #region Resume with event token

        // <Snippet_ResumeContinuationToken>
        public async Task <string> ResumeAsync(DataLakeServiceClient serviceClient,
                                               DataLakeDirectoryClient directoryClient,
                                               List <PathAccessControlItem> accessControlList,
                                               string continuationToken)
        {
            try
            {
                var accessControlChangeResult =
                    await directoryClient.SetAccessControlRecursiveAsync(
                        accessControlList, continuationToken : continuationToken, null);

                if (accessControlChangeResult.Value.Counters.FailedChangesCount > 0)
                {
                    continuationToken =
                        accessControlChangeResult.Value.ContinuationToken;
                }

                return(continuationToken);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(continuationToken);
            }
        }
Esempio n. 2
0
        // </Snippet_UpdateACL>

        #endregion

        #region Set ACLs recursively

        // <Snippet_SetACLRecursively>
        public async Task SetACLRecursively(DataLakeServiceClient serviceClient, bool isDefaultScope)
        {
            DataLakeDirectoryClient directoryClient =
                serviceClient.GetFileSystemClient("my-container").
                GetDirectoryClient("my-parent-directory");

            List <PathAccessControlItem> accessControlList =
                new List <PathAccessControlItem>()
            {
                new PathAccessControlItem(AccessControlType.User,
                                          RolePermissions.Read |
                                          RolePermissions.Write |
                                          RolePermissions.Execute, isDefaultScope),

                new PathAccessControlItem(AccessControlType.Group,
                                          RolePermissions.Read |
                                          RolePermissions.Execute, isDefaultScope),

                new PathAccessControlItem(AccessControlType.Other,
                                          RolePermissions.None, isDefaultScope),

                new PathAccessControlItem(AccessControlType.User,
                                          RolePermissions.Read |
                                          RolePermissions.Execute, isDefaultScope,
                                          entityId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"),
            };

            await directoryClient.SetAccessControlRecursiveAsync
                (accessControlList, null);
        }
        // If recursive is false, remove the ACL from a directory. None of the sub-directory or sub-path ACLs are updated
        // If recursive is true, remove ACLs from the directory and all sub-directories and sub-paths
        // When removing ACLs recursively, the ACLs on all sub-directories and sub-paths are replaced with this directory's ACL
        static async Task RemoveACLsForDirectory(DataLakeDirectoryClient directoryClient, AppSettings settings, bool recursive = false)
        {
            PathAccessControl directoryAccessControl =
                await directoryClient.GetAccessControlAsync();

            List <PathAccessControlItem> accessControlList = RemoveACLs(directoryAccessControl.AccessControlList, settings);

            if (recursive)
            {
                await directoryClient.SetAccessControlRecursiveAsync(accessControlList);
            }
            else
            {
                await directoryClient.SetAccessControlListAsync(accessControlList);
            }
        }
        // If recursive is false, apply ACLs to a directory. None of the sub-directory or sub-path ACLs are updated
        // If recursive is true, apply ACLs to the directory and all sub-directories and sub-paths
        // When applying ACL recursively, the ACLs on all sub-directories and sub-paths are replaced with this directory's ACL
        static async Task ApplyACLsForDirectory(DataLakeDirectoryClient directoryClient, RolePermissions newACLs, AppSettings settings, bool recursive = false)
        {
            PathAccessControl directoryAccessControl =
                await directoryClient.GetAccessControlAsync();

            List <PathAccessControlItem> accessControlList = UpdateACLs(directoryAccessControl.AccessControlList, newACLs, settings);

            if (recursive)
            {
                await directoryClient.SetAccessControlRecursiveAsync(accessControlList);
            }
            else
            {
                await directoryClient.SetAccessControlListAsync(accessControlList);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Set ACL recusive async function
        /// </summary>
        protected override async Task OperationAclResusive(long taskId)
        {
            IStorageBlobManagement localChannel = Channel;

            progressRecord    = GetProgressRecord("Set", taskId);
            continuationToken = this.ContinuationToken;

            bool foundAFolder = false;

            DataLakeFileClient      fileClient = null;
            DataLakeDirectoryClient dirClient  = null;

            DataLakeFileSystemClient fileSystem = GetFileSystemClientByName(localChannel, this.FileSystem);

            foundAFolder = GetExistDataLakeGen2Item(fileSystem, this.Path, out fileClient, out dirClient);


            if (foundAFolder)
            {
                if (ShouldProcess(dirClient.Uri.ToString(), "Set Acl recursively on Directory: "))
                {
                    await dirClient.SetAccessControlRecursiveAsync(PSPathAccessControlEntry.ParseAccessControls(this.Acl),
                                                                   continuationToken,
                                                                   GetAccessControlChangeOptions(taskId),
                                                                   CmdletCancellationToken).ConfigureAwait(false);

                    SetProgressComplete();
                    WriteResult(taskId);
                }
            }
            else
            {
                if (ShouldProcess(fileClient.Uri.ToString(), "Set Acl recursively on File: "))
                {
                    await fileClient.SetAccessControlRecursiveAsync(PSPathAccessControlEntry.ParseAccessControls(this.Acl),
                                                                    continuationToken,
                                                                    GetAccessControlChangeOptions(taskId),
                                                                    CmdletCancellationToken).ConfigureAwait(false);

                    SetProgressComplete();
                    WriteResult(taskId);
                }
            }
        }
Esempio n. 6
0
        // </Snippet_ResumeContinuationToken>

        #endregion

        #region Continue on failure

        // <Snippet_ContinueOnFailure>
        public async Task ContinueOnFailureAsync(DataLakeServiceClient serviceClient,
                                                 DataLakeDirectoryClient directoryClient,
                                                 List <PathAccessControlItem> accessControlList)
        {
            var accessControlChangeResult =
                await directoryClient.SetAccessControlRecursiveAsync(
                    accessControlList, null, new AccessControlChangeOptions()
            {
                ContinueOnFailure = true
            });

            var counters = accessControlChangeResult.Value.Counters;

            Console.WriteLine("Number of directories changed: " +
                              counters.ChangedDirectoriesCount.ToString());

            Console.WriteLine("Number of files changed: " +
                              counters.ChangedFilesCount.ToString());

            Console.WriteLine("Number of failures: " +
                              counters.FailedChangesCount.ToString());
        }