Skip to content

Commit 771e3ee

Browse files
authored
Merge pull request Azure#3247 from solankisamir/dev
[ApiManagement] Identity Provider Endpoint + RBAC changes + SoapToRes…
2 parents 0c84c55 + 2662e64 commit 771e3ee

File tree

60 files changed

+15568
-16144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+15568
-16144
lines changed

src/ResourceManager/ApiManagement/AzureRM.ApiManagement.psd1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ CmdletsToExport = 'Add-AzureRmApiManagementRegion',
140140
'Set-AzureRmApiManagementProperty',
141141
'Set-AzureRmApiManagementSubscription',
142142
'Set-AzureRmApiManagementUser',
143-
'Set-AzureRmApiManagementTenantAccess'
143+
'Set-AzureRmApiManagementTenantAccess',
144+
'Get-AzureRmApiManagementIdentityProvider',
145+
'New-AzureRmApiManagementIdentityProvider',
146+
'Set-AzureRmApiManagementIdentityProvider',
147+
'Remove-AzureRmApiManagementIdentityProvider'
144148

145149
# Variables to export from this module
146150
# VariablesToExport = @()

src/ResourceManager/ApiManagement/ChangeLog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Added new cmdlets to manage external Identity Provider Configurations
22+
- New-AzureRmApiManagementIdentityProvider
23+
- Set-AzureRmApiManagementIdentityProvider
24+
- Get-AzureRmApiManagementIdentityProvider
25+
- Remove-AzureRmApiManagementIdentityProvider
26+
27+
* Updated the client to use .net client 3.2.0 AzureRm.ApiManagement which has RBAC support
28+
* Updated cmdlet Import-AzureRmApiManagementApi to allow importing an Wsdl type API as either Soap Pass Through (ApiType = Http) or Soap To Rest (ApiType = Soap). Default is Soap Pass Through.
29+
* Fixed Issue https://github.com/Azure/azure-powershell/issues/3217
2130

2231
## Version 3.1.0
2332
* Fixed cmdlet Import-AzureRmApiManagementApi when importing Api by SpecificationByUrl parameter

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/ApiManagementClient.cs

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public class ApiManagementClient
5252

5353
static ApiManagementClient()
5454
{
55-
ConfugureMappings();
55+
ConfigureMappings();
5656
}
5757

58-
private static void ConfugureMappings()
58+
private static void ConfigureMappings()
5959
{
6060
ConfigureSmapiToPowershellMappings();
6161
ConfigurePowershellToSmapiMappings();
@@ -176,6 +176,13 @@ private static void ConfigureSmapiToPowershellMappings()
176176
.ForMember(dest => dest.SecondaryKey, opt => opt.MapFrom(src => src.SecondaryKey));
177177

178178
Mapper.CreateMap<TenantConfigurationSyncStateContract, PsApiManagementTenantConfigurationSyncState>();
179+
180+
Mapper
181+
.CreateMap<IdentityProviderContract, PsApiManagementIdentityProvider>()
182+
.ForMember(dest => dest.ClientId, opt => opt.MapFrom(src => src.ClientId))
183+
.ForMember(dest => dest.ClientSecret, opt => opt.MapFrom(src => src.ClientSecret))
184+
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.Type))
185+
.ForMember(dest => dest.AllowedTenants, opt => opt.MapFrom(src => src.AllowedTenants == null ? new string[0] : src.AllowedTenants.ToArray()));
179186
}
180187

181188
public ApiManagementClient(AzureContext context)
@@ -403,13 +410,16 @@ public void ApiImportFromFile(
403410
string specificationPath,
404411
string urlSuffix,
405412
string wsdlServiceName,
406-
string wsdlEndpointName)
413+
string wsdlEndpointName,
414+
PsApiManagementApiType? apiType)
407415
{
408416
string contentType = GetHeaderForApiExportImport(true, specificationFormat, wsdlServiceName, wsdlEndpointName, true);
409417

418+
string apiTypeValue = GetApiTypeForImport(specificationFormat, apiType);
419+
410420
using (var fileStream = File.OpenRead(specificationPath))
411421
{
412-
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, fileStream, urlSuffix, wsdlServiceName, wsdlEndpointName);
422+
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, fileStream, urlSuffix, wsdlServiceName, wsdlEndpointName, apiTypeValue);
413423
}
414424
}
415425

