From 9494bf48bac8d95afbe5f5b5d7f0f70d8505e020 Mon Sep 17 00:00:00 2001 From: Ben Gelens Date: Thu, 19 May 2016 10:33:38 +0200 Subject: [PATCH] Added new website functions: Get-WAPWebSitePublishingInfo, Remove-WAPWebSiteGitRepository, New-WAPWebSiteGitRepository, Get-WAPWebSiteGitRepository --- README.md | 4 ++ WapTenantPublicAPI.psd1 | 10 ++- WapTenantPublicAPI.psm1 | 138 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 147 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index db0a733..62ef878 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,10 @@ New-WAPWebSite -Name ben -Mode SharedFree -Verbose Get-WAPWebSite Get-WAPWebSite -Name ben | Get-WAPWebSitePublishingXML -OutFile C:\Users\gelensb.eu\Desktop\test.xml Get-WAPWebSite -Name ben | Get-WAPWebSiteConfiguration +Get-WAPWebSite -Name ben | New-WAPWebSiteGitRepository +Get-WAPWebSite -Name ben | Get-WAPWebSiteGitRepository +Get-WAPWebSite -Name ben | Get-WAPWebSitePublishingInfo +Get-WAPWebSite -Name ben | Remove-WAPWebSiteGitRepository Get-WAPWebSite -Name ben | Restart-WAPWebSite Get-WAPWebSite -Name ben | Remove-WAPWebSite diff --git a/WapTenantPublicAPI.psd1 b/WapTenantPublicAPI.psd1 index a854d2b..11ef7aa 100644 --- a/WapTenantPublicAPI.psd1 +++ b/WapTenantPublicAPI.psd1 @@ -12,7 +12,7 @@ RootModule = 'WapTenantPublicAPI' # Version number of this module. -ModuleVersion = '0.0.6.0' +ModuleVersion = '0.0.6.1' # ID used to uniquely identify this module GUID = 'eaa28acf-4a1e-4d0e-96dd-fa36de33a658' @@ -114,7 +114,11 @@ FunctionsToExport = @( 'Remove-WAPWebSite', 'Get-WAPWebSiteConfiguration', 'Get-WAPWebSitePublishingXML', - 'Restart-WAPWebSite' + 'Restart-WAPWebSite', + 'New-WAPWebSiteGitRepository', + 'Get-WAPWebSiteGitRepository', + 'Remove-WAPWebSiteGitRepository', + 'Get-WAPWebSitePublishingInfo' ) # Cmdlets to export from this module @@ -168,4 +172,4 @@ HelpInfoURI = 'https://github.com/bgelens/WAPTenantPublicAPI' # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. # DefaultCommandPrefix = '' -} \ No newline at end of file +} diff --git a/WapTenantPublicAPI.psm1 b/WapTenantPublicAPI.psm1 index 3f52e51..372c993 100644 --- a/WapTenantPublicAPI.psm1 +++ b/WapTenantPublicAPI.psm1 @@ -2334,8 +2334,7 @@ function Stop-WAPVM { [OutputType([void])] param ( [Parameter(Mandatory, ValueFromPipeline)] - [ValidateNotNull()] - [PSCustomObject] $VM, + [ValidateNotNull()][PSCustomObject] $VM, [Switch] $RunAsynchronously, @@ -3272,6 +3271,141 @@ function Restart-WAPWebSite { } } +function Get-WAPWebSiteGitRepository { + [cmdletbinding()] + [outputtype([system.string])] + param ( + [Parameter(Mandatory, ValueFromPipeline)] + [System.Management.Automation.PSTypeName('WAP.WebSite')] $Website + ) + process { + try { + if ($script:IgnoreSSL) { + Write-Warning -Message 'IgnoreSSL defined by Connect-WAPAPI, Certificate errors will be ignored!' + #Change Certificate Policy to ignore + IgnoreSSL + } + PreFlight -IncludeConnection -IncludeSubscription -IncludeWebSpace + + $URI = '{0}:{1}/{2}/services/WebSpaces/{3}/sites/{4}/repository' -f $script:PublicTenantAPIUrl,$script:Port,$script:Subscription.SubscriptionId,$script:WebSpace.Name,$Website.Name + Write-Verbose -Message "Constructed WebSite URI: $URI" + + Invoke-RestMethod -Uri $URI -Headers $script:Headers -Method Get -ContentType 'application/json' + } catch { + Write-Error -ErrorRecord $_ + } finally { + #Change Certificate Policy to the original + if ($script:IgnoreSSL) { + [System.Net.ServicePointManager]::CertificatePolicy = $script:OriginalCertificatePolicy + } + } + } +} + +function New-WAPWebSiteGitRepository { + [cmdletbinding()] + [outputtype([void],[System.String])] + param ( + [Parameter(Mandatory, ValueFromPipeline)] + [System.Management.Automation.PSTypeName('WAP.WebSite')] $Website, + + [switch] $PassThru + ) + process { + try { + if ($script:IgnoreSSL) { + Write-Warning -Message 'IgnoreSSL defined by Connect-WAPAPI, Certificate errors will be ignored!' + #Change Certificate Policy to ignore + IgnoreSSL + } + PreFlight -IncludeConnection -IncludeSubscription -IncludeWebSpace + + $URI = '{0}:{1}/{2}/services/WebSpaces/{3}/sites/{4}/repository' -f $script:PublicTenantAPIUrl,$script:Port,$script:Subscription.SubscriptionId,$script:WebSpace.Name,$Website.Name + Write-Verbose -Message "Constructed WebSite URI: $URI" + + $null = Invoke-RestMethod -Uri $URI -Headers $script:Headers -Method Post -ContentType 'application/json' + if ($PassThru) { + $Website | Get-WAPWebSiteGitRepository + } + } catch { + Write-Error -ErrorRecord $_ + } finally { + #Change Certificate Policy to the original + if ($script:IgnoreSSL) { + [System.Net.ServicePointManager]::CertificatePolicy = $script:OriginalCertificatePolicy + } + } + } +} + +function Remove-WAPWebSiteGitRepository { + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] + param ( + [Parameter(Mandatory, ValueFromPipeline)] + [System.Management.Automation.PSTypeName('WAP.WebSite')] $Website, + + [Switch] $Force + ) + process { + try { + if ($script:IgnoreSSL) { + Write-Warning -Message 'IgnoreSSL defined by Connect-WAPAPI, Certificate errors will be ignored!' + #Change Certificate Policy to ignore + IgnoreSSL + } + + PreFlight -IncludeConnection -IncludeSubscription -IncludeWebSpace + + $URI = '{0}:{1}/{2}/services/WebSpaces/{3}/sites/{4}/repository' -f $script:PublicTenantAPIUrl,$script:Port,$script:Subscription.SubscriptionId,$script:WebSpace.Name,$Website.Name + Write-Verbose -Message "Constructed WebSite URI: $URI" + + if ($Force -or $PSCmdlet.ShouldProcess($Website.Name)) { + Invoke-RestMethod -Uri $URI -Headers $script:Headers -Method Delete + } + } catch { + Write-Error -ErrorRecord $_ + } finally { + #Change Certificate Policy to the original + if ($IgnoreSSL) { + [System.Net.ServicePointManager]::CertificatePolicy = $script:OriginalCertificatePolicy + } + } + } +} + +function Get-WAPWebSitePublishingInfo { + [cmdletbinding()] + [outputtype([pscustomobject])] + param ( + [Parameter(Mandatory, ValueFromPipeline)] + [System.Management.Automation.PSTypeName('WAP.WebSite')] $Website + ) + process { + try { + if ($script:IgnoreSSL) { + Write-Warning -Message 'IgnoreSSL defined by Connect-WAPAPI, Certificate errors will be ignored!' + #Change Certificate Policy to ignore + IgnoreSSL + } + + PreFlight -IncludeConnection -IncludeSubscription -IncludeWebSpace + + $URI = $Website.SelfLink + '?propertiesToInclude=RepositoryUri,PublishingUsername,PublishingPassword,Metadata,ScmType' + Write-Verbose -Message "Constructed WebSite URI: $URI" + + (Invoke-RestMethod -Uri $URI -Headers $script:Headers -Method Get).SiteProperties.Properties + + } catch { + Write-Error -ErrorRecord $_ + } finally { + #Change Certificate Policy to the original + if ($IgnoreSSL) { + [System.Net.ServicePointManager]::CertificatePolicy = $script:OriginalCertificatePolicy + } + } + } +} + #endregion Export-ModuleMember -Function *-WAP*