Skip to content

Commit 76989a3

Browse files
authored
Merge pull request Azure#4837 from solankisamir/apim_nov
[ApiManagement] Secure Parameter for Cmdlets
2 parents d5c138b + 3baf55f commit 76989a3

File tree

101 files changed

+3138
-1161
lines changed

Some content is hidden

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

101 files changed

+3138
-1161
lines changed

src/ResourceManager/ApiManagement/ChangeLog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Breaking Changes in Cmdlet to Manage Api Management Users
22+
- New-AzureRmApiManagementUser Parameter `Password` is changed from String to SecureString
23+
- Set-AzureRmApiManagementBackend Parameter `Password` is changed from String to SecureString
24+
25+
* Breaking Changes in Cmdlet to Create Backend Proxy Object
26+
- New-AzureRmApiManagementBackendProxy Parameter `Password` and `UserName` have been replaced with `ProxyCredentials` of type PSCredential
27+
28+
* Updated Cmdlet Get-AzureRmApiManagementUser to fix issue https://github.com/Azure/azure-powershell/issues/4510
29+
30+
* Updated Cmdlet New-AzureRmApiManagementApi to create Api with Empty Path https://github.com/Azure/azure-powershell/issues/4069
2131

2232
## Version 4.4.1
2333

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement
3131
using System.Collections.Generic;
3232
using System.IO;
3333
using System.Linq;
34+
using System.Management.Automation;
3435
using System.Net;
3536
using System.Text;
3637
using System.Text.RegularExpressions;
@@ -190,8 +191,15 @@ private static void ConfigureSmapiToPowershellMappings()
190191
Mapper
191192
.CreateMap<BackendProxyContract, PsApiManagementBackendProxy>()
192193
.ForMember(dest => dest.Url, opt => opt.MapFrom(src => src.Url))
193-
.ForMember(dest => dest.Password, opt => opt.MapFrom(src => src.Password))
194-
.ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.Username));
194+
.ForMember(dest => dest.ProxyCredentials, opt => opt.MapFrom(src =>
195+
string.IsNullOrEmpty(src.Password) ? PSCredential.Empty :
196+
new PSCredential(src.Username, src.Password.ConvertToSecureString())));
197+
198+
Mapper
199+
.CreateMap<PsApiManagementBackendProxy, BackendProxyContract>()
200+
.ForMember(dest => dest.Url, opt => opt.MapFrom(src => src.Url))
201+
.ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.ProxyCredentials == PSCredential.Empty ? null : src.ProxyCredentials.UserName))
202+
.ForMember(dest => dest.Password, opt => opt.MapFrom(src => src.ProxyCredentials == PSCredential.Empty ? null : src.ProxyCredentials.Password.ConvertToString()));
195203

196204
Mapper
197205
.CreateMap<BackendCredentialsContract, PsApiManagementBackendCredential>()
@@ -448,7 +456,7 @@ public void ApiImportFromFile(
448456
string apiId,
449457
PsApiManagementApiFormat specificationFormat,
450458
string specificationPath,
451-
string urlSuffix,
459+
string apiPath,
452460
string wsdlServiceName,
453461
string wsdlEndpointName,
454462
PsApiManagementApiType? apiType)
@@ -459,7 +467,7 @@ public void ApiImportFromFile(
459467

460468
using (var fileStream = File.OpenRead(specificationPath))
461469
{
462-
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, fileStream, urlSuffix, wsdlServiceName, wsdlEndpointName, apiTypeValue);
470+
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, fileStream, apiPath, wsdlServiceName, wsdlEndpointName, apiTypeValue);
463471
}
464472
}
465473

@@ -1043,7 +1051,7 @@ private static QueryParameters CreateQueryUserParameters(string firstName, strin
10431051
{
10441052
query.Filter += "&";
10451053
}
1046-
query.Filter = string.Format("lastName eq '{0}'", email);
1054+
query.Filter = string.Format("email eq '{0}'", email);
10471055
isFirstCondition = false;
10481056
}
10491057

@@ -2079,9 +2087,9 @@ public IList<PsApiManagementBackend> BackendsList(PsApiManagementContext context
20792087
return results;
20802088
}
20812089

