@@ -14,33 +14,104 @@ function Get-AzureRMCloudCapability() {
1414 [CmdletBinding ()]
1515 [OutputType ([string ])]
1616 Param (
17+ [Parameter (ParameterSetName = " local" )]
18+ [Parameter (ParameterSetName = " url" )]
1719 [Parameter (HelpMessage = ' Json output file' )]
1820 [String ] $OutputPath = " AzureCloudCapabilities.Json" ,
1921
22+ [Parameter (ParameterSetName = " local" )]
23+ [Parameter (ParameterSetName = " url" )]
2024 [Parameter (HelpMessage = ' Cloud Capabilities for the specified location' )]
2125 [String ] $Location ,
2226
27+ [Parameter (Mandatory = $true , HelpMessage = " Directory containing api profile jsons for the supported api profiles. Use this parameter when running in a disconnected environment. Please save the api profile jsons from https://github.com/Azure/azure-rest-api-specs/tree/master/profile to a local directory and pass the location." , ParameterSetName = " local" )]
28+ [ValidateScript ( { Test-Path - Path $_ })]
29+ [String ] $ApiProfilePath ,
30+
31+ [Parameter (HelpMessage = " Url pointing to the location of the supported api profiles" , ParameterSetName = " url" )]
32+ [String ] $ApiProfilesUrl = " https://api.github.com/repos/Azure/azure-rest-api-specs/contents/profile" ,
33+
34+ [Parameter (ParameterSetName = " local" )]
35+ [Parameter (ParameterSetName = " url" )]
2336 [Parameter (HelpMessage = ' Set this to get compute resource provider Capabilities like Extensions, Images, Sizes' )]
2437 [Switch ] $IncludeComputeCapabilities ,
2538
39+ [Parameter (ParameterSetName = " local" )]
40+ [Parameter (ParameterSetName = " url" )]
2641 [Parameter (HelpMessage = ' Set this to get storage resource provider Capabilities like Sku' )]
2742 [Switch ] $IncludeStorageCapabilities
2843 )
2944
3045 $sw = [Diagnostics.Stopwatch ]::StartNew()
3146 Write-Verbose " Getting CloudCapabilities for location: '$location '"
47+
48+ $rootPath = $env: TEMP
49+ $fileDir = " ApiProfiles"
50+ $localDirPath = Join-Path - Path $rootPath - ChildPath $fileDir
51+ if (Test-Path ($localDirPath ))
52+ {
53+ Remove-Item - Path $localDirPath - Recurse - Force - ErrorAction Stop
54+ }
55+ New-Item - Path $rootPath - Name $fileDir - ItemType " directory"
56+ if ($PSCmdlet.ParameterSetName -eq " url" )
57+ {
58+ Write-Verbose " Downloading api profile jsons from '$ApiProfilesUrl '"
59+ try {
60+ $content = Invoke-RestMethod - Method GET - UseBasicParsing - Uri $ApiProfilesUrl
61+ $webClient = [System.Net.WebClient ]::new()
62+ foreach ( $c in $content ) {
63+ $destPath = Join-Path - Path $localDirPath - ChildPath $c.name
64+ $webClient.DownloadFile ($c.download_url , $destPath )
65+ }
66+ }
67+ catch {
68+ $err = " Exception: Unable to get the api profile jsons. ApiProfilesUrl - $ApiProfilesUrl . $ ( $_.Exception.Message ) "
69+ Write-Error $err
70+ }
71+ }
72+ else
73+ {
74+ Write-Verbose " Using api profile jsons from local path: '$ApiProfilePath '"
75+ $localDirPath = $ApiProfilePath
76+ }
77+ Write-Verbose " Reading api profiles jsons..."
78+ $apiProfiles = @ ()
79+ if (Test-Path ($localDirPath )) {
80+ $ApiProfilePattern = " *.json"
81+ $ProfilesDirectory = Get-ChildItem - Path $localDirPath - Recurse - Include $ApiProfilePattern
82+ foreach ($apiProfilejson in $ProfilesDirectory ) {
83+ $apiProfileFileName = Split-path - Path $apiProfilejson.FullName - Leaf
84+ Write-Verbose " Reading api profile $apiProfileFileName "
85+ $apiProfile = ConvertFrom-Json (Get-Content - Path $apiProfilejson - Raw) - ErrorAction Stop
86+ $apiProfileName = $apiProfile.info.name
87+ $apiProfiles += $apiProfile
88+ }
89+ }
90+ else {
91+ Write-Warning " Api profiles jsons not found!"
92+ }
93+
3294 $providerNamespaces = (Get-AzureRmResourceProvider - ListAvailable - Location $location - ErrorAction Stop).ProviderNamespace
3395 $resources = @ ()
3496 foreach ($providerNamespace in $providerNamespaces ) {
3597 Write-Verbose " Working on $providerNamespace provider namespace"
3698 try {
3799 $resourceTypes = (Get-AzureRmResourceProvider - ProviderNamespace $providerNamespace - ErrorAction Stop).ResourceTypes
38100 foreach ($resourceType in $resourceTypes ) {
39- $result = " " | Select-Object ProviderNamespace, ResourceTypeName, Locations, ApiVersions
101+ $result = " " | Select-Object ProviderNamespace, ResourceTypeName, Locations, ApiVersions, ApiProfiles
40102 $result.ProviderNamespace = $providerNamespace
41103 $result.ResourceTypeName = $resourceType.ResourceTypeName
42104 $result.Locations = $resourceType.Locations
43105 $result.ApiVersions = $resourceType.ApiVersions
106+ $profileNames = @ ()
107+ foreach ($apiProfile in $apiProfiles ) {
108+ # if $resourceType.ResourceTypeName exists in $apiProfile add $apiProfile.info.name to $profileNames
109+ $apiProfileProviderNamespace = $apiProfile .' resource-manager' .$providerNamespace
110+ if ($null -ne ($apiProfileProviderNamespace.Psobject.Properties | % { $_.value } | ? { $_ -eq $resourceType.ResourceTypeName } )) {
111+ $profileNames += $apiProfile.info.name
112+ }
113+ }
114+ $result.ApiProfiles = $profileNames
44115 $resources += , $result
45116 }
46117 }
0 commit comments