diff --git a/Tests/Public/ZertoApiWrapper.Tests.ps1 b/Tests/Public/ZertoApiWrapper.Tests.ps1 index 529c086..b9f88f4 100644 --- a/Tests/Public/ZertoApiWrapper.Tests.ps1 +++ b/Tests/Public/ZertoApiWrapper.Tests.ps1 @@ -1,23 +1,39 @@ +$moduleName = "ZertoApiWrapper" $moduleFileName = "ZertoApiWrapper.psm1" $filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' -$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' +$docsPath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests[\\\/]Public', 'docs' $modulePath = $filePath -replace "Public", "" -Import-Module $modulePath\$moduleFileName -Force -$userName = "zerto\build" -$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force -$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) - -# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml -$zertoServer = "192.168.1.100" -$zertoPort = "7669" +Import-Module $modulePath\$moduleFileName Describe "File Tests" { - $commands = Get-Command -Module ZertoApiWrapper | Select-Object -ExpandProperty Name + Remove-Module $moduleName -Force + Import-Module $modulePath\$moduleFileName + $commands = Get-Command -Module $moduleName | Select-Object -ExpandProperty Name foreach ($command in $commands) { + $externalHelpFile = "{0}/{1}.md" -f $docsPath, $command $path = "{0}/{1}.ps1" -f $filePath, $command - it "$command is backed by a file with the same name" { - $path | should exist + context "$command File Tests" { + it "$command is backed by a file with the same name" { + $path | should exist + } + it "$command file has openbraces on the same line as the statement" { + $content = Get-Content -Path $path + $openingBracesExist = $content | Where-Object {$_.Trim() -eq '{'} + if ($openingBracesExist) { + Write-Warning "Found the following opening brances on their own line:" + foreach ($openingBrace in $openingBracesExist) { + Write-Warning "Opening Brace on it's own line - $openingBrace" + } + } + $openingBracesExist | should benullorempty + } + it "$command has an external help file" { + $externalHelpFile | should exist + } + it "$command has the External Help File Defined" { + Get-Content -Path $path -First 1 | should be "<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>" + } } } -} \ No newline at end of file +} diff --git a/ZertoApiWrapper.Depend.psd1 b/ZertoApiWrapper.Depend.psd1 new file mode 100644 index 0000000..9b60641 --- /dev/null +++ b/ZertoApiWrapper.Depend.psd1 @@ -0,0 +1,50 @@ +@{ + psake = @{ + Name = 'InvokeBuild' + DependencyType = 'PSGalleryModule' + Parameters = @{ + Repository = 'PSGallery' + SkipPublisherCheck = $true + } + Target = 'CurrentUser' + Version = '5.4.3' + Tags = 'Bootstrap' + } + + Pester = @{ + Name = 'Pester' + DependencyType = 'PSGalleryModule' + Parameters = @{ + Repository = 'PSGallery' + SkipPublisherCheck = $true + } + Target = 'CurrentUser' + Version = '4.6.0' + Tags = 'Bootstrap' + } + + PSScriptAnalyzer = @{ + Name = 'PSScriptAnalyzer' + DependencyType = 'PSGalleryModule' + Parameters = @{ + Repository = 'PSGallery' + SkipPublisherCheck = $true + } + Target = 'CurrentUser' + Version = '1.17.1' + Tags = 'Bootstrap' + } + + Platyps = @{ + Name = 'Platyps' + DependencyType = 'PSGalleryModule' + Parameters = @{ + Repository = 'PSGallery' + SkipPublisherCheck = $true + } + Target = 'CurrentUser' + Version = '0.12.0' + Tags = 'Bootstrap' + } + +} diff --git a/ZertoApiWrapper.build.ps1 b/ZertoApiWrapper.build.ps1 index d4f7348..e469509 100644 --- a/ZertoApiWrapper.build.ps1 +++ b/ZertoApiWrapper.build.ps1 @@ -1,17 +1,44 @@ -task . InstallDependencies, Analyze +#Requires -Modules 'InvokeBuild' -task InstallDependencies { - Install-Module Pester -Force - Install-Module PSScriptAnalyzer -Force +. '.\ZertoApiWrapper.settings.ps1' +# import-module "$BuildRoot\ZertoApiWrapper\ZertoApiWrapper.psd1" -Verbose -Force + +<# [CmdletBinding()] +param([switch]$Install, + [string]$Configuration = (property Configuration Release)) +$targetDir = "temp/$Configuration/ZertoApiWrapper" #> + +task . Analyze, FileTests + +<# Synopsis: Ensure platyPS is installed #> +task CheckPlatyPSInstalled { + if ($null -eq (Get-Module -List platyPS)) { + Install-Module -Scope CurrentUser -Repository PSGallery -Name platyPS + } } -task Analyze { +<# Synopsis: Ensure Pester is installed #> +task CheckPesterInstalled { + if ($null -eq (Get-Module -List Pester)) { + Install-Module -Scope CurrentUser -Repository PSGallery -Name Pester + } +} + +<# Synopsis: Ensure PSScriptAnalyzer is installed #> +task CheckPSScriptAnalyzerInstalled { + if ($null -eq (Get-Module -List PSScriptAnalyzer)) { + Install-Module -Scope CurrentUser -Repository PSGallery -Name PSScriptAnalyzer + } +} + +<# Synopsis: Analyze ZertoApiWrapper functions for Code Violations #> +task Analyze CheckPSScriptAnalyzerInstalled, CheckPesterInstalled, CheckPlatyPSInstalled, { $scriptAnalyzerParams = @{ Path = "$BuildRoot\ZertoApiWrapper\" Severity = @('Error', 'Warning') Recurse = $true Verbose = $false - ExcludeRule = 'PSUseDeclaredVarsMoreThanAssignments' + ExcludeRule = @('PSUseDeclaredVarsMoreThanAssignments', 'PSUseShouldProcessForStateChangingFunctions', 'PSUseToExportFieldsInManifest') } $saresults = Invoke-ScriptAnalyzer @scriptAnalyzerParams @@ -21,3 +48,25 @@ task Analyze { } } +task FileTests CheckPesterInstalled, { + $testResultsFile = "$BuildRoot\Tests\Public\TestResults.xml" + Invoke-Pester -Script "$BuildRoot\Tests\Public\ZertoApiWrapper.Tests.ps1" -OutputFile $testResultsFile -PassThru +} + +$buildMamlParams = @{ + Inputs = { Get-ChildItem docs\*.md } + Outputs = ".\ZertoApiWrapper\Public\en-us\ZertoApiWrapper-help.xml" +} + +task BuildMamlHelp CheckPlatyPSInstalled, { + if (Test-Path $buildMamlParams.Outputs) { + Remove-Item $buildMamlParams.Outputs + } + platyPS\New-ExternalHelp .\docs -Force -OutputPath $buildMamlParams.Outputs +} + +task UpdateMarkdownHelp CheckPlatyPSInstalled, { + remove-module ZertoApiWrapper -force -ErrorAction SilentlyContinue + Import-Module .\ZertoApiWrapper\ZertoApiWrapper.psm1 -Force + Update-MarkDownHelp -Path docs -AlphabeticParamsOrder +} diff --git a/ZertoApiWrapper/Public/Import-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Import-ZertoVpg.ps1 index 4c269d0..bbc45ef 100644 --- a/ZertoApiWrapper/Public/Import-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/Import-ZertoVpg.ps1 @@ -24,7 +24,7 @@ function Import-ZertoVpg { $importedSettings.VpgSettingsIdentifier = $vpgSettingsIdentifier $uri = "{0}/{1}" -f $baseUri, $vpgSettingsIdentifier Invoke-ZertoRestRequest -uri $uri -method "PUT" -body $($importedSettings | convertto-json -Depth 10) - $vpgSettingsIdentifier | Save-ZertoVpgSettings + $vpgSettingsIdentifier | Save-ZertoVpgSetting if ($settingsFile.Count -gt 1) { Start-Sleep 5 } diff --git a/ZertoApiWrapper/Public/Save-ZertoVpgSettings.ps1 b/ZertoApiWrapper/Public/Save-ZertoVpgSetting.ps1 similarity index 95% rename from ZertoApiWrapper/Public/Save-ZertoVpgSettings.ps1 rename to ZertoApiWrapper/Public/Save-ZertoVpgSetting.ps1 index 24f5084..8e06784 100644 --- a/ZertoApiWrapper/Public/Save-ZertoVpgSettings.ps1 +++ b/ZertoApiWrapper/Public/Save-ZertoVpgSetting.ps1 @@ -1,5 +1,5 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> -function Save-ZertoVpgSettings { +function Save-ZertoVpgSetting { [cmdletbinding( SupportsShouldProcess = $true )] diff --git a/ZertoApiWrapper/Public/en-us/ZertoApiWrapper-help.xml b/ZertoApiWrapper/Public/en-us/ZertoApiWrapper-help.xml index 0ee3eb7..03653be 100644 --- a/ZertoApiWrapper/Public/en-us/ZertoApiWrapper-help.xml +++ b/ZertoApiWrapper/Public/en-us/ZertoApiWrapper-help.xml @@ -5977,35 +5977,35 @@ -------------------------- Example 1 -------------------------- - PS C:\> Get-ZertoVpgSettings -vpgSettingsIdentifier "MySettingsIdentifier" + PS C:\> Get-ZertoVpgSetting -vpgSettingsIdentifier "MySettingsIdentifier" Returns all current settings for vpgSettingsIdentifier "MySettingsIdentifier" -------------------------- Example 2 -------------------------- - PS C:\> Get-ZertoVpgSettings -vpgSettingsIdentifier "MySettingsIdentifier" -vmIdentifier "MyVmId" + PS C:\> Get-ZertoVpgSetting -vpgSettingsIdentifier "MySettingsIdentifier" -vmIdentifier "MyVmId" Returns all current vm level settings for the vmIdentifier "MyVmId" in vpgSettingsIdentifier "MySettingsIdentifier" -------------------------- Example 3 -------------------------- - PS C:\> Get-ZertoVpgSettings -vpgSettingsIdentifier "MySettingsIdentifier" -vmIdentifier "MyVmId" -volumes + PS C:\> Get-ZertoVpgSetting -vpgSettingsIdentifier "MySettingsIdentifier" -vmIdentifier "MyVmId" -volumes Returns current vm level settings for volumes for vmId "MyVmId" in vpgSettingsIdentifier "MySettingsIdentifier" -------------------------- Example 4 -------------------------- - PS C:\> Get-ZertoVpgSettings -vpgSettingsIdentifier "MySettingsIdentifier" -nics + PS C:\> Get-ZertoVpgSetting -vpgSettingsIdentifier "MySettingsIdentifier" -nics Returns current vm level settings for nics for vmId "MyVmId" in vpgSettingsIdentifier "MySettingsIdentifier" -------------------------- Example 5 -------------------------- - PS C:\> Get-ZertoVpgSettings -vpgSettingsIdentifier "MySettingsIdentifier" -basic + PS C:\> Get-ZertoVpgSetting -vpgSettingsIdentifier "MySettingsIdentifier" -basic Returns current basic settings for vpgSettingsIdentifier "MySettingsIdentifier" @@ -10656,9 +10656,9 @@ - Save-ZertoVpgSettings + Save-ZertoVpgSetting Save - ZertoVpgSettings + ZertoVpgSetting Commits the updated Vpg Settings with the configured Vpg Settings Identifier @@ -10668,8 +10668,8 @@ - Save-ZertoVpgSettings - + Save-ZertoVpgSetting + vpgSettingsIdentifier VpgSettings Identifier to save @@ -10706,7 +10706,7 @@ - + vpgSettingsIdentifier VpgSettings Identifier to save @@ -10771,7 +10771,7 @@ -------------------------- Example 1 -------------------------- - PS C:> Save-ZertoVpgSettings -vpgSettingsIdentifier "MyVpgSettingsIdentifier" + PS C:> Save-ZertoVpgSetting -vpgSettingsIdentifier "MyVpgSettingsIdentifier" Commits vpg settings with vpg settings identifier "MyVpgSettingsIdentifier" @@ -10780,7 +10780,7 @@ Online Version: - https://github.com/wcarroll/ZertoApiWrapper/blob/master/docs/Save-ZertoVpgSettings.md + https://github.com/wcarroll/ZertoApiWrapper/blob/master/docs/Save-ZertoVpgSetting.md Zerto REST API VPG Settings End Point Documentation diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..afbd413 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,64 @@ +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +jobs: + - job: Build_PS_Win2016 + pool: + vmImage: vs2017-win2016 + steps: + - powershell: | + .\build.ps1 -Verbose + displayName: 'Build and Test' + - task: PublishTestResults@2 + inputs: + testRunner: 'NUnit' + testResultsFiles: '**/Public/TestResults.xml' + testRunTitle: 'PS_Win2016' + displayName: 'Publish Test Results' + + - job: Build_PSCore_Ubuntu1604 + + pool: + vmImage: ubuntu-16.04 + + steps: + - script: | + curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - + curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list + sudo apt-get update + sudo apt-get install -y powershell + displayName: 'Install PowerShell Core' + + - script: | + pwsh -c '.\build.ps1' + displayName: 'Build and Test' + + - task: PublishTestResults@2 + inputs: + testRunner: 'NUnit' + testResultsFiles: '**/Public/TestResults.xml' + testRunTitle: 'PSCore_Ubuntu1604' + displayName: 'Publish Test Results' + + - job: Build_PSCore_MacOS1013 + pool: + vmImage: xcode9-macos10.13 + steps: + - script: | + brew update + brew tap caskroom/cask + brew cask install powershell + displayName: 'Install PowerShell Core' + + - script: | + pwsh -c '.\build.ps1' + displayName: 'Build and Test' + + - task: PublishTestResults@2 + inputs: + testRunner: 'NUnit' + testResultsFiles: '**/Public/TestResults.xml' + testRunTitle: 'PSCore_MacOS1013' + displayName: 'Publish Test Results' diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..9ce90cf --- /dev/null +++ b/build.ps1 @@ -0,0 +1,16 @@ +# Bootstrap the environment +$null = Get-PackageProvider -Name NuGet -ForceBootstrap + +if (-not (Get-Module -Name PSDepend -ListAvailable)) { + Install-Module -Name PSDepend -Scope CurrentUser -Force -Confirm:$false +} + +Import-Module -Name PSDepend +Invoke-PSDepend ` + -Path $PSScriptRoot ` + -Force ` + -Import ` + -Install ` + -Tags 'Bootstrap' + +Invoke-Build . diff --git a/docs/Get-ZertoVpgSetting.md b/docs/Get-ZertoVpgSetting.md index d812532..8c97811 100644 --- a/docs/Get-ZertoVpgSetting.md +++ b/docs/Get-ZertoVpgSetting.md @@ -118,35 +118,35 @@ It is important to note that only once a VPG settings object has been created, w ### Example 1 ```powershell -PS C:\> Get-ZertoVpgSettings -vpgSettingsIdentifier "MySettingsIdentifier" +PS C:\> Get-ZertoVpgSetting -vpgSettingsIdentifier "MySettingsIdentifier" ``` Returns all current settings for vpgSettingsIdentifier "MySettingsIdentifier" ### Example 2 ```powershell -PS C:\> Get-ZertoVpgSettings -vpgSettingsIdentifier "MySettingsIdentifier" -vmIdentifier "MyVmId" +PS C:\> Get-ZertoVpgSetting -vpgSettingsIdentifier "MySettingsIdentifier" -vmIdentifier "MyVmId" ``` Returns all current vm level settings for the vmIdentifier "MyVmId" in vpgSettingsIdentifier "MySettingsIdentifier" ### Example 3 ```powershell -PS C:\> Get-ZertoVpgSettings -vpgSettingsIdentifier "MySettingsIdentifier" -vmIdentifier "MyVmId" -volumes +PS C:\> Get-ZertoVpgSetting -vpgSettingsIdentifier "MySettingsIdentifier" -vmIdentifier "MyVmId" -volumes ``` Returns current vm level settings for volumes for vmId "MyVmId" in vpgSettingsIdentifier "MySettingsIdentifier" ### Example 4 ```powershell -PS C:\> Get-ZertoVpgSettings -vpgSettingsIdentifier "MySettingsIdentifier" -nics +PS C:\> Get-ZertoVpgSetting -vpgSettingsIdentifier "MySettingsIdentifier" -nics ``` Returns current vm level settings for nics for vmId "MyVmId" in vpgSettingsIdentifier "MySettingsIdentifier" ### Example 5 ```powershell -PS C:\> Get-ZertoVpgSettings -vpgSettingsIdentifier "MySettingsIdentifier" -basic +PS C:\> Get-ZertoVpgSetting -vpgSettingsIdentifier "MySettingsIdentifier" -basic ``` Returns current basic settings for vpgSettingsIdentifier "MySettingsIdentifier" diff --git a/docs/Remove-ZertoPeerSite.md b/docs/Remove-ZertoPeerSite.md index 142d574..6bb3816 100644 --- a/docs/Remove-ZertoPeerSite.md +++ b/docs/Remove-ZertoPeerSite.md @@ -150,8 +150,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. -For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/docs/Save-ZertoVpgSettings.md b/docs/Save-ZertoVpgSetting.md similarity index 85% rename from docs/Save-ZertoVpgSettings.md rename to docs/Save-ZertoVpgSetting.md index 16d9dda..2e2efaf 100644 --- a/docs/Save-ZertoVpgSettings.md +++ b/docs/Save-ZertoVpgSetting.md @@ -1,92 +1,92 @@ ---- -external help file: ZertoApiWrapper-help.xml -Module Name: ZertoApiWrapper -online version: https://github.com/wcarroll/ZertoApiWrapper/blob/master/docs/Save-ZertoVpgSettings.md -schema: 2.0.0 ---- - -# Save-ZertoVpgSettings - -## SYNOPSIS -Commits the updated Vpg Settings with the configured Vpg Settings Identifier - -## SYNTAX - -``` -Save-ZertoVpgSettings [-vpgSettingsIdentifier] [-WhatIf] [-Confirm] [] -``` - -## DESCRIPTION -Commits the updated Vpg Settings with the configured Vpg Settings Identifier - -## EXAMPLES - -### Example 1 -```powershell -PS C:> Save-ZertoVpgSettings -vpgSettingsIdentifier "MyVpgSettingsIdentifier" -``` - -Commits vpg settings with vpg settings identifier "MyVpgSettingsIdentifier" - -## PARAMETERS - -### -vpgSettingsIdentifier -VpgSettings Identifier to save - -```yaml -Type: String -Parameter Sets: (All) -Aliases: vpgSettingsId - -Required: True -Position: 0 -Default value: None -Accept pipeline input: True (ByPropertyName, ByValue) -Accept wildcard characters: False -``` - -### -Confirm -Prompts you for confirmation before running the cmdlet. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: cf - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -WhatIf -Shows what would happen if the cmdlet runs. -The cmdlet is not run. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: wi - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). - -## INPUTS - -### System.String -## OUTPUTS - -### System.Object -## NOTES - -## RELATED LINKS - -[Zerto REST API VPG Settings End Point Documentation](http://s3.amazonaws.com/zertodownload_docs/Latest/Zerto%20Virtual%20Replication%20Zerto%20Virtual%20Manager%20%28ZVM%29%20-%20vSphere%20Online%20Help/RestfulAPIs/StatusAPIs.5.108.html#) +--- +external help file: ZertoApiWrapper-help.xml +Module Name: ZertoApiWrapper +online version: https://github.com/wcarroll/ZertoApiWrapper/blob/master/docs/Save-ZertoVpgSetting.md +schema: 2.0.0 +--- + +# Save-ZertoVpgSetting + +## SYNOPSIS +Commits the updated Vpg Settings with the configured Vpg Settings Identifier + +## SYNTAX + +``` +Save-ZertoVpgSetting [-vpgSettingsIdentifier] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +Commits the updated Vpg Settings with the configured Vpg Settings Identifier + +## EXAMPLES + +### Example 1 +```powershell +PS C:> Save-ZertoVpgSetting -vpgSettingsIdentifier "MyVpgSettingsIdentifier" +``` + +Commits vpg settings with vpg settings identifier "MyVpgSettingsIdentifier" + +## PARAMETERS + +### -vpgSettingsIdentifier +VpgSettings Identifier to save + +```yaml +Type: String +Parameter Sets: (All) +Aliases: vpgSettingsId + +Required: True +Position: 1 +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS + +[Zerto REST API VPG Settings End Point Documentation](http://s3.amazonaws.com/zertodownload_docs/Latest/Zerto%20Virtual%20Replication%20Zerto%20Virtual%20Manager%20%28ZVM%29%20-%20vSphere%20Online%20Help/RestfulAPIs/StatusAPIs.5.108.html#)