2082-
public PsApiManagementBackend BackendById(PsApiManagementContext context, string loggerId)
2090+
public PsApiManagementBackend BackendById(PsApiManagementContext context, string backendId)
20832091
{
2084-
var response = Client.Backends.Get(context.ResourceGroupName, context.ServiceName, loggerId);
2092+
var response = Client.Backends.Get(context.ResourceGroupName, context.ServiceName, backendId);
20852093
var backend = Mapper.Map<PsApiManagementBackend>(response.Value);
20862094

20872095
return backend;
@@ -2172,7 +2180,7 @@ public void BackendSet(
21722180

21732181
if (proxy != null)
21742182
{
2175-
backendUpdateParams.Proxy = Mapper.Map<PsApiManagementBackendProxy, BackendProxyContract>(proxy);
2183+
backendUpdateParams.Proxy = Mapper.Map<BackendProxyContract>(proxy);
21762184
}
21772185

21782186
Client.Backends.Update(

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ public override void ExecuteApiManagementCmdlet()
8989
var user = Client.UserById(Context, UserId);
9090
WriteObject(user);
9191
}
92-
else
92+
else
9393
{
94-
throw new InvalidOperationException(string.Format("Parameter set name '{0}' is not supported.", ParameterSetName));
94+
var user = Client.UsersList(Context, FirstName, LastName, Email, State, GroupId);
95+
WriteObject(user, true);
9596
}
9697
}
9798
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public class NewAzureApiManagementApi : AzureApiManagementCmdletBase
6161
ValueFromPipelineByPropertyName = true,
6262
Mandatory = true,
6363
HelpMessage = "Web API Path. Last part of the API's public URL. This URL will be used by API consumers for sending requests to the web service." +
64-
" Must be 1 to 400 characters long. This parameter is required.")]
65-
[ValidateNotNullOrEmpty]
64+
" Must be 0 to 400 characters long. This parameter is required.")]
65+
[ValidateNotNull]
6666
public String Path { get; set; }
6767

6868
[Parameter(

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,16 @@ public class NewAzureApiManagementBackendProxy : AzureApiManagementCmdletBase
3535
[Parameter(
3636
ValueFromPipelineByPropertyName = false,
3737
Mandatory = false,
38-
HelpMessage = "UserName used to connect to Backend Proxy. This parameter is optional.")]
39-
[Obsolete("New-AzureRmApiManagementBackendProxy: The parameter \"UserName\" is being removed in a future release in favor of a new PSCredential parameter (-Credential).")]
40-
public string UserName { get; set; }
41-
42-
[Parameter(
43-
ValueFromPipelineByPropertyName = false,
44-
Mandatory = false,
45-
HelpMessage = "Password used to connect to Backend Proxy. This parameter is optional.")]
46-
[Obsolete("New-AzureRmApiManagementBackendProxy: The parameter \"Password\" is being removed in a future release in favor of a new PSCredential parameter (-Credential).")]
47-
public string Password { get; set; }
38+
HelpMessage = "Credentials used to connect to Backend Proxy. This parameter is optional.")]
39+
public PSCredential ProxyCredential { get; set; }
4840

4941
public override void ExecuteApiManagementCmdlet()
5042
{
5143
WriteObject(
5244
new PsApiManagementBackendProxy
5345
{
5446
Url = Url,
55-
#pragma warning disable 0618
56-
UserName = UserName,
57-
Password = Password
58-
#pragma warning restore 0618
47+
ProxyCredentials = ProxyCredential != null ? ProxyCredential : PSCredential.Empty
5948
});
6049
}
6150
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
1717
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models;
1818
using System;
1919
using System.Management.Automation;
20+
using System.Security;
21+
using WindowsAzure.Commands.Common;
2022

2123
[Cmdlet(VerbsCommon.New, Constants.ApiManagementUser)]
2224
[OutputType(typeof(PsApiManagementUser))]
@@ -61,8 +63,7 @@ public class NewAzureApiManagementUser : AzureApiManagementCmdletBase
6163
Mandatory = true,
6264
HelpMessage = "User password. This parameter is required.")]
6365
[ValidateNotNullOrEmpty]
64-
[Obsolete("New-AzureRmApiManagementUser: The parameter \"Password\" is being changed from a string to a SecureString in an upcoming breaking change release.")]
65-
public String Password { get; set; }
66+
public SecureString Password { get; set; }
6667

