Skip to content

[ApiManagement] Secure Parameter for Cmdlets #4837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ResourceManager/ApiManagement/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
- Additional information about change #1
-->
## Current Release
* Breaking Changes in Cmdlet to Manage Api Management Users
- New-AzureRmApiManagementUser Parameter `Password` is changed from String to SecureString
- Set-AzureRmApiManagementBackend Parameter `Password` is changed from String to SecureString

* Breaking Changes in Cmdlet to Create Backend Proxy Object
- New-AzureRmApiManagementBackendProxy Parameter `Password` and `UserName` have been replaced with `ProxyCredentials` of type PSCredential

* Updated Cmdlet Get-AzureRmApiManagementUser to fix issue https://github.com/Azure/azure-powershell/issues/4510

* Updated Cmdlet New-AzureRmApiManagementApi to create Api with Empty Path https://github.com/Azure/azure-powershell/issues/4069

## Version 4.4.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -190,8 +191,15 @@ private static void ConfigureSmapiToPowershellMappings()
Mapper
.CreateMap<BackendProxyContract, PsApiManagementBackendProxy>()
.ForMember(dest => dest.Url, opt => opt.MapFrom(src => src.Url))
.ForMember(dest => dest.Password, opt => opt.MapFrom(src => src.Password))
.ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.Username));
.ForMember(dest => dest.ProxyCredentials, opt => opt.MapFrom(src =>
string.IsNullOrEmpty(src.Password) ? PSCredential.Empty :
new PSCredential(src.Username, src.Password.ConvertToSecureString())));

Mapper
.CreateMap<PsApiManagementBackendProxy, BackendProxyContract>()
.ForMember(dest => dest.Url, opt => opt.MapFrom(src => src.Url))
.ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.ProxyCredentials == PSCredential.Empty ? null : src.ProxyCredentials.UserName))
.ForMember(dest => dest.Password, opt => opt.MapFrom(src => src.ProxyCredentials == PSCredential.Empty ? null : src.ProxyCredentials.Password.ConvertToString()));

Mapper
.CreateMap<BackendCredentialsContract, PsApiManagementBackendCredential>()
Expand Down Expand Up @@ -448,7 +456,7 @@ public void ApiImportFromFile(
string apiId,
PsApiManagementApiFormat specificationFormat,
string specificationPath,
string urlSuffix,
string apiPath,
string wsdlServiceName,
string wsdlEndpointName,
PsApiManagementApiType? apiType)
Expand All @@ -459,7 +467,7 @@ public void ApiImportFromFile(

using (var fileStream = File.OpenRead(specificationPath))
{
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, fileStream, urlSuffix, wsdlServiceName, wsdlEndpointName, apiTypeValue);
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, fileStream, apiPath, wsdlServiceName, wsdlEndpointName, apiTypeValue);
}
}

Expand Down Expand Up @@ -1043,7 +1051,7 @@ private static QueryParameters CreateQueryUserParameters(string firstName, strin
{
query.Filter += "&";
}
query.Filter = string.Format("lastName eq '{0}'", email);
query.Filter = string.Format("email eq '{0}'", email);
isFirstCondition = false;
}

Expand Down Expand Up @@ -2079,9 +2087,9 @@ public IList<PsApiManagementBackend> BackendsList(PsApiManagementContext context
return results;
}

public PsApiManagementBackend BackendById(PsApiManagementContext context, string loggerId)
public PsApiManagementBackend BackendById(PsApiManagementContext context, string backendId)
{
var response = Client.Backends.Get(context.ResourceGroupName, context.ServiceName, loggerId);
var response = Client.Backends.Get(context.ResourceGroupName, context.ServiceName, backendId);
var backend = Mapper.Map<PsApiManagementBackend>(response.Value);

return backend;
Expand Down Expand Up @@ -2172,7 +2180,7 @@ public void BackendSet(

if (proxy != null)
{
backendUpdateParams.Proxy = Mapper.Map<PsApiManagementBackendProxy, BackendProxyContract>(proxy);
backendUpdateParams.Proxy = Mapper.Map<BackendProxyContract>(proxy);
}

Client.Backends.Update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ public override void ExecuteApiManagementCmdlet()
var user = Client.UserById(Context, UserId);
WriteObject(user);
}
else
else
{
throw new InvalidOperationException(string.Format("Parameter set name '{0}' is not supported.", ParameterSetName));
var user = Client.UsersList(Context, FirstName, LastName, Email, State, GroupId);
WriteObject(user, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public class NewAzureApiManagementApi : AzureApiManagementCmdletBase
ValueFromPipelineByPropertyName = true,
Mandatory = true,
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." +
" Must be 1 to 400 characters long. This parameter is required.")]
[ValidateNotNullOrEmpty]
" Must be 0 to 400 characters long. This parameter is required.")]
[ValidateNotNull]
public String Path { get; set; }

[Parameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,16 @@ public class NewAzureApiManagementBackendProxy : AzureApiManagementCmdletBase
[Parameter(
ValueFromPipelineByPropertyName = false,
Mandatory = false,
HelpMessage = "UserName used to connect to Backend Proxy. This parameter is optional.")]
[Obsolete("New-AzureRmApiManagementBackendProxy: The parameter \"UserName\" is being removed in a future release in favor of a new PSCredential parameter (-Credential).")]
public string UserName { get; set; }

[Parameter(
ValueFromPipelineByPropertyName = false,
Mandatory = false,
HelpMessage = "Password used to connect to Backend Proxy. This parameter is optional.")]
[Obsolete("New-AzureRmApiManagementBackendProxy: The parameter \"Password\" is being removed in a future release in favor of a new PSCredential parameter (-Credential).")]
public string Password { get; set; }
HelpMessage = "Credentials used to connect to Backend Proxy. This parameter is optional.")]
public PSCredential ProxyCredential { get; set; }

public override void ExecuteApiManagementCmdlet()
{
WriteObject(
new PsApiManagementBackendProxy
{
Url = Url,
#pragma warning disable 0618
UserName = UserName,
Password = Password
#pragma warning restore 0618
ProxyCredentials = ProxyCredential != null ? ProxyCredential : PSCredential.Empty
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models;
using System;
using System.Management.Automation;
using System.Security;
using WindowsAzure.Commands.Common;

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

[Parameter(
ValueFromPipelineByPropertyName = true,
Expand All @@ -79,10 +80,8 @@ public class NewAzureApiManagementUser : AzureApiManagementCmdletBase
public override void ExecuteApiManagementCmdlet()
{
string userId = UserId ?? Guid.NewGuid().ToString("N");

#pragma warning disable 0618
var user = Client.UserCreate(Context, userId, FirstName, LastName, Password, Email, State, Note);
#pragma warning restore 0618

var user = Client.UserCreate(Context, userId, FirstName, LastName, Password.ConvertToString(), Email, State, Note);

WriteObject(user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models;
using System;
using System.Management.Automation;
using System.Security;
using WindowsAzure.Commands.Common;

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

[Parameter(
ValueFromPipelineByPropertyName = true,
Expand All @@ -83,9 +84,7 @@ public class SetAzureApiManagementUser : AzureApiManagementCmdletBase

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

if (PassThru)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models
{
using System.Management.Automation;

public class PsApiManagementBackendProxy
{
public string Url { get; set; }

public string UserName { get; set; }

public string Password { get; set; }
public PSCredential ProxyCredentials { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Adds an API to a product.

```
Add-AzureRmApiManagementApiToProduct -Context <PsApiManagementContext> -ProductId <String> -ApiId <String>
[-PassThru] [<CommonParameters>]
[-PassThru] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

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

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

Expand Down Expand Up @@ -61,6 +62,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -DefaultProfile
The credentials, account, tenant, and subscription used for communication with azure.

```yaml
Type: IAzureContextContainer
Parameter Sets: (All)
Aliases: AzureRmContext, AzureCredential

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -PassThru
passthru

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Adds a product to a group.

```
Add-AzureRmApiManagementProductToGroup -Context <PsApiManagementContext> -GroupId <String> -ProductId <String>
[-PassThru] [<CommonParameters>]
[-PassThru] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

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

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

Expand All @@ -48,6 +49,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -DefaultProfile
The credentials, account, tenant, and subscription used for communication with azure.

```yaml
Type: IAzureContextContainer
Parameter Sets: (All)
Aliases: AzureRmContext, AzureCredential

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -GroupId
Specifies the group ID.
This parameter is required.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Adds new deployment regions to a PsApiManagement instance.

```
Add-AzureRmApiManagementRegion -ApiManagement <PsApiManagement> -Location <String> [-Sku <PsApiManagementSku>]
[-Capacity <Int32>] [-VirtualNetwork <PsApiManagementVirtualNetwork>] [<CommonParameters>]
[-Capacity <Int32>] [-VirtualNetwork <PsApiManagementVirtualNetwork>]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -70,26 +71,26 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Location
Specifies the location of the new deployment region.
### -DefaultProfile
The credentials, account, tenant, and subscription used for communication with azure.

```yaml
Type: IAzureContextContainer
Parameter Sets: (All)
Aliases: AzureRmContext, AzureCredential

Valid values are:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

- North Central US
- South Central US
- Central US
- West Europe
- North Europe
- West US
- East US
- East US 2
- Japan East
- Japan West
- Brazil South
- Southeast Asia
- East Asia
- Australia East
- Australia Southeast
### -Location
Specifies the location of the new deployment region amongst the supported region for Api Management service.

To obtain valid locations, use the cmdlet
Get-AzureRmResourceProvider -ProviderNamespace "Microsoft.ApiManagement" | where {$_.ResourceTypes[0].ResourceTypeName -eq "service"} | Select-Object Locations

```yaml
Type: String
Expand Down Expand Up @@ -145,7 +146,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## INPUTS

### PsApiManagement

Parameter 'ApiManagement' accepts value of type 'PsApiManagement' from the pipeline

## OUTPUTS
Expand Down
Loading