diff --git a/RestSetAcls/RestSetAcls/PrintUtils.ps1 b/RestSetAcls/RestSetAcls/PrintUtils.ps1 index e783bab..9221b4b 100644 --- a/RestSetAcls/RestSetAcls/PrintUtils.ps1 +++ b/RestSetAcls/RestSetAcls/PrintUtils.ps1 @@ -1,11 +1,11 @@ -function Ask([Parameter(Mandatory=$false)][string] $question) -{ +function Ask([Parameter(Mandatory = $false)][string] $question) { while ($true) { $yn = Read-Host "${question} [Y/n]" $yn = $yn.Trim().ToLower() if ($yn -eq 'n') { return $false - } elseif ($yn -eq '' -or $yn -eq 'y') { + } + elseif ($yn -eq '' -or $yn -eq 'y') { return $true } Write-Host "Invalid answer '$yn'. Answer with either 'y' or 'n'" -ForegroundColor Red @@ -35,7 +35,8 @@ function Write-DoneHeader { if (Get-SpecialCharactersPrintable) { $checkmark = [System.Char]::ConvertFromUtf32([System.Convert]::ToInt32("2713", 16)) Write-Host "($checkmark) Done: " -ForegroundColor Green -NoNewline - } else { + } + else { Write-Host "Done: " -ForegroundColor Green -NoNewline } } @@ -44,7 +45,8 @@ function Write-PartialHeader { if (Get-SpecialCharactersPrintable) { $cross = [System.Char]::ConvertFromUtf32([System.Convert]::ToInt32("2717", 16)) Write-Host "($cross) Partial: " -ForegroundColor Yellow -NoNewline - } else { + } + else { Write-Host "Partial: " -ForegroundColor Yellow -NoNewline } } @@ -53,7 +55,8 @@ function Write-FailedHeader { if (Get-SpecialCharactersPrintable) { $cross = [System.Char]::ConvertFromUtf32([System.Convert]::ToInt32("2717", 16)) Write-Host "($cross) Failed: " -ForegroundColor Red -NoNewline - } else { + } + else { Write-Host "Failed: " -ForegroundColor Red -NoNewline } } @@ -62,17 +65,18 @@ function Write-WarningHeader { if (Get-SpecialCharactersPrintable) { $warning = [System.Char]::ConvertFromUtf32([System.Convert]::ToInt32("26A0", 16)) Write-Host "($warning) Warning: " -ForegroundColor Yellow -NoNewline - } else { + } + else { Write-Host "Warning: " -ForegroundColor Yellow -NoNewline } } function Write-Failure { param ( - [Parameter(Mandatory=$true, Position=0)] + [Parameter(Mandatory = $true, Position = 0)] [string]$Overview, - [Parameter(Mandatory=$false)] + [Parameter(Mandatory = $false)] [string]$Details = $null ) @@ -83,3 +87,4 @@ function Write-Failure { Write-Host $Details -ForegroundColor Red } } + diff --git a/RestSetAcls/RestSetAcls/RestSetAcls.psd1 b/RestSetAcls/RestSetAcls/RestSetAcls.psd1 index f455282..096766e 100644 --- a/RestSetAcls/RestSetAcls/RestSetAcls.psd1 +++ b/RestSetAcls/RestSetAcls/RestSetAcls.psd1 @@ -8,141 +8,142 @@ @{ -# Script module or binary module file associated with this manifest. -RootModule = 'RestSetAcls.psm1' + # Script module or binary module file associated with this manifest. + RootModule = 'RestSetAcls.psm1' -# Version number of this module. -ModuleVersion = '0.1.2' + # Version number of this module. + ModuleVersion = '0.1.2' -# Supported PSEditions -# CompatiblePSEditions = @() + # Supported PSEditions + # CompatiblePSEditions = @() -# ID used to uniquely identify this module -GUID = '1b9ea644-06b1-47d4-8da4-f8758a43fc49' + # ID used to uniquely identify this module + GUID = '1b9ea644-06b1-47d4-8da4-f8758a43fc49' -# Author of this module -Author = 'Microsoft Corporation' + # Author of this module + Author = 'Microsoft Corporation' -# Company or vendor of this module -CompanyName = 'Microsoft Corporation' + # Company or vendor of this module + CompanyName = 'Microsoft Corporation' -# Copyright statement for this module -Copyright = '(c) Microsoft Corporation. All rights reserved.' + # Copyright statement for this module + Copyright = '(c) Microsoft Corporation. All rights reserved.' -# Description of the functionality provided by this module -Description = 'Set file permissions on an Azure Files share using REST API' + # Description of the functionality provided by this module + Description = 'Set file permissions on an Azure Files share using REST API' -# Minimum version of the PowerShell engine required by this module -PowerShellVersion = '5.1' + # Minimum version of the PowerShell engine required by this module + PowerShellVersion = '5.1' -# Name of the PowerShell host required by this module -# PowerShellHostName = '' + # Name of the PowerShell host required by this module + # PowerShellHostName = '' -# Minimum version of the PowerShell host required by this module -# PowerShellHostVersion = '' + # Minimum version of the PowerShell host required by this module + # PowerShellHostVersion = '' -# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# DotNetFrameworkVersion = '' + # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # DotNetFrameworkVersion = '' -# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# ClrVersion = '' + # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # ClrVersion = '' -# Processor architecture (None, X86, Amd64) required by this module -# ProcessorArchitecture = '' + # Processor architecture (None, X86, Amd64) required by this module + # ProcessorArchitecture = '' -# Modules that must be imported into the global environment prior to importing this module -RequiredModules = @( - @{ - ModuleName = "Az.Storage" - GUID = "dfa9e4ea-1407-446d-9111-79122977ab20" - ModuleVersion = "6.0.0" - } -) + # Modules that must be imported into the global environment prior to importing this module + RequiredModules = @( + @{ + ModuleName = "Az.Storage" + GUID = "dfa9e4ea-1407-446d-9111-79122977ab20" + ModuleVersion = "6.0.0" + } + ) -# Assemblies that must be loaded prior to importing this module -# RequiredAssemblies = @() + # Assemblies that must be loaded prior to importing this module + # RequiredAssemblies = @() -# Script files (.ps1) that are run in the caller's environment prior to importing this module. -# ScriptsToProcess = @() + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + # ScriptsToProcess = @() -# Type files (.ps1xml) to be loaded when importing this module -# TypesToProcess = @() + # Type files (.ps1xml) to be loaded when importing this module + # TypesToProcess = @() -# Format files (.ps1xml) to be loaded when importing this module -# FormatsToProcess = @() + # Format files (.ps1xml) to be loaded when importing this module + # FormatsToProcess = @() -# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess -# NestedModules = @() + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess + # NestedModules = @() -# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = @( - "Set-AzureFilesAclRecursive" -) + # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. + FunctionsToExport = @( + "Set-AzureFilesAclRecursive" + ) -# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. -CmdletsToExport = @() + # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. + CmdletsToExport = @() -# Variables to export from this module -VariablesToExport = '*' + # Variables to export from this module + VariablesToExport = '*' -# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. -AliasesToExport = @() + # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. + AliasesToExport = @() -# DSC resources to export from this module -# DscResourcesToExport = @() + # DSC resources to export from this module + # DscResourcesToExport = @() -# List of all modules packaged with this module -# ModuleList = @() + # List of all modules packaged with this module + # ModuleList = @() -# List of all files packaged with this module -# FileList = @() + # List of all files packaged with this module + # FileList = @() -# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. -PrivateData = @{ + # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + PrivateData = @{ - PSData = @{ + PSData = @{ - # Tags applied to this module. These help with module discovery in online galleries. - # See: https://learn.microsoft.com/en-us/powershell/gallery/concepts/publishing-guidelines?view=powershellget-3.x#tag-your-package-with-the-compatible-pseditions-and-platforms - Tags = @( - "Azure", - "Storage", - "ACL", - "PSEdition_Desktop", # Packages that are compatible with Windows PowerShell - "PSEdition_Core", # Packages that are compatible with PowerShell 6 and higher - "Windows" # Packages that are compatible with the Windows Operating System - ) + # Tags applied to this module. These help with module discovery in online galleries. + # See: https://learn.microsoft.com/en-us/powershell/gallery/concepts/publishing-guidelines?view=powershellget-3.x#tag-your-package-with-the-compatible-pseditions-and-platforms + Tags = @( + "Azure", + "Storage", + "ACL", + "PSEdition_Desktop", # Packages that are compatible with Windows PowerShell + "PSEdition_Core", # Packages that are compatible with PowerShell 6 and higher + "Windows" # Packages that are compatible with the Windows Operating System + ) - # A URL to the license for this module. - LicenseUri = 'https://raw.githubusercontent.com/Azure-Samples/azure-files-samples/master/LICENSE.md' + # A URL to the license for this module. + LicenseUri = 'https://raw.githubusercontent.com/Azure-Samples/azure-files-samples/master/LICENSE.md' - # A URL to the main website for this project. - ProjectUri = 'https://github.com/Azure-Samples/azure-files-samples' + # A URL to the main website for this project. + ProjectUri = 'https://github.com/Azure-Samples/azure-files-samples' - # A URL to an icon representing this module. - # IconUri = '' + # A URL to an icon representing this module. + # IconUri = '' - # ReleaseNotes of this module - # ReleaseNotes = '' + # ReleaseNotes of this module + # ReleaseNotes = '' - # Prerelease string of this module - # Prerelease = '' + # Prerelease string of this module + # Prerelease = '' - # Flag to indicate whether the module requires explicit user acceptance for install/update/save - # RequireLicenseAcceptance = $false + # Flag to indicate whether the module requires explicit user acceptance for install/update/save + # RequireLicenseAcceptance = $false - # External dependent modules of this module - # ExternalModuleDependencies = @() + # External dependent modules of this module + # ExternalModuleDependencies = @() - } # End of PSData hashtable + } # End of PSData hashtable -} # End of PrivateData hashtable + } # End of PrivateData hashtable -# HelpInfo URI of this module -# HelpInfoURI = '' + # HelpInfo URI of this module + # HelpInfoURI = '' -# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. -# DefaultCommandPrefix = '' + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + # DefaultCommandPrefix = '' } + diff --git a/RestSetAcls/RestSetAcls/RestSetAcls.psm1 b/RestSetAcls/RestSetAcls/RestSetAcls.psm1 index d14fe58..4cc76e6 100644 --- a/RestSetAcls/RestSetAcls/RestSetAcls.psm1 +++ b/RestSetAcls/RestSetAcls/RestSetAcls.psm1 @@ -4,13 +4,13 @@ function Write-LiveFilesAndFoldersProcessingStatus { [OutputType([int])] param ( - [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Object[]]$FileOrFolder, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [datetime]$StartTime, - [Parameter(Mandatory=$false)] + [Parameter(Mandatory = $false)] [int]$RefreshRateHertz = 10 ) @@ -65,16 +65,16 @@ function Write-LiveFilesAndFoldersProcessingStatus { function Write-FinalFilesAndFoldersProcessed { [OutputType([System.Void])] param ( - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [int]$ProcessedCount, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [hashtable]$Errors, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [timespan]$TotalTime, - [Parameter(Mandatory=$false)] + [Parameter(Mandatory = $false)] [int]$MaxErrorsToShow = 10 ) @@ -125,7 +125,8 @@ function Write-FinalFilesAndFoldersProcessed { Write-Host "errors.json" -ForegroundColor Blue Write-Host - } else { + } + else { $itemsPerSec = [math]::Round($successCount / $TotalTime.TotalSeconds, 1) Write-DoneHeader @@ -142,10 +143,10 @@ function Write-FinalFilesAndFoldersProcessed { function Write-SddlWarning { param ( - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [string]$Sddl, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [string]$NewSddl ) Write-WarningHeader @@ -168,19 +169,19 @@ function Write-SddlWarning { function Get-AzureFilesRecursive { param ( - [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageBase[]]$DirectoryContents, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext]$Context, - [Parameter(Mandatory=$false)] + [Parameter(Mandatory = $false)] [string]$DirectoryPath = "", - [Parameter(Mandatory=$false)] + [Parameter(Mandatory = $false)] [switch]$SkipFiles = $false, - [Parameter(Mandatory=$false)] + [Parameter(Mandatory = $false)] [switch]$SkipDirectories = $false ) @@ -212,7 +213,7 @@ function Get-AzureFilesRecursive { if (($isDirectory -and !$SkipDirectories) -or (!$isDirectory -and !$SkipFiles)) { Write-Output @{ FullPath = $fullPath - File = $file + File = $file } } } @@ -221,18 +222,18 @@ function Get-AzureFilesRecursive { function New-AzureFilePermission { [OutputType([string])] param ( - [Parameter(Mandatory=$true, HelpMessage="Azure storage context")] + [Parameter(Mandatory = $true, HelpMessage = "Azure storage context")] [Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext]$Context, - [Parameter(Mandatory=$true, HelpMessage="Name of the file share")] + [Parameter(Mandatory = $true, HelpMessage = "Name of the file share")] [string]$FileShareName, [Parameter( - Mandatory=$true, - HelpMessage="File permission in the Security Descriptor Definition Language (SDDL). " + - "SDDL must have an owner, group, and discretionary access control list (DACL). " + - "The provided SDDL string format of the security descriptor should not have " + - "domain relative identifier (like 'DU', 'DA', 'DD' etc) in it.")] + Mandatory = $true, + HelpMessage = "File permission in the Security Descriptor Definition Language (SDDL). " + + "SDDL must have an owner, group, and discretionary access control list (DACL). " + + "The provided SDDL string format of the security descriptor should not have " + + "domain relative identifier (like 'DU', 'DA', 'DD' etc) in it.")] [string]$Sddl ) @@ -244,10 +245,10 @@ function New-AzureFilePermission { function Get-AzureFilePermission { [OutputType([string])] param ( - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [string]$PermissionKey, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileShare]$Share ) @@ -256,10 +257,10 @@ function Get-AzureFilePermission { function Set-AzureFilePermission { param ( - [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageBase]$File, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [string]$SddlPermission ) @@ -269,7 +270,8 @@ function Set-AzureFilePermission { $null, # SmbProperties $SddlPermission # filePermission ) | Out-Null - } else { + } + else { $file = [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFile]$File $file.ShareFileClient.SetHttpHeaders( $null, # newSize @@ -282,10 +284,10 @@ function Set-AzureFilePermission { function Set-AzureFilePermissionKey { param ( - [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageBase]$File, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [string]$FilePermissionKey ) @@ -295,7 +297,8 @@ function Set-AzureFilePermissionKey { if ($File.GetType().Name -eq "AzureStorageFileDirectory") { $directory = [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileDirectory]$File $directory.ShareDirectoryClient.SetHttpHeaders($smbProperties) | Out-Null - } else { + } + else { $file = [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFile]$File $file.ShareFileClient.SetHttpHeaders( $null, # newSize @@ -308,14 +311,15 @@ function Set-AzureFilePermissionKey { function Get-AzureFilePermissionKey { [OutputType([string])] param ( - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageBase]$FileOrDirectory ) if ($FileOrDirectory.GetType().Name -eq "AzureStorageFileDirectory") { $directory = [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFileDirectory]$FileOrDirectory return $directory.ShareDirectoryProperties.SmbProperties.FilePermissionKey - } else { + } + else { $file = [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageFile]$FileOrDirectory return $file.FileProperties.SmbProperties.FilePermissionKey } @@ -324,31 +328,31 @@ function Get-AzureFilePermissionKey { function Set-AzureFilesAclRecursive { [CmdletBinding()] param ( - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext]$Context, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [string]$FileShareName, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [string]$FilePath, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [string]$SddlPermission, - [Parameter(Mandatory=$false)] + [Parameter(Mandatory = $false)] [bool]$Parallel = $true, - [Parameter(Mandatory=$false)] + [Parameter(Mandatory = $false)] [int]$ThrottleLimit = 10, - [Parameter(Mandatory=$false)] + [Parameter(Mandatory = $false)] [switch]$SkipFiles = $false, - [Parameter(Mandatory=$false)] + [Parameter(Mandatory = $false)] [switch]$SkipDirectories = $false, - [Parameter(Mandatory=$false)] + [Parameter(Mandatory = $false)] [switch]$WriteToPipeline = $false ) @@ -366,7 +370,8 @@ function Set-AzureFilesAclRecursive { # Try to parse SDDL permission, check for common issues try { $securityDescriptor = ConvertTo-RawSecurityDescriptor -Sddl $SddlPermission - } catch { + } + catch { Write-Failure "SDDL permission is invalid" return } @@ -399,7 +404,8 @@ function Set-AzureFilesAclRecursive { # Setting permission key should in theory also be slightly faster than setting SDDL directly (though this may not be noticeable in practice). try { $filePermissionKey = New-AzureFilePermission -Context $Context -FileShareName $FileShareName -Sddl $SddlPermission - } catch { + } + catch { Write-Failure "Failed to create file permission" -Details $_.Exception.Message return } @@ -410,7 +416,8 @@ function Set-AzureFilesAclRecursive { # If it's a directory, Get-AzureFilesRecursive will get its contents. try { $directory = Get-AzStorageFile -Context $Context -ShareName $FileShareName -Path $FilePath -ErrorAction Stop - } catch { + } + catch { Write-Failure "Failed to read root directory" -Details $_.Exception.Message return } @@ -434,7 +441,8 @@ function Set-AzureFilesAclRecursive { $errorMessage = "" try { Set-AzureFilePermissionKey -File $_.File -FilePermissionKey $using:filePermissionKey - } catch { + } + catch { $success = $false $errorMessage = $_.Exception.Message } @@ -442,16 +450,17 @@ function Set-AzureFilesAclRecursive { # Write full output if requested, otherwise write minimal output if ($using:WriteToPipeline) { Write-Output @{ - Time = (Get-Date).ToString("o") - FullPath = $_.FullPath - Permission = $using:SddlPermission - Success = $success + Time = (Get-Date).ToString("o") + FullPath = $_.FullPath + Permission = $using:SddlPermission + Success = $success ErrorMessage = $errorMessage } - } else { + } + else { Write-Output @{ - FullPath = $_.FullPath - Success = $success + FullPath = $_.FullPath + Success = $success ErrorMessage = $errorMessage } } @@ -466,7 +475,8 @@ function Set-AzureFilesAclRecursive { } ` | Write-LiveFilesAndFoldersProcessingStatus -RefreshRateHertz 10 -StartTime $startTime ` | ForEach-Object { if ($WriteToPipeline) { Write-Output $_ } } - } else { + } + else { Get-AzureFilesRecursive ` -Context $Context ` -DirectoryContents @($directory) ` @@ -480,7 +490,8 @@ function Set-AzureFilesAclRecursive { # Set the ACL try { Set-AzureFilePermissionKey -File $_.File -FilePermissionKey $filePermissionKey - } catch { + } + catch { $success = $false $errorMessage = $_.Exception.Message $errors[$fullPath] = $errorMessage @@ -491,16 +502,17 @@ function Set-AzureFilesAclRecursive { # Write full output if requested, otherwise write minimal output if ($WriteToPipeline) { Write-Output @{ - Time = (Get-Date).ToString("o") - FullPath = $fullPath - Permission = $SddlPermission - Success = $success + Time = (Get-Date).ToString("o") + FullPath = $fullPath + Permission = $SddlPermission + Success = $success ErrorMessage = $errorMessage } - } else { + } + else { Write-Output @{ - FullPath = $fullPath - Success = $success + FullPath = $fullPath + Success = $success ErrorMessage = $errorMessage } } @@ -515,3 +527,4 @@ function Set-AzureFilesAclRecursive { Write-Host "`r" -NoNewline # Clear the line from the live progress reporting Write-FinalFilesAndFoldersProcessed -ProcessedCount $processedCount -Errors $errors -TotalTime $totalTime } + diff --git a/RestSetAcls/RestSetAcls/SddlUtils.ps1 b/RestSetAcls/RestSetAcls/SddlUtils.ps1 index 9052e19..05665a4 100644 --- a/RestSetAcls/RestSetAcls/SddlUtils.ps1 +++ b/RestSetAcls/RestSetAcls/SddlUtils.ps1 @@ -1,6 +1,6 @@ function ConvertTo-RawSecurityDescriptor { param ( - [Parameter(Mandatory=$true, ValueFromPipeline=$true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [string]$sddl ) @@ -20,7 +20,7 @@ function ConvertTo-RawSecurityDescriptor { function ConvertFrom-RawSecurityDescriptor { param ( - [Parameter(Mandatory=$true, ValueFromPipeline=$true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [System.Security.AccessControl.RawSecurityDescriptor]$descriptor ) return $descriptor.GetSddlForm([System.Security.AccessControl.AccessControlSections]::All) @@ -28,13 +28,13 @@ function ConvertFrom-RawSecurityDescriptor { function Get-AllAceFlagsMatch { param ( - [Parameter(Mandatory=$true, ValueFromPipeline=$true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [System.Security.AccessControl.RawSecurityDescriptor]$SecurityDescriptor, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [System.Security.AccessControl.AceFlags]$EnabledFlags, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [System.Security.AccessControl.AceFlags]$DisabledFlags ) @@ -51,13 +51,13 @@ function Get-AllAceFlagsMatch { function Set-AceFlags { param ( - [Parameter(Mandatory=$true, ValueFromPipeline=$true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [System.Security.AccessControl.RawSecurityDescriptor]$SecurityDescriptor, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [System.Security.AccessControl.AceFlags]$EnableFlags, - [Parameter(Mandatory=$true)] + [Parameter(Mandatory = $true)] [System.Security.AccessControl.AceFlags]$DisableFlags ) @@ -77,7 +77,8 @@ function Set-AceFlags { $_.SecurityIdentifier, $_.IsCallback, $_.GetOpaque()) - } else { + } + else { throw "Unsupported ACE type: $($_.GetType().Name)" } } @@ -91,4 +92,4 @@ function Set-AceFlags { for ($i = 0; $i -lt $newAces.Count; $i++) { $SecurityDescriptor.DiscretionaryAcl.InsertAce($i, $newAces[$i]) | Out-Null } -} \ No newline at end of file +} diff --git a/RestSetAcls/build.depend.psd1 b/RestSetAcls/build.depend.psd1 index 8b10eb7..46a918f 100644 --- a/RestSetAcls/build.depend.psd1 +++ b/RestSetAcls/build.depend.psd1 @@ -1,13 +1,13 @@ # This file lists out development requirements for the module. # For the runtime requirements, see the module manifest. @{ - PSDependOptions = @{ - Target = 'bin\Dependencies' - Install = $true + PSDependOptions = @{ + Target = 'bin\Dependencies' + Install = $true AddToPath = $true } - Pester = 'latest' + Pester = 'latest' PSScriptAnalyzer = 'latest' - 'Az.Storage' = '6.0.0' -} \ No newline at end of file + 'Az.Storage' = '6.0.0' +} diff --git a/RestSetAcls/lint.ps1 b/RestSetAcls/lint.ps1 index ae714d0..eba6e7f 100644 --- a/RestSetAcls/lint.ps1 +++ b/RestSetAcls/lint.ps1 @@ -1,8 +1,10 @@ -Invoke-ScriptAnalyzer -Path $PSScriptRoot\RestSetAcls -Severity Warning -Recurse -Outvariable issues -$errors = $issues.Where({$_.Severity -eq 'Error'}) -$warnings = $issues.Where({$_.Severity -eq 'Warning'}) +Invoke-ScriptAnalyzer -Path $PSScriptRoot\RestSetAcls -Severity Warning -Recurse -OutVariable issues +$errors = $issues.Where({ $_.Severity -eq 'Error' }) +$warnings = $issues.Where({ $_.Severity -eq 'Warning' }) if ($errors) { Write-Error "There were $($errors.Count) errors and $($warnings.Count) warnings total." -ErrorAction Stop -} else { +} +else { Write-Output "There were $($errors.Count) errors and $($warnings.Count) warnings total." } + diff --git a/RestSetAcls/test/TestSetup.ps1 b/RestSetAcls/test/TestSetup.ps1 index 1d91298..6d06276 100644 --- a/RestSetAcls/test/TestSetup.ps1 +++ b/RestSetAcls/test/TestSetup.ps1 @@ -1,5 +1,4 @@ -function New-Arborescence -{ +function New-Arborescence { [CmdletBinding(SupportsShouldProcess)] param ( [Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext]$context, @@ -10,18 +9,17 @@ function New-Arborescence [int]$Depth ) - if ($Depth -eq 0) - { + if ($Depth -eq 0) { # Create file - for ($j = 1; $j -le $NumberFilesPerDir; $j++) - { + for ($j = 1; $j -le $NumberFilesPerDir; $j++) { $fileName = "file-$j.txt" $filePath = $BasePath + "/" + $fileName $localFilePath = Join-Path -Path $env:TEMP -ChildPath $fileName if ($WhatIfPreference) { Write-Host "WhatIf: Creating file $filePath" - } else { + } + else { Write-Host "Creating file $filePath" # Create file locally @@ -44,16 +42,15 @@ function New-Arborescence } } } - else - { - for ($i = 1; $i -le $NumberDirs; $i++) - { + else { + for ($i = 1; $i -le $NumberDirs; $i++) { # Create dir $dirPath = "${BasePath}/dir-$i" if ($WhatIfPreference) { Write-Host "WhatIf: Creating dir $dirPath" - } else { + } + else { Write-Host "Creating dir $dirPath" New-AzStorageDirectory ` -Context $Context ` @@ -73,3 +70,4 @@ function New-Arborescence } } } +