@@ -420,10 +430,13 @@ public void ApiImportFromUrl(
420430
string specificationUrl,
421431
string urlSuffix,
422432
string wsdlServiceName,
423-
string wsdlEndpointName)
433+
string wsdlEndpointName,
434+
PsApiManagementApiType? apiType)
424435
{
425436
string contentType = GetHeaderForApiExportImport(false, specificationFormat, wsdlServiceName, wsdlEndpointName, true);
426437

438+
string apiTypeValue = GetApiTypeForImport(specificationFormat, apiType);
439+
427440
var jobj = JObject.FromObject(
428441
new
429442
{
@@ -432,7 +445,7 @@ public void ApiImportFromUrl(
432445

433446
using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(jobj.ToString(Formatting.None))))
434447
{
435-
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, memoryStream, urlSuffix, wsdlServiceName, wsdlEndpointName);
448+
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, memoryStream, urlSuffix, wsdlServiceName, wsdlEndpointName, apiTypeValue);
436449
}
437450
}
438451

@@ -483,6 +496,18 @@ private string GetHeaderForApiExportImport(
483496
return headerValue;
484497
}
485498

499+
private string GetApiTypeForImport(
500+
PsApiManagementApiFormat specificationFormat,
501+
PsApiManagementApiType? apiType)
502+
{
503+
if (specificationFormat != PsApiManagementApiFormat.Wsdl)
504+
{
505+
return null;
506+
}
507+
508+
return apiType.HasValue ? apiType.Value.ToString("g") : PsApiManagementApiType.Http.ToString("g");
509+
}
510+
486511
public void ApiAddToProduct(PsApiManagementContext context, string productId, string apiId)
487512
{
488513
Client.ProductApis.Add(context.ResourceGroupName, context.ServiceName, productId, apiId);
@@ -1780,5 +1805,79 @@ public void TenantAccessSet(
17801805
Client.TenantAccess.Update(context.ResourceGroupName, context.ServiceName, accessInformationParams, "*");
17811806
}
17821807
#endregion
1808+
1809+
#region IdentityProvider
1810+
public PsApiManagementIdentityProvider IdentityProviderCreate(
1811+
PsApiManagementContext context,
1812+
string identityProviderName,
1813+
string clientId,
1814+
string clientSecret,
1815+
string[] allowedTenants)
1816+
{
1817+
var identityProviderCreateParameters = new IdentityProviderCreateParameters(clientId, clientSecret);
1818+
if (allowedTenants != null)
1819+
{
1820+
identityProviderCreateParameters.AllowedTenants = allowedTenants;
1821+
}
1822+
1823+
Client.IdentityProvider.Create(context.ResourceGroupName, context.ServiceName, identityProviderName,
1824+
identityProviderCreateParameters);
1825+
1826+
var response = Client.IdentityProvider.Get(context.ResourceGroupName, context.ServiceName, identityProviderName);
1827+
var identityProvider = Mapper.Map<PsApiManagementIdentityProvider>(response.Value);
1828+
1829+
return identityProvider;
1830+
}
1831+
1832+
public IList<PsApiManagementIdentityProvider> IdentityProviderList(PsApiManagementContext context)
1833+
{
1834+
var identityProviderListResponse = Client.IdentityProvider.List(context.ResourceGroupName, context.ServiceName,
1835+
new QueryParameters());
1836+
1837+
var results = Mapper.Map<IList<PsApiManagementIdentityProvider>>(identityProviderListResponse.Result);
1838+
1839+
return results;
1840+
}
1841+
1842+
public PsApiManagementIdentityProvider IdentityProviderByName(PsApiManagementContext context, string identityProviderName)
1843+
{
1844+
var response = Client.IdentityProvider.Get(context.ResourceGroupName, context.ServiceName,
1845+
identityProviderName);
1846+
var identityProvider = Mapper.Map<PsApiManagementIdentityProvider>(response.Value);
1847+
1848+
return identityProvider;
1849+
}
1850+
1851+
public void IdentityProviderRemove(PsApiManagementContext context, string identityProviderName)
1852+
{
1853+
Client.IdentityProvider.Delete(context.ResourceGroupName, context.ServiceName, identityProviderName, "*");
1854+
}
1855+
1856+
public void IdentityProviderSet(PsApiManagementContext context, string identityProviderName, string clientId, string clientSecret, string[] allowedTenant)
1857+
{
1858+
var parameters = new IdentityProviderUpdateParameters();
1859+
if (!string.IsNullOrEmpty(clientId))
1860+
{
1861+
parameters.ClientId = clientId;
1862+
}
1863+
1864+
if (!string.IsNullOrEmpty(clientSecret))
1865+
{
1866+
parameters.ClientSecret = clientSecret;
1867+
}
1868+
1869+
if (allowedTenant != null)
1870+
{
1871+
parameters.AllowedTenants = allowedTenant;
1872+
}
1873+
1874+
Client.IdentityProvider.Update(
1875+
context.ResourceGroupName,
1876+
context.ServiceName,
1877+
identityProviderName,
1878+
parameters,
1879+
"*");
1880+
}
1881+
#endregion
17831882
}
17841883
}

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands.ApiManagement.ServiceManagement.csproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
<HintPath>..\..\..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll</HintPath>
6767
<Private>True</Private>
6868
</Reference>
69-
<Reference Include="Microsoft.Azure.Management.ApiManagement, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
69+
<Reference Include="Microsoft.Azure.Management.ApiManagement, Version=3.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7070
<SpecificVersion>False</SpecificVersion>
71-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ApiManagement.3.1.0-preview\lib\net45\Microsoft.Azure.Management.ApiManagement.dll</HintPath>
71+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ApiManagement.3.2.0-preview\lib\net45\Microsoft.Azure.Management.ApiManagement.dll</HintPath>
7272
<Private>True</Private>
7373
</Reference>
7474
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -151,6 +151,7 @@
151151
<Compile Include="Commands\GetAzureApiManagementAuthorizationServer.cs" />
152152
<Compile Include="Commands\GetAzureApiManagementCertificate.cs" />
153153
<Compile Include="Commands\GetAzureApiManagementGroup.cs" />
154+
<Compile Include="Commands\GetAzureApiManagementIdentityProvider.cs" />
154155
<Compile Include="Commands\GetAzureApiManagementLogger.cs" />
155156
<Compile Include="Commands\GetAzureApiManagementOpenIdConnectProvider.cs" />
156157
<Compile Include="Commands\GetAzureApiManagementOperation.cs" />
@@ -169,6 +170,7 @@
169170
<Compile Include="Commands\NewAzureApiManagementCertificate.cs" />
170171
<Compile Include="Commands\NewAzureApiManagementContext.cs" />
171172
<Compile Include="Commands\NewAzureApiManagementGroup.cs" />
173+
<Compile Include="Commands\NewAzureApiManagementIdentityProvider.cs" />
172174
<Compile Include="Commands\NewAzureApiManagementLogger.cs" />
173175
<Compile Include="Commands\NewAzureApiManagementOpenIdConnectProvider.cs" />
174176
<Compile Include="Commands\NewAzureApiManagementOperation.cs" />
@@ -182,6 +184,7 @@
182184
<Compile Include="Commands\RemoveAzureApiManagementAuthorizationServer.cs" />
183185
<Compile Include="Commands\RemoveAzureApiManagementCertificate.cs" />
184186
<Compile Include="Commands\RemoveAzureApiManagementGroup.cs" />
187+
<Compile Include="Commands\RemoveAzureApiManagementIdentityProvider.cs" />
185188
<Compile Include="Commands\RemoveAzureApiManagementLogger.cs" />
186189
<Compile Include="Commands\RemoveAzureApiManagementOpenIdConnectProvider.cs" />
187190
<Compile Include="Commands\RemoveAzureApiManagementOperation.cs" />
@@ -197,6 +200,7 @@
197200
<Compile Include="Commands\SetAzureApiManagementAuthorizationServer.cs" />
198201
<Compile Include="Commands\SetAzureApiManagementCertificate.cs" />
199202
<Compile Include="Commands\SetAzureApiManagementGroup.cs" />
203+
<Compile Include="Commands\SetAzureApiManagementIdentityProvider.cs" />
200204
<Compile Include="Commands\SetAzureApiManagementLogger.cs" />
201205
<Compile Include="Commands\SetAzureApiManagementOpenIdConnectProvider.cs" />
202206
<Compile Include="Commands\SetAzureApiManagementOperation.cs" />
@@ -209,6 +213,9 @@
209213
<Compile Include="Constants.cs" />
210214
<Compile Include="Models\ErrorBody.cs" />
211215
<Compile Include="Models\ErrorField.cs" />
216+
<Compile Include="Models\PsApiManagementApiType.cs" />
217+
<Compile Include="Models\PsApiManagementIdentityProvider.cs" />
218+
<Compile Include="Models\PsApiManagementIdentityProviderType.cs" />
212219
<Compile Include="Models\PsApiManagementOperationResult.cs" />
213220
<Compile Include="Models\PsApiManagementTenantConfigurationSyncState.cs" />
214221
<Compile Include="Models\TenantConfigurationState.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
16+
{
17+
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
22+
[Cmdlet(VerbsCommon.Get, Constants.ApiManagementIdentityProvider, DefaultParameterSetName = AllIdentityProviders)]
23+
[OutputType(typeof(IList<PsApiManagementIdentityProvider>), ParameterSetName = new[] { AllIdentityProviders })]
24+
[OutputType(typeof(PsApiManagementIdentityProvider), ParameterSetName = new[] { IdentityProviderByType })]
25+
public class GetAzureApiManagementIdentityProvider : AzureApiManagementCmdletBase
26+
{
27+
private const string AllIdentityProviders = "AllIdentityProviders";
28+
private const string IdentityProviderByType = "IdentityProviderByType";
29+
30+
[Parameter(
31+
ValueFromPipelineByPropertyName = true,
32+
Mandatory = true,
33+
HelpMessage = "Instance of PsApiManagementContext. This parameter is required.")]
34+
[ValidateNotNullOrEmpty]
35+
public PsApiManagementContext Context { get; set; }
36+
37+
[Parameter(
38+
ParameterSetName = IdentityProviderByType,
39+
ValueFromPipelineByPropertyName = true,
40+
Mandatory = true,
41+
HelpMessage = "Identifier of a Identity Provider. If specified will try to find identity provider configuration by the identifier. This parameter is optional.")]
42+
public PsApiManagementIdentityProviderType Type { get; set; }
43+
44+
public override void ExecuteApiManagementCmdlet()
45+
{
46+
if (ParameterSetName.Equals(AllIdentityProviders))
47+
{
48+
var identityProviders = Client.IdentityProviderList(Context);
49+
WriteObject(identityProviders, true);
50+
}
51+
else if (ParameterSetName.Equals(IdentityProviderByType))
52+
{
53+
var identityProvider = Client.IdentityProviderByName(Context, Type.ToString("g"));
54+
WriteObject(identityProvider);
55+
}
56+
else
57+
{
58+
throw new InvalidOperationException(string.Format("Parameter set name '{0}' is not supported.", ParameterSetName));
59+
}
60+
}
61+
}
62+
}

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/GetAzureApiManagementLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class GetAzureApiManagementLogger : AzureApiManagementCmdletBase
3737
[Parameter(
3838
ParameterSetName = GetById,
3939
ValueFromPipelineByPropertyName = true,
40-
Mandatory = false,
40+
Mandatory = true,
4141
HelpMessage = "Identifier of a logger. If specified will try to find logger by the identifier. This parameter is optional.")]
4242
public String LoggerId { get; set; }
4343

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/ImportAzureApiManagementApi.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,24 @@ public class ImportAzureApiManagementApi : AzureApiManagementCmdletBase
8181
" Must be 1 to 400 characters long. This parameter is optional and only required for importing Wsdl. Default value is $null.")]
8282
public String WsdlEndpointName { get; set; }
8383

