Exemplo n.º 1
0
        public void ParseSymbolicPermissions()
        {
            AssertPathPermissionsEquality(new PathPermissions(
                                              owner: AllPermissions,
                                              group: AllPermissions,
                                              other: AllPermissions),
                                          PathPermissions.ParseSymbolicPermissions("rwxrwxrwx"));

            AssertPathPermissionsEquality(new PathPermissions(
                                              owner: AllPermissions,
                                              group: AllPermissions,
                                              other: AllPermissions,
                                              stickyBit: true),
                                          PathPermissions.ParseSymbolicPermissions("rwxrwxrwt"));

            AssertPathPermissionsEquality(new PathPermissions(
                                              owner: AllPermissions,
                                              group: AllPermissions,
                                              other: AllPermissions,
                                              extendedInfoInAcl: true),
                                          PathPermissions.ParseSymbolicPermissions("rwxrwxrwx+"));

            AssertPathPermissionsEquality(new PathPermissions(
                                              owner: AllPermissions,
                                              group: AllPermissions,
                                              other: AllPermissions,
                                              stickyBit: true,
                                              extendedInfoInAcl: true),
                                          PathPermissions.ParseSymbolicPermissions("rwxrwxrwt+"));
        }
Exemplo 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;
            }
        }
Exemplo n.º 3
0
 public void AssertPathPermissionsEquality(PathPermissions expected, PathPermissions actual)
 {
     Assert.AreEqual(expected.Owner, actual.Owner);
     Assert.AreEqual(expected.Group, actual.Group);
     Assert.AreEqual(expected.Other, actual.Other);
     Assert.AreEqual(expected.StickyBit, actual.StickyBit);
     Assert.AreEqual(expected.ExtendedAcls, actual.ExtendedAcls);
 }
    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    //  The helper methods
    //////////////////////////////////////////////////////////////////////////////////////////////////////////


    private PathPermissions GetPermissions(string physicalPath)
    {
        PathPermissions permission = PathPermissions.Read;

        permission = CheckPermissions(physicalPath, PathPermissions.Delete) ? permission | PathPermissions.Delete : permission;
        permission = CheckPermissions(physicalPath, PathPermissions.Upload) ? permission | PathPermissions.Upload : permission;

        return(permission);
    }
Exemplo n.º 5
0
            /// <summary>
            /// Gets the directory.
            /// </summary>
            /// <param name="dir">The dir.</param>
            /// <param name="virtualName">Name of the virtual.</param>
            /// <param name="location">The location.</param>
            /// <param name="fullPath">The full path.</param>
            /// <param name="tag">The tag.</param>
            /// <returns></returns>
            public DirectoryItem GetDirectory(DirectoryInfo dir, string virtualName, string location, string fullPath, string tag)
            {
                PathPermissions permissions = this._contentProvider.GetPermissions(fullPath);
                bool            flag        = this.IsListMode ? this.IncludeDirectories : this.IsParentOf(fullPath, this.SelectedUrl);
                bool            flag2       = this.IsParentOf(fullPath, this.SelectedUrl);

                DirectoryItem[] directories = flag ? this.GetDirectories(dir, fullPath) : new DirectoryItem[0];
                return(new DirectoryItem(virtualName, location, fullPath, tag, permissions, flag2 ? this.GetFiles(dir, permissions, fullPath + "/") : new FileItem[0], directories));
            }
Exemplo n.º 6
0
        public void ParseOctalPermissions_invalid()
        {
            TestHelper.AssertExpectedException(
                () => PathPermissions.ParseOctalPermissions("777"),
                new ArgumentException("s must be 4 characters.  Value is \"777\""));

            TestHelper.AssertExpectedException(
                () => PathPermissions.ParseOctalPermissions("3777"),
                new ArgumentException("First digit of s must be 0 or 1.  Value is \"3777\""));
        }
