Skip to content

Commit c6ae2ed

Browse files
authored
Merge pull request Azure#24 from viananth/AzureStack
Add ShouldProcess & Format files to AzureBridge
2 parents f092016 + b09af70 commit c6ae2ed

File tree

5 files changed

+125
-51
lines changed

5 files changed

+125
-51
lines changed

src/StackAdmin/Azs.AzureBridge.Admin/Module/Azs.AzureBridge.Admin/Azs.Azurebridge.Admin.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ Licensed under the MIT License. See License.txt in the project root for license
6565
# ScriptsToProcess = @()
6666

6767
# Type files (.ps1xml) to be loaded when importing this module
68-
# TypesToProcess = @()
68+
TypesToProcess = @('Generated.PowerShell.Commands\FormatFiles\Azs.AzureBridge.Admin.Type.ps1xml')
6969

7070
# Format files (.ps1xml) to be loaded when importing this module
71-
# FormatsToProcess = @()
71+
FormatsToProcess = @('Generated.PowerShell.Commands\FormatFiles\Azs.AzureBridge.Admin.Format.ps1xml')
7272

7373
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
7474
NestedModules = @()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
//
4+
// Copyright (c) Microsoft and contributors. All rights reserved.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
//
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
-->
19+
<Configuration>
20+
<ViewDefinitions></ViewDefinitions>
21+
</Configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
//
4+
// Copyright (c) Microsoft and contributors. All rights reserved.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
//
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
-->
19+
<Types>
20+
<Type>
21+
<Name>Microsoft.AzureStack.Management.AzureBridge.Admin.Models.GalleryIcons</Name>
22+
<Members>
23+
<ScriptMethod>
24+
<Name>ToString</Name>
25+
<Script>
26+
$this | fl | Out-String
27+
</Script>
28+
</ScriptMethod>
29+
</Members>
30+
</Type>
31+
<Type>
32+
<Name>Microsoft.AzureStack.Management.AzureBridge.Admin.Models.ProductProperties</Name>
33+
<Members>
34+
<ScriptMethod>
35+
<Name>ToString</Name>
36+
<Script>
37+
$this | fl | Out-String
38+
</Script>
39+
</ScriptMethod>
40+
</Members>
41+
</Type>
42+
43+
</Types>