6768
[Parameter(
6869
ValueFromPipelineByPropertyName = true,
@@ -79,10 +80,8 @@ public class NewAzureApiManagementUser : AzureApiManagementCmdletBase
7980
public override void ExecuteApiManagementCmdlet()
8081
{
8182
string userId = UserId ?? Guid.NewGuid().ToString("N");
82-
83-
#pragma warning disable 0618
84-
var user = Client.UserCreate(Context, userId, FirstName, LastName, Password, Email, State, Note);
85-
#pragma warning restore 0618
83+
84+
var user = Client.UserCreate(Context, userId, FirstName, LastName, Password.ConvertToString(), Email, State, Note);
8685

8786
WriteObject(user);
8887
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
1717
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models;
1818
using System;
1919
using System.Management.Automation;
20+
using System.Security;
21+
using WindowsAzure.Commands.Common;
2022

2123
[Cmdlet(VerbsCommon.Set, Constants.ApiManagementUser)]
2224
[OutputType(typeof(PsApiManagementUser))]
@@ -58,8 +60,7 @@ public class SetAzureApiManagementUser : AzureApiManagementCmdletBase
5860
ValueFromPipelineByPropertyName = true,
5961
Mandatory = false,
6062
HelpMessage = "User password. This parameter is optional.")]
61-
[Obsolete("Set-AzureRmApiManagementUser: The parameter \"Password\" is being changed from a string to a SecureString in an upcoming breaking change release.")]
62-
public String Password { get; set; }
63+
public SecureString Password { get; set; }
6364

6465
[Parameter(
6566
ValueFromPipelineByPropertyName = true,
@@ -83,9 +84,7 @@ public class SetAzureApiManagementUser : AzureApiManagementCmdletBase
8384

8485
public override void ExecuteApiManagementCmdlet()
8586
{
86-
#pragma warning disable 0618
87-
Client.UserSet(Context, UserId, FirstName, LastName, Password, Email, State, Note);
88-
#pragma warning restore 0618
87+
Client.UserSet(Context, UserId, FirstName, LastName, Password != null ? Password.ConvertToString() : null, Email, State, Note);
8988

9089
if (PassThru)
9190
{

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Models/PsApiManagementBackendProxy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models
1616
{
17+
using System.Management.Automation;
18+
1719
public class PsApiManagementBackendProxy
1820
{
1921
public string Url { get; set; }
2022

21-
public string UserName { get; set; }
22-
23-
public string Password { get; set; }
23+
public PSCredential ProxyCredentials { get; set; }
2424
}
2525
}

src/ResourceManager/ApiManagement/Commands.ApiManagement/help/Add-AzureRmApiManagementApiToProduct.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Adds an API to a product.
1414

1515
```
1616
Add-AzureRmApiManagementApiToProduct -Context <PsApiManagementContext> -ProductId <String> -ApiId <String>
17-
[-PassThru] [<CommonParameters>]
17+
[-PassThru] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
1818
```
1919

2020
## DESCRIPTION
@@ -24,6 +24,7 @@ The **Add-AzureRmApiManagementApiToProduct** cmdlet adds an Azure API Management
2424

2525
### Example 1: Add an API to a product
2626
```
27+
PS C:\>$ApiMgmtContext = New-AzureRmApiManagementContext -ResourceGroupName "Api-Default-WestUS" -ServiceName "contoso"
2728
PS C:\>Add-AzureRmApiManagementApiToProduct -Context $ApiMgmtContext -ProductId "0123456789" -ApiId "0001"
2829
```
2930

@@ -61,6 +62,21 @@ Accept pipeline input: True (ByPropertyName)
6162
Accept wildcard characters: False
6263
```
6364
65+
### -DefaultProfile
66+
The credentials, account, tenant, and subscription used for communication with azure.
67+
68+
```yaml
69+
Type: IAzureContextContainer
70+
Parameter Sets: (All)
71+
Aliases: AzureRmContext, AzureCredential
72+
73+
Required: False
74+
Position: Named
75+
Default value: None
76+
Accept pipeline input: False
77+
Accept wildcard characters: False
78+
```
79+
6480
### -PassThru
6581
passthru
6682

src/ResourceManager/ApiManagement/Commands.ApiManagement/help/Add-AzureRmApiManagementProductToGroup.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Adds a product to a group.
1414

1515
```
1616
Add-AzureRmApiManagementProductToGroup -Context <PsApiManagementContext> -GroupId <String> -ProductId <String>
17-
[-PassThru] [<CommonParameters>]
17+
[-PassThru] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
1818
```
1919

2020
## DESCRIPTION
@@ -25,6 +25,7 @@ In other words, this cmdlet assigns a group to a product.
2525

2626
### Example 1: Add a product to a group
2727
```
28+
PS C:\>$apimContext = New-AzureRmApiManagementContext -ResourceGroupName "Api-Default-WestUS" -ServiceName "contoso"
2829
PS C:\>Add-AzureRmApiManagementProductToGroup -Context $apimContext -GroupId "0001" -ProductId "0123456789"
2930
```
3031

@@ -48,6 +49,21 @@ Accept pipeline input: True (ByPropertyName)
4849
Accept wildcard characters: False
4950
```
5051
52+
### -DefaultProfile
53+
The credentials, account, tenant, and subscription used for communication with azure.
54+
55+
```yaml
56+
Type: IAzureContextContainer
57+
Parameter Sets: (All)
58+
Aliases: AzureRmContext, AzureCredential
59+
60+
Required: False
61+
Position: Named
62+
Default value: None
63+
Accept pipeline input: False
64+
Accept wildcard characters: False
65+
```
66+
5167
### -GroupId
5268
Specifies the group ID.
5369
This parameter is required.

src/ResourceManager/ApiManagement/Commands.ApiManagement/help/Add-AzureRmApiManagementRegion.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Adds new deployment regions to a PsApiManagement instance.
1414

1515
```
1616
Add-AzureRmApiManagementRegion -ApiManagement <PsApiManagement> -Location <String> [-Sku <PsApiManagementSku>]
17-
[-Capacity <Int32>] [-VirtualNetwork <PsApiManagementVirtualNetwork>] [<CommonParameters>]
17+
[-Capacity <Int32>] [-VirtualNetwork <PsApiManagementVirtualNetwork>]
18+
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
1819
```
1920

2021
## DESCRIPTION
@@ -70,26 +71,26 @@ Accept pipeline input: False
7071
Accept wildcard characters: False
7172
```
7273
73-
### -Location
74-
Specifies the location of the new deployment region.
74+
### -DefaultProfile
75+
The credentials, account, tenant, and subscription used for communication with azure.
76+
77+
```yaml
78+
Type: IAzureContextContainer
79+
Parameter Sets: (All)
80+
Aliases: AzureRmContext, AzureCredential
7581

76-
Valid values are:
82+
Required: False
83+
Position: Named
84+
Default value: None
85+
Accept pipeline input: False
86+
Accept wildcard characters: False
87+
```
7788
78-
- North Central US
79-
- South Central US
80-
- Central US
81-
- West Europe
82-
- North Europe
83-
- West US
84-
- East US
85-
- East US 2
86-
- Japan East
87-
- Japan West
88-
- Brazil South
89-
- Southeast Asia
90-
- East Asia
91-
- Australia East
92-
- Australia Southeast
89+
### -Location
90+
Specifies the location of the new deployment region amongst the supported region for Api Management service.
91+
92+
To obtain valid locations, use the cmdlet
93+
Get-AzureRmResourceProvider -ProviderNamespace "Microsoft.ApiManagement" | where {$_.ResourceTypes[0].ResourceTypeName -eq "service"} | Select-Object Locations
9394
9495
```yaml
9596
Type: String
@@ -145,7 +146,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
145146
## INPUTS
146147
147148
### PsApiManagement
148-
149149
Parameter 'ApiManagement' accepts value of type 'PsApiManagement' from the pipeline
150150
151151
## OUTPUTS

0 commit comments

Comments
 (0)