Exemplo n.º 7
0
            public DirectoryItem GetDirectory(DirectoryInfo dir, string virtualName, string location, string fullPath,
                                              string tag)
            {
                PathPermissions permissions     = _contentProvider.GetPermissions(fullPath);
                bool            showDirictories = IsListMode ? IncludeDirectories : IsParentOf(fullPath, SelectedUrl);
                bool            showFiles       = IsParentOf(fullPath, SelectedUrl);

                DirectoryItem[] directories = showDirictories ? GetDirectories(dir, fullPath) : new DirectoryItem[0];
                return(new DirectoryItem(virtualName, location, fullPath, tag, permissions,
                                         showFiles ? GetFiles(dir, permissions, fullPath + "/") : new FileItem[0], directories));
            }
Exemplo n.º 8
0
        protected PathPermissions GetPermissions(string path)
        {
            PathPermissions read = PathPermissions.Read;

            if (this.CanUpload(path))
            {
                read |= PathPermissions.Upload;
            }
            if (this.CanDelete(path))
            {
                read |= PathPermissions.Delete;
            }
            return(read);
        }
Exemplo n.º 9
0
        private FileItem[] GetFiles(PathPermissions permissions)
        {
            if (_allItems == null)
            {
                return(new FileItem[0]);
            }

            return
                (_allItems.Where(o => !o.IsFolder)
                 .Select(
                     item =>
                     new FileItem(item.Name, Path.GetExtension(item.Name), item.Size, "", item.Url, "",
                                  permissions))
                 .ToArray());
        }
Exemplo n.º 10
0
    private PathPermissions GetPermissions(string folderPath)
    {
        PathPermissions permissions = PathPermissions.Read;

        if (CheckDeletePermissions(folderPath))
        {
            permissions = PathPermissions.Delete | permissions;
        }
        if (CheckWritePermissions(folderPath))
        {
            permissions = PathPermissions.Upload | permissions;
        }

        return(permissions);
    }
Exemplo n.º 11
0
        public void ParseOctalPermissions()
        {
            AssertPathPermissionsEquality(new PathPermissions(
                                              owner: AllPermissions,
                                              group: AllPermissions,
                                              other: AllPermissions),
                                          PathPermissions.ParseOctalPermissions("0777"));

            AssertPathPermissionsEquality(new PathPermissions(
                                              owner: AllPermissions,
                                              group: AllPermissions,
                                              other: AllPermissions,
                                              stickyBit: true),
                                          PathPermissions.ParseOctalPermissions("1777"));
        }
Exemplo n.º 12
0
        private DirectoryItem GetDir(string path)
        {
            const PathPermissions PERMISSIONS = (PathPermissions)7;
            var dir   = GetChildDirs();
            var files = GetFiles(PERMISSIONS);

            return(new DirectoryItem
            {
                Name = Path.GetFileName(path),
                FullPath = path,
                Path = path,
                Location = "",
                Directories = dir,
                Files = files,
                Tag = "",
                Permissions = PERMISSIONS
            });
        }