src/StackAdmin/Azs.AzureBridge.Admin/Module/Azs.AzureBridge.Admin/Generated.PowerShell.Commands/SwaggerPathCommands/Invoke-AzsAzureBridgeProductDownload.ps1

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Licensed under the MIT License. See License.txt in the project root for license
2929
Download a product from Azure Marketplace
3030
#>
3131
function Invoke-AzsAzureBridgeProductDownload {
32-
[CmdletBinding(DefaultParameterSetName = 'Products_Download')]
32+
[CmdletBinding(DefaultParameterSetName = 'Products_Download', SupportsShouldProcess = $true)]
3333
param(
3434
[Parameter(Mandatory = $true, ParameterSetName = 'Products_Download')]
3535
[ValidateNotNullOrEmpty()]
@@ -55,7 +55,11 @@ function Invoke-AzsAzureBridgeProductDownload {
5555

5656
[Parameter(Mandatory = $false)]
5757
[switch]
58-
$AsJob
58+
$AsJob,
59+
60+
[Parameter(Mandatory = $false)]
61+
[switch]
62+
$Force
5963
)
6064

6165
Begin {
@@ -99,58 +103,64 @@ function Invoke-AzsAzureBridgeProductDownload {
99103
$productName = $ArmResourceIdParameterValues['productName']
100104
}
101105

102-
if ('Products_Download' -eq $PsCmdlet.ParameterSetName -or 'ResourceId' -eq $PsCmdlet.ParameterSetName) {
103-
Write-Verbose -Message 'Performing operation DownloadWithHttpMessagesAsync on $AzureBridgeAdminClient.'
104-
$TaskResult = $AzureBridgeAdminClient.Products.DownloadWithHttpMessagesAsync($ResourceGroupName, $ActivationName, $ProductName)
105-
} else {
106-
Write-Verbose -Message 'Failed to map parameter set to operation method.'
107-
throw 'Module failed to find operation to execute.'
108-
}
106+
if ($PSCmdlet.ShouldProcess("$ProductName" , "Start product download")) {
107+
if (($Force.IsPresent -or $PSCmdlet.ShouldContinue("Start the product download?", "Performing operation DownloadWithHttpMessagesAsync on $ProductName."))) {
109108

110-
Write-Verbose -Message "Waiting for the operation to complete."
111-
112-
$PSSwaggerJobScriptBlock = {
113-
[CmdletBinding()]
114-
param(
115-
[Parameter(Mandatory = $true)]
116-
[System.Threading.Tasks.Task]
117-
$TaskResult,
118-
119-
[Parameter(Mandatory = $true)]
120-
[string]
121-
$TaskHelperFilePath
122-
)
123-
if ($TaskResult) {
124-
. $TaskHelperFilePath
125-
$GetTaskResult_params = @{
126-
TaskResult = $TaskResult
109+
if ('Products_Download' -eq $PsCmdlet.ParameterSetName -or 'ResourceId' -eq $PsCmdlet.ParameterSetName) {
110+
Write-Verbose -Message 'Performing operation DownloadWithHttpMessagesAsync on $AzureBridgeAdminClient.'
111+
$TaskResult = $AzureBridgeAdminClient.Products.DownloadWithHttpMessagesAsync($ResourceGroupName, $ActivationName, $ProductName)
112+
}
113+
else {
114+
Write-Verbose -Message 'Failed to map parameter set to operation method.'
115+
throw 'Module failed to find operation to execute.'
127116
}
128117

129-
Get-TaskResult @GetTaskResult_params
118+
Write-Verbose -Message "Waiting for the operation to complete."
130119

131-
}
132-
}
120+
$PSSwaggerJobScriptBlock = {
121+
[CmdletBinding()]
122+
param(
123+
[Parameter(Mandatory = $true)]
124+
[System.Threading.Tasks.Task]
125+
$TaskResult,
126+
127+
[Parameter(Mandatory = $true)]
128+
[string]
129+
$TaskHelperFilePath
130+
)
131+
if ($TaskResult) {
132+
. $TaskHelperFilePath
133+
$GetTaskResult_params = @{
134+
TaskResult = $TaskResult
135+
}
133136

134-
$PSCommonParameters = Get-PSCommonParameter -CallerPSBoundParameters $PSBoundParameters
135-
$TaskHelperFilePath = Join-Path -Path $ExecutionContext.SessionState.Module.ModuleBase -ChildPath 'Get-TaskResult.ps1'
136-
if ($AsJob) {
137-
$ScriptBlockParameters = New-Object -TypeName 'System.Collections.Generic.Dictionary[string,object]'
138-
$ScriptBlockParameters['TaskResult'] = $TaskResult
139-
$ScriptBlockParameters['AsJob'] = $true
140-
$ScriptBlockParameters['TaskHelperFilePath'] = $TaskHelperFilePath
141-
$PSCommonParameters.GetEnumerator() | ForEach-Object { $ScriptBlockParameters[$_.Name] = $_.Value }
142-
143-
Start-PSSwaggerJobHelper -ScriptBlock $PSSwaggerJobScriptBlock `
144-
-CallerPSBoundParameters $ScriptBlockParameters `
145-
-CallerPSCmdlet $PSCmdlet `
146-
@PSCommonParameters
147-
} else {
148-
Invoke-Command -ScriptBlock $PSSwaggerJobScriptBlock `
149-
-ArgumentList $TaskResult, $TaskHelperFilePath `
150-
@PSCommonParameters
137+
Get-TaskResult @GetTaskResult_params
138+
139+
}
140+
}
141+
142+
$PSCommonParameters = Get-PSCommonParameter -CallerPSBoundParameters $PSBoundParameters
143+
$TaskHelperFilePath = Join-Path -Path $ExecutionContext.SessionState.Module.ModuleBase -ChildPath 'Get-TaskResult.ps1'
144+
if ($AsJob) {
145+
$ScriptBlockParameters = New-Object -TypeName 'System.Collections.Generic.Dictionary[string,object]'
146+
$ScriptBlockParameters['TaskResult'] = $TaskResult
147+
$ScriptBlockParameters['AsJob'] = $true
148+
$ScriptBlockParameters['TaskHelperFilePath'] = $TaskHelperFilePath
149+
$PSCommonParameters.GetEnumerator() | ForEach-Object { $ScriptBlockParameters[$_.Name] = $_.Value }
150+
151+
Start-PSSwaggerJobHelper -ScriptBlock $PSSwaggerJobScriptBlock `
152+
-CallerPSBoundParameters $ScriptBlockParameters `
153+
-CallerPSCmdlet $PSCmdlet `
154+
@PSCommonParameters
155+
}
156+
else {
157+
Invoke-Command -ScriptBlock $PSSwaggerJobScriptBlock `
158+
-ArgumentList $TaskResult, $TaskHelperFilePath `
159+
@PSCommonParameters
160+
}
161+
}
151162
}
152163
}
153-
154164
End {
155165
if ($tracerObject) {
156166
$global:DebugPreference = $oldDebugPreference

src/StackAdmin/Azs.AzureBridge.Admin/Tests/src/Azs.AzureBridge.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ InModuleScope Azs.AzureBridge.Admin {
137137
Context "Invoke-AzsAzureBridgeProductDownload" {
138138
It "TestDownloadAzsAzureBridgeProduct" {
139139
$global:TestName = "TestDownloadAzsAzureBridgeProduct"
140-
Invoke-AzsAzureBridgeProductDownload -ActivationName $ActivationName -ProductName $ProductName1 -ResourceGroupName $ResourceGroupName -ErrorAction Stop
140+
Invoke-AzsAzureBridgeProductDownload -ActivationName $ActivationName -ProductName $ProductName1 -ResourceGroupName $ResourceGroupName -Force -ErrorAction Stop
141141
}
142142

143143
It "TestDownloadAzsAzureBridgeProductPipeline" -Skip {
144144
$global:TestName = "TestDownloadAzsAzureBridgeProductPipeline"
145-
$DownloadedProduct = (Get-AzsAzureBridgeProduct -ActivationName $ActivationName -Name $ProductName2 -ResourceGroupName $ResourceGroupName) | Invoke-AzsAzureBridgeProductDownload
145+
$DownloadedProduct = (Get-AzsAzureBridgeProduct -ActivationName $ActivationName -Name $ProductName2 -ResourceGroupName $ResourceGroupName) | Invoke-AzsAzureBridgeProductDownload -Force
146146
ValidateProductInfo $DownloadedProduct
147147
}
148148
}

0 commit comments

Comments
 (0)