From e0f5eb752984c0d096c3b2b04d1a0ae7754fb37f Mon Sep 17 00:00:00 2001 From: Samir Solanki Date: Fri, 17 Aug 2018 14:24:25 -0700 Subject: [PATCH] Fix issue #6853 #6814 #6603 https://github.com/Azure/azure-powershell/issues/6814 --- .../ApiManagementClient.cs | 4 ++-- .../Commands/ImportAzureApiManagementApi.cs | 15 ++++++++++++--- .../Commands/NewAzureApiManagementCertificate.cs | 12 ++++++++++-- .../Commands/SetAzureApiManagementCertificate.cs | 12 ++++++++++-- .../Properties/Resources.Designer.cs | 9 +++++++++ .../Properties/Resources.resx | 4 ++++ ...ureApiManagementCustomHostnameConfiguration.cs | 14 +++++++++++--- .../NewAzureApiManagementSystemCertificate.cs | 14 +++++++++++--- .../Properties/Resources.Designer.cs | 9 +++++++++ .../Properties/Resources.resx | 4 ++++ 10 files changed, 82 insertions(+), 15 deletions(-) diff --git a/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/ApiManagementClient.cs b/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/ApiManagementClient.cs index 951384493551..ad73291e4d6c 100644 --- a/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/ApiManagementClient.cs +++ b/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/ApiManagementClient.cs @@ -529,7 +529,7 @@ public IList ApiByName(PsApiManagementContext context, strin context.ServiceName, new Rest.Azure.OData.ODataQuery { - Filter = string.Format("contains('{0}',properties/displayName)", name) + Filter = string.Format("properties/displayName eq '{0}'", name) }), nextLink => Client.Api.ListByServiceNext(nextLink)); @@ -1269,7 +1269,7 @@ public IList ProductList (PsApiManagementContext context var query = new Rest.Azure.OData.ODataQuery(); if (!string.IsNullOrWhiteSpace(title)) { - query.Filter = string.Format("contains('{0}',properties/displayName)", title); + query.Filter = string.Format("properties/displayName eq '{0}'", title); } var results = ListPagedAndMap( diff --git a/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/ImportAzureApiManagementApi.cs b/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/ImportAzureApiManagementApi.cs index 17db8f034d79..bec5985db13c 100644 --- a/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/ImportAzureApiManagementApi.cs +++ b/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/ImportAzureApiManagementApi.cs @@ -14,10 +14,13 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands { - using Models; using System; + using System.Globalization; + using System.IO; using System.Management.Automation; using Management.ApiManagement.Models; + using Models; + using Properties; [Cmdlet("Import", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ApiManagementApi", DefaultParameterSetName = FromLocalFile)] [OutputType(typeof(PsApiManagementApi))] @@ -109,15 +112,21 @@ public override void ExecuteApiManagementCmdlet() else { apiId = Guid.NewGuid().ToString("N"); - } + } if (ParameterSetName.Equals(FromLocalFile)) { + FileInfo localFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.SpecificationPath)); + if (!localFile.Exists) + { + throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.SourceFileNotFound, this.SpecificationPath)); + } + Client.ApiImportFromFile( Context, apiId, SpecificationFormat, - SpecificationPath, + localFile.FullName, Path, WsdlServiceName, WsdlEndpointName, diff --git a/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/NewAzureApiManagementCertificate.cs b/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/NewAzureApiManagementCertificate.cs index 3213371fcd9a..cd688398b3b0 100644 --- a/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/NewAzureApiManagementCertificate.cs +++ b/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/NewAzureApiManagementCertificate.cs @@ -14,11 +14,13 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands { - using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models; using System; + using System.Globalization; using System.IO; using System.Management.Automation; using System.Security.Cryptography.X509Certificates; + using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models; + using Properties; [Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ApiManagementCertificate", DefaultParameterSetName = FromFile)] [OutputType(typeof(PsApiManagementCertificate))] @@ -67,7 +69,13 @@ public override void ExecuteApiManagementCmdlet() byte[] rawBytes; if (ParameterSetName.Equals(FromFile)) { - using (var certStream = File.OpenRead(PfxFilePath)) + FileInfo localFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.PfxFilePath)); + if (!localFile.Exists) + { + throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.SourceFileNotFound, PfxFilePath)); + } + + using (var certStream = File.OpenRead(localFile.Name)) { rawBytes = new byte[certStream.Length]; certStream.Read(rawBytes, 0, rawBytes.Length); diff --git a/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/SetAzureApiManagementCertificate.cs b/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/SetAzureApiManagementCertificate.cs index 642b6e39c5b6..deee7429d4f0 100644 --- a/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/SetAzureApiManagementCertificate.cs +++ b/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/SetAzureApiManagementCertificate.cs @@ -14,11 +14,13 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands { - using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models; using System; + using System.Globalization; using System.IO; using System.Management.Automation; using System.Security.Cryptography.X509Certificates; + using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models; + using Properties; [Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ApiManagementCertificate", DefaultParameterSetName = FromFile)] [OutputType(typeof(PsApiManagementCertificate))] @@ -77,7 +79,13 @@ public override void ExecuteApiManagementCmdlet() byte[] rawBytes; if (ParameterSetName.Equals(FromFile)) { - using (var certStream = File.OpenRead(PfxFilePath)) + FileInfo localFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.PfxFilePath)); + if (!localFile.Exists) + { + throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.SourceFileNotFound, this.PfxFilePath)); + } + + using (var certStream = File.OpenRead(localFile.Name)) { rawBytes = new byte[certStream.Length]; certStream.Read(rawBytes, 0, rawBytes.Length); diff --git a/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Properties/Resources.Designer.cs b/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Properties/Resources.Designer.cs index 196c8f8705f8..247ec2b8ed92 100644 --- a/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Properties/Resources.Designer.cs +++ b/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Properties/Resources.Designer.cs @@ -474,6 +474,15 @@ internal static string ShouldProcessCaption { } } + /// + /// Looks up a localized string similar to File '{0}' does not exist.. + /// + internal static string SourceFileNotFound { + get { + return ResourceManager.GetString("SourceFileNotFound", resourceCulture); + } + } + /// /// Looks up a localized string similar to Removing Subscription "{0}".. /// diff --git a/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Properties/Resources.resx b/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Properties/Resources.resx index a7f9baff72d3..d23c9414891a 100644 --- a/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Properties/Resources.resx +++ b/src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Properties/Resources.resx @@ -299,6 +299,10 @@ Confirm Process workflow + + File '{0}' does not exist. + Process workflow + Removing Subscription "{0}". Process workflow diff --git a/src/ResourceManager/ApiManagement/Commands.ApiManagement/Commands/NewAzureApiManagementCustomHostnameConfiguration.cs b/src/ResourceManager/ApiManagement/Commands.ApiManagement/Commands/NewAzureApiManagementCustomHostnameConfiguration.cs index 158a48072799..1644c40ba334 100644 --- a/src/ResourceManager/ApiManagement/Commands.ApiManagement/Commands/NewAzureApiManagementCustomHostnameConfiguration.cs +++ b/src/ResourceManager/ApiManagement/Commands.ApiManagement/Commands/NewAzureApiManagementCustomHostnameConfiguration.cs @@ -14,12 +14,14 @@ namespace Microsoft.Azure.Commands.ApiManagement.Commands { - using Microsoft.Azure.Commands.ApiManagement.Models; - using ResourceManager.Common; using System; + using System.Globalization; using System.IO; using System.Management.Automation; using System.Security; + using Microsoft.Azure.Commands.ApiManagement.Models; + using Properties; + using ResourceManager.Common; using WindowsAzure.Commands.Common; [Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ApiManagementCustomHostnameConfiguration", DefaultParameterSetName = "NoChangeCertificate")] @@ -99,8 +101,14 @@ public override void ExecuteCmdlet() } else if (!string.IsNullOrWhiteSpace(PfxPath)) { + FileInfo localFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.PfxPath)); + if (!localFile.Exists) + { + throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.SourceFileNotFound, this.PfxPath)); + } + byte[] certificate; - using (var certStream = File.OpenRead(PfxPath)) + using (var certStream = File.OpenRead(localFile.Name)) { certificate = new byte[certStream.Length]; certStream.Read(certificate, 0, certificate.Length); diff --git a/src/ResourceManager/ApiManagement/Commands.ApiManagement/Commands/NewAzureApiManagementSystemCertificate.cs b/src/ResourceManager/ApiManagement/Commands.ApiManagement/Commands/NewAzureApiManagementSystemCertificate.cs index d6597c20d841..de70f7bd9ef1 100644 --- a/src/ResourceManager/ApiManagement/Commands.ApiManagement/Commands/NewAzureApiManagementSystemCertificate.cs +++ b/src/ResourceManager/ApiManagement/Commands.ApiManagement/Commands/NewAzureApiManagementSystemCertificate.cs @@ -14,12 +14,14 @@ namespace Microsoft.Azure.Commands.ApiManagement.Commands { - using Microsoft.Azure.Commands.ApiManagement.Models; - using ResourceManager.Common; using System; + using System.Globalization; using System.IO; using System.Management.Automation; using System.Security; + using Microsoft.Azure.Commands.ApiManagement.Models; + using Properties; + using ResourceManager.Common; using WindowsAzure.Commands.Common; [Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ApiManagementSystemCertificate")] @@ -48,9 +50,15 @@ public override void ExecuteCmdlet() { var systemCertificate = new PsApiManagementSystemCertificate(); systemCertificate.StoreName = StoreName; + + FileInfo localFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.PfxPath)); + if (!localFile.Exists) + { + throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.SourceFileNotFound, this.PfxPath)); + } byte[] certificate; - using (var certStream = File.OpenRead(PfxPath)) + using (var certStream = File.OpenRead(localFile.Name)) { certificate = new byte[certStream.Length]; certStream.Read(certificate, 0, certificate.Length); diff --git a/src/ResourceManager/ApiManagement/Commands.ApiManagement/Properties/Resources.Designer.cs b/src/ResourceManager/ApiManagement/Commands.ApiManagement/Properties/Resources.Designer.cs index 11bcf433f87e..fbcff8062c3c 100644 --- a/src/ResourceManager/ApiManagement/Commands.ApiManagement/Properties/Resources.Designer.cs +++ b/src/ResourceManager/ApiManagement/Commands.ApiManagement/Properties/Resources.Designer.cs @@ -123,6 +123,15 @@ internal static string ShouldProcessCaption { } } + /// + /// Looks up a localized string similar to File at path '{0}' does not exist. + /// + internal static string SourceFileNotFound { + get { + return ResourceManager.GetString("SourceFileNotFound", resourceCulture); + } + } + /// /// Looks up a localized string similar to Update an Api Management Service.. /// diff --git a/src/ResourceManager/ApiManagement/Commands.ApiManagement/Properties/Resources.resx b/src/ResourceManager/ApiManagement/Commands.ApiManagement/Properties/Resources.resx index c7a5513b9193..0685cdaf751e 100644 --- a/src/ResourceManager/ApiManagement/Commands.ApiManagement/Properties/Resources.resx +++ b/src/ResourceManager/ApiManagement/Commands.ApiManagement/Properties/Resources.resx @@ -145,6 +145,10 @@ Confirm Process workflow + + File at path '{0}' does not exist + Process workflow + Update an Api Management Service. Process workflow