Exemplo n.º 13
0
            protected FileItem[] GetFiles(DirectoryInfo directory, PathPermissions permissions, string location)
            {
                ArrayList list      = new ArrayList();
                Hashtable hashtable = new Hashtable();

                foreach (string str in this._contentProvider.SearchPatterns)
                {
                    foreach (FileInfo info in directory.GetFiles(str))
                    {
                        if (!hashtable.ContainsKey(info.FullName) && this._contentProvider.IsValid(info))
                        {
                            hashtable.Add(info.FullName, string.Empty);
                            string tag = this.IsListMode ? (location + info.Name) : string.Empty;
                            list.Add(new FileItem(info.Name, info.Extension, info.Length, string.Empty, string.Empty, tag, permissions));
                        }
                    }
                }
                return((FileItem[])list.ToArray(typeof(FileItem)));
            }
    private bool CheckPermissions(string folderPath, PathPermissions permToCheck)
    {
        //add a ending slash to the upload folder
        folderPath = folderPath.TrimEnd(PhysicalPathSeparator) + PhysicalPathSeparator;


        string[] pathsToCheck;
        if ((permToCheck & PathPermissions.Upload) != 0)
        {
            pathsToCheck = UploadPaths;
        }
        else if ((permToCheck & PathPermissions.Delete) != 0)
        {
            pathsToCheck = DeletePaths;
        }
        else
        {
            pathsToCheck = ViewPaths;
        }


        //Compare the 'folderPath' to all paths in the 'pathsToCheck' collection and check if it is a child or one of them.
        foreach (string pathToCheck in pathsToCheck)
        {
            if (!String.IsNullOrEmpty(pathToCheck) && folderPath.StartsWith(pathToCheck, StringComparison.OrdinalIgnoreCase))
            {
                // Remove trailing slash from the path
                string trimmedPath = pathToCheck.TrimEnd(PhysicalPathSeparator);
                //if (trimmedPath.Length == 0)
                //{
                //    //Path contains only the Path separator ==> give permissions everywhere
                //    return true;
                //}
                if (folderPath.Length > trimmedPath.Length && folderPath[trimmedPath.Length] == PhysicalPathSeparator)
                {
                    return(true);
                }
            }
        }
        return(false);
    }
        public void SetPermissions()
        {
            // 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-acl" and then create it
            DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem-per"));

            filesystem.Create();
            try
            {
                #region Snippet:SampleSnippetDataLakeFileClient_SetPermissions
                // Create a DataLake file so we can set the Access Controls on the files
                DataLakeFileClient fileClient = filesystem.GetFileClient(Randomize("sample-file"));
                fileClient.Create();

                // Set the Permissions of the file
                PathPermissions pathPermissions = PathPermissions.ParseSymbolicPermissions("rwxrwxrwx");
                fileClient.SetPermissions(permissions: pathPermissions);
                #endregion Snippet:SampleSnippetDataLakeFileClient_SetPermissions

                // Get Access Control List
                PathAccessControl accessControlResponse = fileClient.GetAccessControl();

                // 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
                filesystem.Delete();
            }
        }
Exemplo n.º 16
0
	private bool CheckPermissions(string folderPath, PathPermissions permToCheck)
	{
		//add a ending slash to the upload folder
		folderPath = folderPath.TrimEnd(PhysicalPathSeparator) + PhysicalPathSeparator;


		string[] pathsToCheck;
		if ((permToCheck & PathPermissions.Upload) != 0)
			pathsToCheck = UploadPaths;
		else if ((permToCheck & PathPermissions.Delete) != 0)
			pathsToCheck = DeletePaths;
		else
			pathsToCheck = ViewPaths;


		//Compare the 'folderPath' to all paths in the 'pathsToCheck' collection and check if it is a child or one of them.
		foreach (string pathToCheck in pathsToCheck)
		{
			if (!String.IsNullOrEmpty(pathToCheck) && folderPath.StartsWith(pathToCheck, StringComparison.OrdinalIgnoreCase))
			{
				// Remove trailing slash from the path
				string trimmedPath = pathToCheck.TrimEnd(PhysicalPathSeparator);
				//if (trimmedPath.Length == 0)
				//{
				//    //Path contains only the Path separator ==> give permissions everywhere
				//    return true;
				//}
				if (folderPath.Length > trimmedPath.Length && folderPath[trimmedPath.Length] == PhysicalPathSeparator)
				{
					return true;
				}
			}
		}
		return false;
	}
Exemplo n.º 17
0
 public void ParseSymbolicPermissions_invalid()
 {
     TestHelper.AssertExpectedException(
         () => PathPermissions.ParseSymbolicPermissions("rwxrwxrw"),
         new ArgumentException("s must be 9 or 10 characters.  Value is \"rwxrwxrw\""));
 }
        /// <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);
                }
            }
        }