Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 4938fef

Browse files
Made changes to make get and remove operations work.
1 parent 7404dd9 commit 4938fef

File tree

4 files changed

+50
-18
lines changed

4 files changed

+50
-18
lines changed
70 Bytes
Binary file not shown.
Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
11

2+
$script:azureRMProfile = $null
3+
24
<#
35
.DESCRIPTION
46
Gets the Azure Profile for the current process.
57
This command uses Login-AzureRMAccount
68
#>
9+
function Get-AzRMProfile
10+
{
11+
[CmdletBinding()]
12+
param()
713

14+
if (-not $script:azureRMProfile)
15+
{
16+
$script:azureRMProfile = Login-AzureRmAccount
17+
}
18+
$script:azureRMProfile
19+
}
820

9-
function Get-AzServiceCredntial
21+
22+
function Get-AzServiceCredential
1023
{
1124
[CmdletBinding()]
1225
param()
1326

14-
$ap = Get-Az
27+
$ap = Get-AzRMProfile
1528
$authenticationFactory = [Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory]::new()
1629
$serviceCredentials = $authenticationFactory.GetServiceClientCredentials($ap.Context)
1730
$serviceCredentials
1831
}
1932

20-
fuction Get-AzDelegatingHandler
33+
function Get-AzDelegatingHandler
34+
{
35+
[CmdletBinding()]
36+
param()
37+
38+
,[System.Net.Http.DelegatingHandler[]]::new(0)
39+
}
40+
41+
function Get-AzSubscriptionId
2142
{
2243
[CmdletBinding()]
2344
param()
2445

25-
[System.Net.Http.DelegatingHandler[]]::new(0)
46+
$ap = Get-AzureRmContext -ea stop
47+
$ap.Subscription.SubscriptionId
2648
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[reflection.assembly]::LoadFrom("$PSScriptRoot\Net45\Microsoft.Rest.ClientRuntime.dll")
2-
[reflection.assembly]::LoadFrom("$PSScriptRoot\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll")
3-
[reflection.assembly]::LoadFrom("$PSScriptRoot\net45\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll")
4-
[reflection.assembly]::LoadFrom("$PSScriptRoot\net45\Newtonsoft.Json.dll")
1+
$null = [reflection.assembly]::LoadFrom("$PSScriptRoot\Net45\Microsoft.Rest.ClientRuntime.dll")
2+
$null = [reflection.assembly]::LoadFrom("$PSScriptRoot\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll")
3+
#[reflection.assembly]::LoadFrom("$PSScriptRoot\net45\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll")
4+
$null = [reflection.assembly]::LoadFrom("$PSScriptRoot\net45\Newtonsoft.Json.dll")

PSSwagger.psm1

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,21 @@ $helpParamStr = @'
126126
'@
127127

128128
$functionBodyStr = @'
129-
$serviceCredentials = Get-AzCredentials
130-
$subscriptionId = Get-SubscriptionId
131129
132-
$clientName = [$fullModuleName]::new($serviceCredentials, [System.Net.Http.DelegatingHandler[]]::new(0))
133-
$clientName.ApiVersion = $infoVersion
130+
$serviceCredentials = Get-AzServiceCredential
131+
$subscriptionId = Get-AzSubscriptionId
132+
$delegatingHandler = Get-AzDelegatingHandler
133+
134+
$clientName = [$fullModuleName]::new($serviceCredentials, $delegatingHandler)
135+
$clientName.ApiVersion = '$infoVersion'
134136
$clientName.SubscriptionId = $subscriptionId
135-
$operationVar = $clientName.$operations.$methodName($requiredParamList)
137+
138+
Write-Verbose 'Performing operation $methodName on $clientName.'
139+
$taskResult = $clientName.$operations.$methodName($requiredParamList)
140+
Write-Verbose "Waiting for the operation to complete."
141+
$taskResult.AsyncWaitHandle.WaitOne() | out-null
142+
Write-Verbose "Operation Completed."
143+
$taskResult.Result.Body.Value
136144
'@
137145

138146
$commandName = ProcessOperationId $jsonPathItemObject.operationId
@@ -190,9 +198,9 @@ $functionBodyStr = @'
190198
# Handle the function body
191199
#region Function Body
192200
$infoVersion = $Global:parameters['infoVersion']
193-
$modulePostfix = $Global:parameters['infoTitle'] + '.' + $Global:parameters['infoName']
201+
$modulePostfix = $Global:parameters['infoName']
194202
$fullModuleName = $Global:parameters['namespace'] + '.' + $modulePostfix
195-
$clientName = '$' + $modulePostfix.Split('.')[$_.count - 1]
203+
$clientName = '$' + $modulePostfix
196204

197205
$operationName = $jsonPathItemObject.operationId.Split('_')[0]
198206
$operationType = $jsonPathItemObject.operationId.Split('_')[1]
@@ -202,6 +210,8 @@ $functionBodyStr = @'
202210

203211
$serviceCredentials = '$' + 'serviceCredentials'
204212
$subscriptionId = '$' + 'subscriptionId'
213+
$delegatingHandler = '$' + 'delegatingHandler'
214+
$taskResult = '$taskResult'
205215

206216
$body = $executionContext.InvokeCommand.ExpandString($functionBodyStr)
207217

@@ -219,7 +229,7 @@ function ProcessOperationId
219229
param([string] $opId)
220230

221231
$cmdNounMap = @{"Create" = "New"; "Activate" = "Enable"; "Delete" = "Remove";
222-
"List" = "Get"}
232+
"List" = "GetAll"}
223233
$opIdValues = $opId.Split('_')
224234
$cmdNoun = $opIdValues[0]
225235
$cmdVerb = $opIdValues[1]
@@ -337,7 +347,7 @@ function GenerateCsharpCode
337347
del $net45Dir -Force -Recurse
338348
}
339349

340-
& $autoRestExePath -input $swaggerSpecPath -CodeGenerator CSharp -OutputDirectory $generatedCSharpPath -NameSpace $nameSpace
350+
& $autoRestExePath -AddCredentials -input $swaggerSpecPath -CodeGenerator CSharp -OutputDirectory $generatedCSharpPath -NameSpace $nameSpace
341351
if ($LastExitCode)
342352
{
343353
throw "AutoRest resulted in an error"
@@ -376,7 +386,7 @@ function GenerateModuleManifest
376386
Add-Type -LiteralPath "$PSScriptRoot\azure.csharp.ps.generated.dll"
377387
'@ | out-file -Encoding Ascii $startUpScriptFile
378388

379-
New-ModuleManifest -Path $moduleManifestFile -Guid (New-Guid) -Author (whoami) -ScriptsToProcess ($moduleName + ".StartupScript.ps1") -RequiredModules "Generated.Azure.Common.Helpers" -RootModule "$rootModule"
389+
New-ModuleManifest -Path $moduleManifestFile -Guid (New-Guid) -Author (whoami) -ScriptsToProcess ($moduleName + ".StartupScript.ps1") -RequiredModules "Generated.Azure.Common.Helpers" -RootModule "$rootModule" -FunctionsToExport '*'
380390
}
381391

382392
#endregion

0 commit comments

Comments
 (0)