private static void Main(string[] args) { Parser.Default.ParseArguments <CommandLineOptions>(args) .WithParsed(o => { if (o.DefaultConnectionLimit != null) { ServicePointManager.DefaultConnectionLimit = o.DefaultConnectionLimit.Value; } if (o.Expect100Continue != null) { ServicePointManager.Expect100Continue = o.Expect100Continue.Value; } var cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = cancellationTokenSource.Token; Task.Factory.StartNew(async() => { var file = await File.ReadAllTextAsync(o.ConfigurationPath); var directories = JsonConvert.DeserializeObject <List <DataLakeDirectory> >(file); var applyPermissions = new ApplyPermissions(o.StorageAccountName, o.SharedAccessKey); await applyPermissions.ProcessAsync(directories, cancellationToken); }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current) .Unwrap().Wait(); }); }
public void Setup() { _directories = new List <DataLakeDirectory> { new DataLakeDirectory { Path = "raw/directory", Upn = true, Recurse = true, Acls = new List <Acl> { new Acl { Read = true, Write = true, Execute = true, DefaultRead = true, DefaultWrite = true, DefaultExecute = true, Identity = "ea6be951-d694-4b49-bd5c-fef06e7b9a59", ObjectType = ObjectType.User }, new Acl { Read = true, Write = true, Execute = true, DefaultRead = true, DefaultWrite = true, DefaultExecute = true, Identity = "c20047f4-79e8-4446-b441-b1ea03a8e17d", ObjectType = ObjectType.User } } }, new DataLakeDirectory { Path = "trusted/directory", Upn = true, Recurse = true, Acls = new List <Acl> { new Acl { Read = true, Write = true, Execute = true, DefaultRead = true, DefaultWrite = true, DefaultExecute = true, Identity = "c20047f4-79e8-4446-b441-b1ea03a8e17d", ObjectType = ObjectType.User } } } }; var rawAccessControl = new AccessControl("$superuser", "$superuser", "rwxrwx---+", "user::rwx,user:c20047f4-79e8-4446-b441-b1ea03a8e17d:rwx,user:ea6be951-d694-4b49-bd5c-fef06e7b9a59:rwx,group::r-x,mask::rwx,other::---,default:user::rwx,default:user:c20047f4-79e8-4446-b441-b1ea03a8e17d:rwx,default:user:ea6be951-d694-4b49-bd5c-fef06e7b9a59:rwx,default:group::r-x,default:mask::rwx,default:other::---"); var trustedAccessControl = new AccessControl("$superuser", "$superuser", "rwxrwx---+", "user::rwx,user:c20047f4-79e8-4446-b441-b1ea03a8e17d:rwx,group::r-x,mask::rwx,other::---,default:user::rwx,default:user:c20047f4-79e8-4446-b441-b1ea03a8e17d:rwx,default:group::r-x,default:mask::rwx,default:other::---"); var file1AccessControl = new AccessControl("c20047f4-79e8-4446-b441-b1ea03a8e17d", "$superuser", "rw-r-----+", "user::rw-,user:c20047f4-79e8-4446-b441-b1ea03a8e17d:rwx,user:ea6be951-d694-4b49-bd5c-fef06e7b9a59:rwx,group::r-x,mask::r--,other::---"); var file2AccessControl = new AccessControl("c20047f4-79e8-4446-b441-b1ea03a8e17d", "$superuser", "rw-r-----+", "user::rw-,user:c20047f4-79e8-4446-b441-b1ea03a8e17d:rwx,user:ea6be951-d694-4b49-bd5c-fef06e7b9a59:rwx,group::r-x,mask::r--,other::---"); var subDirectoryAccessControl = new AccessControl("$superuser", "$superuser", "rwxrwx---+", "user::rwx,user:c20047f4-79e8-4446-b441-b1ea03a8e17d:rwx,user:ea6be951-d694-4b49-bd5c-fef06e7b9a59:rwx,group::r-x,mask::rwx,other::---,default:user::rwx,default:user:c20047f4-79e8-4446-b441-b1ea03a8e17d:rwx,default:user:ea6be951-d694-4b49-bd5c-fef06e7b9a59:rwx,default:group::r-x,default:mask::rwx,default:other::---"); var newAccessControl = new AccessControl("$superuser", "$superuser", "rwxr-x---", "user::rwx,group::r-x,other::---"); _azureDataLakeStorage = new Mock <IAzureDataLakeStorageWrapper>(); _azureDataLakeStorage.Setup(x => x.ExistsAsync("raw/directory", It.IsAny <CancellationToken>())) .Returns(Task.FromResult(true)); _azureDataLakeStorage.Setup(x => x.ExistsAsync("trusted/directory", It.IsAny <CancellationToken>())) .Returns(Task.FromResult(true)); _azureDataLakeStorage.Setup(x => x.ListFilesystemsAsync(It.IsAny <CancellationToken>())) .Returns(Task.FromResult( (IReadOnlyCollection <Filesystem>) new List <Filesystem> { new Filesystem { Name = "new" } }) ); _azureDataLakeStorage.Setup(x => x.GetAccessControlAsync("raw/directory", true, It.IsAny <CancellationToken>())) .Returns(Task.FromResult(rawAccessControl)); _azureDataLakeStorage.Setup(x => x.GetAccessControlAsync("trusted/directory", true, It.IsAny <CancellationToken>())) .Returns(Task.FromResult(trustedAccessControl)); _azureDataLakeStorage.Setup(x => x.GetAccessControlAsync("trusted/directory/file1.parquet", true, It.IsAny <CancellationToken>())) .Returns(Task.FromResult(file1AccessControl)); _azureDataLakeStorage.Setup(x => x.GetAccessControlAsync("trusted/directory/file2.parquet", true, It.IsAny <CancellationToken>())) .Returns(Task.FromResult(file2AccessControl)); _azureDataLakeStorage.Setup(x => x.GetAccessControlAsync("trusted/directory/subdirectory", true, It.IsAny <CancellationToken>())) .Returns(Task.FromResult(subDirectoryAccessControl)); _azureDataLakeStorage.Setup(x => x.GetAccessControlAsync("new", true, It.IsAny <CancellationToken>())) .Returns(Task.FromResult(newAccessControl)); _azureDataLakeStorage .Setup(x => x.SetAccessControlAsync(It.IsAny <string>(), It.IsAny <AccessControl>(), It.IsAny <CancellationToken>())) .Returns(Task.CompletedTask); _azureDataLakeStorage .Setup(x => x.ListAsync(It.Is <ListOptions>(y => y.FolderPath == "trusted/directory"), It.IsAny <CancellationToken>())) .Returns(Task.FromResult((IReadOnlyCollection <Blob>) new List <Blob> { new Blob("trusted/directory/file1.parquet"), new Blob("trusted/directory/file2.parquet"), new Blob("trusted/directory/subdirectory", BlobItemKind.Folder) })); _azureDataLakeStorage .Setup(x => x.ListAsync(It.Is <ListOptions>(y => y.FolderPath != "trusted/directory"), It.IsAny <CancellationToken>())) .Returns(Task.FromResult((IReadOnlyCollection <Blob>) new List <Blob>())); _logger = new Mock <ILogger>(); _sut = new ApplyPermissions(_azureDataLakeStorage.Object, _logger.Object); }