84+
[Parameter(
85+
ValueFromPipelineByPropertyName = true,
86+
Mandatory = false,
87+
HelpMessage = "This parameter is optional with a default value of Http. " +
88+
"The Soap option is only applicable when importing WSDL and will create a SOAP Passthrough API.")]
89+
public PsApiManagementApiType? ApiType { get; set; }
90+
8491
public override void ExecuteApiManagementCmdlet()
8592
{
8693
ApiId = ApiId ?? Guid.NewGuid().ToString("N");
8794

8895
if (ParameterSetName.Equals(FromLocalFile))
8996
{
90-
Client.ApiImportFromFile(Context, ApiId, SpecificationFormat, SpecificationPath, Path, WsdlServiceName, WsdlEndpointName);
97+
Client.ApiImportFromFile(Context, ApiId, SpecificationFormat, SpecificationPath, Path, WsdlServiceName, WsdlEndpointName, ApiType);
9198
}
9299
else if (ParameterSetName.Equals(FromUrl))
93100
{
94-
Client.ApiImportFromUrl(Context, ApiId, SpecificationFormat, SpecificationUrl, Path, WsdlServiceName, WsdlEndpointName);
101+
Client.ApiImportFromUrl(Context, ApiId, SpecificationFormat, SpecificationUrl, Path, WsdlServiceName, WsdlEndpointName, ApiType);
95102
}
96103
else
97104
{

0 commit comments

Comments
 (0)