Skip to content

Commit

Permalink
Merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
erich-wang committed May 14, 2021
2 parents d207d5d + f71129a commit fa90e3c
Show file tree
Hide file tree
Showing 129 changed files with 4,308 additions and 4,641 deletions.
3 changes: 2 additions & 1 deletion src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
-->

## Upcoming Release
* Upgraded Azure.Identity to 1.4 and MSAL lib to 4.30.1
* Removed obsolete parameters `ManagedServiceHostName`, `ManagedServicePort` and `ManagedServiceSecret` of cmdlet `Connect-AzAccount`, environment variables `MSI_ENDPOINT` and `MSI_SECRET` could be used instead
* Customize display format of PSAzureRmAccount to hide secret of service principal [#14208]
* Added optional parameter `AuthScope` to `Connect-AzAccount` to support enhanced authentication of data plane features
* Upgraded Azure.Identity to 1.4 and MSAL lib to 4.30.1
* Set retry times by environment variable [#14748]

## Version 2.2.8
* Fallback to first valid context if current default context key is "Default" which is invalid
Expand Down
122 changes: 122 additions & 0 deletions src/Accounts/Authentication/Extensions/ServiceClientExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Rest.TransientFaultHandling;
using System;

namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
{
internal static class ServiceClientExtension
{
private class HttpRetryTimes
{
private const string maxRetriesVariableName = "AZURE_PS_HTTP_MAX_RETRIES";
private const string maxRetriesFor429VariableName = "AZURE_PS_HTTP_MAX_RETRIES_FOR_429";

public static int? AzurePsHttpMaxRetries
{
get
{
return TryGetAzurePsHttpMaxRetries();
}
}
public static int? AzurePsHttpMaxRetriesFor429
{
get
{
return TryGetAzurePsHttpMaxRetriesFor429();
}
}

private static int? TryGetValue(string environmentVariable)
{
int? retries = null;
var value = Environment.GetEnvironmentVariable(environmentVariable);
if (value != null)
{
int valueParsed = int.MinValue;
if (int.TryParse(value, out valueParsed))
{
retries = valueParsed;
}
}
return retries;
}

private static int? TryGetAzurePsHttpMaxRetries()
{
return TryGetValue(maxRetriesVariableName);
}

private static int? TryGetAzurePsHttpMaxRetriesFor429()
{
return TryGetValue(maxRetriesFor429VariableName);
}
}

private static bool SetMaxTimesForRetryAfterHandler<TClient>(this Microsoft.Rest.ServiceClient<TClient> serviceClient, uint retrytimes) where TClient : Microsoft.Rest.ServiceClient<TClient>
{
bool findRetryHandler = false;
foreach (var handler in serviceClient.HttpMessageHandlers)
{
var retryHandler = handler as Microsoft.Rest.RetryAfterDelegatingHandler;
if (retryHandler != null)
{
retryHandler.MaxRetries = Convert.ToInt32(retrytimes);
findRetryHandler = true;
}
}
return findRetryHandler;
}

/// <summary>
/// Set max retry times of retry after handler that is used to handle the response with retry-after header
/// from environement variable AZURE_PS_HTTP_MAX_RETRIES_FOR_429
/// </summary>
/// <returns>Whether succeed to set max retry times or not</returns>
public static bool TrySetMaxTimesForRetryAfterHandler<TClient>(this Microsoft.Rest.ServiceClient<TClient> serviceClient) where TClient : Microsoft.Rest.ServiceClient<TClient>
{
int? maxretriesfor429 = HttpRetryTimes.AzurePsHttpMaxRetriesFor429;
if (maxretriesfor429 != null && maxretriesfor429 >= 0)
{
return serviceClient.SetMaxTimesForRetryAfterHandler(Convert.ToUInt32(maxretriesfor429));
}
return false;
}

/// <summary>
/// Set retry count of retry policy using ExponentialBackoffRetryStrategy from environement variable AZURE_PS_HTTP_MAX_RETRIES
/// </summary>
/// <returns>Whether succeed to set retry count or not</returns>
public static bool TrySetRetryCountofRetryPolicy<TClient>(this Microsoft.Rest.ServiceClient<TClient> serviceClient) where TClient : Microsoft.Rest.ServiceClient<TClient>
{
int? maxretries = ServiceClientExtension.HttpRetryTimes.AzurePsHttpMaxRetries;
if (maxretries != null && maxretries >= 0)
{
TimeSpan defaultBackoffDelta = new TimeSpan(0, 0, 10);
TimeSpan defaultMaxBackoff = new TimeSpan(0, 0, 10);
TimeSpan defaultMinBackoff = new TimeSpan(0, 0, 1);
var retryStrategy = new ExponentialBackoffRetryStrategy(
(int)maxretries,
defaultBackoffDelta,
defaultMaxBackoff,
defaultMinBackoff);
var retryPolicy = new RetryPolicy<HttpStatusCodeErrorDetectionStrategy>(retryStrategy);
serviceClient.SetRetryPolicy(retryPolicy);
return true;
}
return false;
}
}
}
3 changes: 3 additions & 0 deletions src/Accounts/Authentication/Factories/ClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public virtual TClient CreateCustomArmClient<TClient>(params object[] parameters
client.UserAgent.Add(userAgent);
}

client.TrySetMaxTimesForRetryAfterHandler();
client.TrySetRetryCountofRetryPolicy();

return client;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Microsoft.Azure.Commands.Compute.StorageServices
/// <summary>
/// Uploads a vhd as fixed disk format vhd to a blob in Microsoft Azure Storage
/// </summary>
[GenericBreakingChange("This cmdlet will now try to resize the VHD file to (N * Mib + 512 bytes) using Hyper-V before uploading.\n If Hyper-V is not found, user will have to either enabled Hyper-V or resize manually before uploading.", "5.10.0" ,"05/25/2021")]
[GenericBreakingChange("This cmdlet will now try to resize the VHD file to (N * Mib + 512 bytes) using Hyper-V before uploading.\n If Hyper-V is not found, user will have to either enabled Hyper-V or resize manually before uploading.")]
[Cmdlet("Add", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "Vhd"), OutputType(typeof(VhdUploadContext))]
public class AddAzureVhdCommand : ComputeClientBaseCmdlet
{
Expand Down
12 changes: 8 additions & 4 deletions src/ContainerRegistry/ContainerRegistry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ Global
{094709D1-0301-44F4-8BB2-203162006A3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{094709D1-0301-44F4-8BB2-203162006A3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{094709D1-0301-44F4-8BB2-203162006A3D}.Release|Any CPU.Build.0 = Release|Any CPU
{2EF2B093-6C82-4AC4-A073-89DA030980E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2EF2B093-6C82-4AC4-A073-89DA030980E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EF2B093-6C82-4AC4-A073-89DA030980E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EF2B093-6C82-4AC4-A073-89DA030980E7}.Release|Any CPU.Build.0 = Release|Any CPU
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.Build.0 = Release|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.Build.0 = Release|Any CPU
{2EF2B093-6C82-4AC4-A073-89DA030980E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2EF2B093-6C82-4AC4-A073-89DA030980E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EF2B093-6C82-4AC4-A073-89DA030980E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EF2B093-6C82-4AC4-A073-89DA030980E7}.Release|Any CPU.Build.0 = Release|Any CPU
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
1 change: 1 addition & 0 deletions src/ContainerRegistry/ContainerRegistry/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Fixed username and password issue in `Import-AzContainerRegistryImage` [#14971]
* Fixed data plane operations (repository, tag, manifest) failed cross registry in single Powershell session [#14849]

## Version 2.2.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.Azure.Commands.ContainerRegistry.Models
{
public class PSImportSourceCredentials
{
public PSImportSourceCredentials(string password, string username = default(string))
public PSImportSourceCredentials(string username, string password)
{
Username = username;
Password = password;
Expand Down
8 changes: 1 addition & 7 deletions src/DataBox/DataBox/DataBox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,4 @@
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>


<ItemGroup>
<PackageReference Update="Microsoft.Rest.ClientRuntime" Version="2.3.20" />
</ItemGroup>

</Project>
</Project>
1 change: 1 addition & 0 deletions src/KeyVault/KeyVault/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Provided key size for RSA key [#14819]

## Version 3.4.3
* Fixed a bug for `Get-AzKeyVaultSecret -IncludeVersions` when current version is disabled [#14740]
Expand Down
34 changes: 28 additions & 6 deletions src/KeyVault/KeyVault/Helpers/JwkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,34 @@ namespace Microsoft.Azure.Commands.KeyVault.Helpers
{
internal static class JwkHelper
{
/// <summary>
/// Export the public key of a JsonWebKey to PEM format.
/// </summary>
/// <param name="jwk"></param>
/// <returns></returns>
internal static string ExportPublicKeyToPem(JsonWebKey jwk)
internal static RSACryptoServiceProvider ConvertToRSAKey(JsonWebKey jwk)
{
if (!"RSA".Equals(jwk?.Kty))
{
return null;
}
try
{
var csp = new RSACryptoServiceProvider();
csp.ImportParameters(new RSAParameters()
{
Exponent = jwk.E,
Modulus = jwk.N
});
return csp;
}
catch (CryptographicException)
{
return null;
}
}

/// <summary>
/// Export the public key of a JsonWebKey to PEM format.
/// </summary>
/// <param name="jwk"></param>
/// <returns></returns>
internal static string ExportPublicKeyToPem(JsonWebKey jwk)
{

var csp = new RSACryptoServiceProvider();
Expand Down
Loading

0 comments on commit fa90e3c

Please sign in to comment.