Esempio n. 1
0
        /// <summary>
        /// Azure DataLakeGen2 Item constructor
        /// </summary>
        /// <param name="blobDir">Cloud blob Directory object</param>
        public AzureDataLakeGen2Item(DataLakeDirectoryClient directoryClient)
        {
            Name        = directoryClient.Name;
            Path        = directoryClient.Path;
            Directory   = directoryClient;
            IsDirectory = true;
            if (directoryClient.Path != "/" || string.IsNullOrEmpty(directoryClient.Path)) //if root directory, GetProperties() will fail. Skip until this is fixed.
            {
                try
                {
                    Properties   = directoryClient.GetProperties();
                    Length       = Properties.ContentLength;
                    ContentType  = Properties.ContentType;
                    LastModified = Properties.LastModified;
                }
                catch (global::Azure.RequestFailedException e) when(e.Status == 403 || e.Status == 404)
                {
                    // skip get dir properties if don't have read permission
                }
            }

            try
            {
                AccessControl = directoryClient.GetAccessControl();
                Permissions   = AccessControl.Permissions;
                ACL           = PSPathAccessControlEntry.ParsePSPathAccessControlEntrys(AccessControl.AccessControlList);
                Owner         = AccessControl.Owner;
                Group         = AccessControl.Group;
            }
            catch (global::Azure.RequestFailedException e) when(e.Status == 403 || e.Status == 404)
            {
                // skip get dir ACL if don't have read permission
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Azure DataLakeGen2 Item constructor
        /// </summary>
        /// <param name="item">datalake gen2 listout item</param>
        public AzureDataLakeGen2Item(PathItem item, DataLakeFileSystemClient fileSystem, bool fetchProperties = false)
        {
            this.Name         = item.Name;
            this.Path         = item.Name;
            this.ListPathItem = item;
            this.IsDirectory  = item.IsDirectory is null ? false : item.IsDirectory.Value;
            DataLakePathClient pathclient = null;

            if (this.IsDirectory) // Directory
            {
                this.Directory = fileSystem.GetDirectoryClient(item.Name);
                pathclient     = this.Directory;
            }
            else //File
            {
                this.File  = fileSystem.GetFileClient(item.Name);
                pathclient = this.File;
            }

            this.Owner        = item.Owner;
            this.Group        = item.Group;
            this.Permissions  = PathPermissions.ParseSymbolicPermissions(item.Permissions);
            this.LastModified = item.LastModified;
            this.Length       = item.ContentLength is null ? 0 : item.ContentLength.Value;

            if (fetchProperties)
            {
                this.Properties    = pathclient.GetProperties();
                this.AccessControl = pathclient.GetAccessControl();
                this.ACL           = PSPathAccessControlEntry.ParsePSPathAccessControlEntrys(this.AccessControl.AccessControlList);
                this.ContentType   = Properties.ContentType;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Azure DataLakeGen2 Item constructor
 /// </summary>
 /// <param name="blob">CloudBlockBlob blob object</param>
 public AzureDataLakeGen2Item(DataLakeFileClient fileClient)
 {
     Name        = fileClient.Name;
     Path        = fileClient.Path;
     File        = fileClient;
     IsDirectory = false;
     try
     {
         Properties   = fileClient.GetProperties();
         Length       = Properties.ContentLength;
         ContentType  = Properties.ContentType;
         LastModified = Properties.LastModified;
     }
     catch (global::Azure.RequestFailedException e) when(e.Status == 403 || e.Status == 404)
     {
         // skip get file properties if don't have read permission
     }
     try
     {
         AccessControl = File.GetAccessControl();
         Permissions   = AccessControl.Permissions;
         ACL           = PSPathAccessControlEntry.ParsePSPathAccessControlEntrys(AccessControl.AccessControlList);
         Owner         = AccessControl.Owner;
         Group         = AccessControl.Group;
     }
     catch (global::Azure.RequestFailedException e) when(e.Status == 403 || e.Status == 404)
     {
         // skip get file ACL if don't have read permission
     }
 }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            List <PSPathAccessControlEntry> psacls = new List <PSPathAccessControlEntry>();

            if (InputObject != null)
            {
                psacls = new List <PSPathAccessControlEntry>(this.InputObject);
            }

            // Remove the ACL entry to add if already exist, to avoid duplicated entries
            PSPathAccessControlEntry entryToRemove = null;

            foreach (PSPathAccessControlEntry entry in psacls)
            {
                if (entry.DefaultScope == this.DefaultScope.IsPresent &&
                    entry.AccessControlType == this.AccessControlType &&
                    entry.EntityId == this.EntityId)
                {
                    entryToRemove = entry;
                }
            }
            if (entryToRemove != null)
            {
                psacls.Remove(entryToRemove);
            }

            PSPathAccessControlEntry psacl = new PSPathAccessControlEntry(this.AccessControlType, PathAccessControlExtensions.ParseSymbolicRolePermissions(this.Permission), this.DefaultScope, this.EntityId);

            psacls.Add(psacl);

            WriteObject(psacls.ToArray(), true);
        }
Esempio n. 5
0
 /// <summary>
 /// Azure DataLakeGen2 Item constructor
 /// </summary>
 /// <param name="blob">CloudBlockBlob blob object</param>
 public AzureDataLakeGen2Item(DataLakeFileClient fileClient)
 {
     Name          = fileClient.Name;
     Path          = fileClient.Path;
     File          = fileClient;
     Properties    = fileClient.GetProperties();
     AccessControl = File.GetAccessControl();
     Length        = Properties.ContentLength;
     ContentType   = Properties.ContentType;
     LastModified  = Properties.LastModified;
     IsDirectory   = false;
     Permissions   = AccessControl.Permissions;
     ACL           = PSPathAccessControlEntry.ParsePSPathAccessControlEntrys(AccessControl.AccessControlList);
     Owner         = AccessControl.Owner;
     Group         = AccessControl.Group;
 }
        /// <summary>
        /// Remove ACL recusive async function
        /// </summary>
        protected override async Task OperationAclResusive(long taskId)
        {
            IStorageBlobManagement localChannel = Channel;

            progressRecord    = GetProgressRecord("Remove", 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(), "Remove Acl recursively on Directory: "))
                {
                    WriteWarning("To find the ACL Entry to remove, will only compare AccessControlType, DefaultScope and EntityId, will omit Permission.");
                    await dirClient.RemoveAccessControlRecursiveAsync(PSPathAccessControlEntry.ParseRemoveAccessControls(this.Acl),
                                                                      continuationToken,
                                                                      GetAccessControlChangeOptions(taskId),
                                                                      CmdletCancellationToken).ConfigureAwait(false);

                    SetProgressComplete();
                    WriteResult(taskId);
                }
            }
            else
            {
                if (ShouldProcess(fileClient.Uri.ToString(), "Remove Acl recursively on File: "))
                {
                    WriteWarning("To find the ACL Entry to remove, will only compare AccessControlType, DefaultScope and EntityId, will omit Permission.");
                    await fileClient.RemoveAccessControlRecursiveAsync(PSPathAccessControlEntry.ParseRemoveAccessControls(this.Acl),
                                                                       continuationToken,
                                                                       GetAccessControlChangeOptions(taskId),
                                                                       CmdletCancellationToken).ConfigureAwait(false);

                    SetProgressComplete();
                    WriteResult(taskId);
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Azure DataLakeGen2 Item constructor
 /// </summary>
 /// <param name="blobDir">Cloud blob Directory object</param>
 public AzureDataLakeGen2Item(DataLakeDirectoryClient directoryClient)
 {
     Name        = directoryClient.Name;
     Path        = directoryClient.Path;
     Directory   = directoryClient;
     IsDirectory = true;
     if (directoryClient.Path != "/") //if root directory, GetProperties() will fail. Skip until this is fixed.
     {
         Properties   = directoryClient.GetProperties();
         Length       = Properties.ContentLength;
         ContentType  = Properties.ContentType;
         LastModified = Properties.LastModified;
     }
     AccessControl = directoryClient.GetAccessControl();
     Permissions   = AccessControl.Permissions;
     ACL           = PSPathAccessControlEntry.ParsePSPathAccessControlEntrys(AccessControl.AccessControlList);
     Owner         = AccessControl.Owner;
     Group         = AccessControl.Group;
 }
        /// <summary>
        /// execute command
        /// </summary>
        public override void ExecuteCmdlet()
        {
            IStorageBlobManagement localChannel = Channel;

            bool foundAFolder = false;

            DataLakeFileClient      fileClient = null;
            DataLakeDirectoryClient dirClient  = null;

            if (ParameterSetName == ManualParameterSet)
            {
                DataLakeFileSystemClient fileSystem = GetFileSystemClientByName(localChannel, this.FileSystem);
                foundAFolder = GetExistDataLakeGen2Item(fileSystem, this.Path, out fileClient, out dirClient);
            }
            else //BlobParameterSet
            {
                if (!InputObject.IsDirectory)
                {
                    fileClient = InputObject.File;
                }
                else
                {
                    dirClient    = InputObject.Directory;
                    foundAFolder = true;
                }
            }

            if (foundAFolder)
            {
                if (ShouldProcess(GetDataLakeItemUriWithoutSas(dirClient), "Update Directory: "))
                {
                    //Set Permission
                    if (this.Permission != null || this.Owner != null || this.Group != null)
                    {
                        //PathAccessControl originPathAccessControl = dirClient.GetAccessControl().Value;
                        dirClient.SetPermissions(
                            this.Permission != null ? PathPermissions.ParseSymbolicPermissions(this.Permission) : null,
                            this.Owner,
                            this.Group);
                    }

                    //Set ACL
                    if (this.Acl != null)
                    {
                        dirClient.SetAccessControlList(PSPathAccessControlEntry.ParseAccessControls(this.Acl));
                    }

                    // Set Properties
                    SetDatalakegen2ItemProperties(dirClient, this.BlobProperties, setToServer: true);

                    //Set MetaData
                    SetDatalakegen2ItemMetaData(dirClient, this.BlobMetadata, setToServer: true);

                    WriteDataLakeGen2Item(localChannel, dirClient);
                }
            }
            else
            {
                if (ShouldProcess(GetDataLakeItemUriWithoutSas(fileClient), "Update File: "))
                {
                    //Set Permission
                    if (this.Permission != null || this.Owner != null || this.Group != null)
                    {
                        fileClient.SetPermissions(
                            this.Permission != null ? PathPermissions.ParseSymbolicPermissions(this.Permission) : null,
                            this.Owner,
                            this.Group);
                    }

                    //Set ACL
                    if (this.Acl != null)
                    {
                        fileClient.SetAccessControlList(PSPathAccessControlEntry.ParseAccessControls(this.Acl));
                    }

                    // Set Properties
                    SetDatalakegen2ItemProperties(fileClient, this.BlobProperties, setToServer: true);

                    //Set MetaData
                    SetDatalakegen2ItemMetaData(fileClient, this.BlobMetadata, setToServer: true);

                    WriteDataLakeGen2Item(localChannel, fileClient);
                }
            }
        }