Skip to content

Commit 0485e6e

Browse files
[http-client-csharp] bump MGC version and implement the credential types (Azure#47528)
* bump version and implement the credential types * bump version * regen * fix the issue and introduce test cases
1 parent e86ae27 commit 0485e6e

25 files changed

+848
-443
lines changed

eng/Packages.Data.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
</ItemGroup>
260260

261261
<ItemGroup Condition="'$(IsGeneratorLibrary)' == 'true'">
262-
<PackageReference Update="Microsoft.Generator.CSharp.ClientModel" Version="1.0.0-alpha.20241128.1" />
262+
<PackageReference Update="Microsoft.Generator.CSharp.ClientModel" Version="1.0.0-alpha.20241215.1" />
263263
</ItemGroup>
264264

265265
<!--

eng/packages/http-client-csharp/generator/Azure.Generator/src/Azure.Generator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3232
</Compile>
3333
</ItemGroup>
34-
34+
3535
</Project>

eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureTypeFactory.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ namespace Azure.Generator
2323
/// <inheritdoc/>
2424
public class AzureTypeFactory : ScmTypeFactory
2525
{
26-
/// <inheritdoc/>
27-
public override CSharpType KeyCredentialType => typeof(AzureKeyCredential);
28-
2926
/// <inheritdoc/>
3027
public override IClientResponseApi ClientResponseApi => AzureClientResponseProvider.Instance;
3128

eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpPipelineProvider.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public HttpPipelineProvider(ValueExpression original) : base(typeof(HttpPipeline
2929

3030
public override CSharpType PipelinePolicyType => typeof(HttpPipelinePolicy);
3131

32+
public override CSharpType? KeyCredentialType => typeof(AzureKeyCredential);
33+
34+
public override CSharpType? TokenCredentialType => typeof(TokenCredential);
35+
3236
public override ValueExpression Create(ValueExpression options, ValueExpression perRetryPolicies)
3337
=> Static(typeof(HttpPipelineBuilder)).Invoke(nameof(HttpPipelineBuilder.Build), [options, perRetryPolicies]);
3438

@@ -38,8 +42,11 @@ public override ValueExpression CreateMessage(HttpRequestOptionsApi requestOptio
3842
public override ClientPipelineApi FromExpression(ValueExpression expression)
3943
=> new HttpPipelineProvider(expression);
4044

41-
public override ValueExpression AuthorizationPolicy(params ValueExpression[] arguments)
42-
=> New.Instance(typeof(AzureKeyCredentialPolicy), arguments);
45+
public override ValueExpression KeyAuthorizationPolicy(ValueExpression credential, ValueExpression headerName, ValueExpression? keyPrefix = null)
46+
=> New.Instance(typeof(AzureKeyCredentialPolicy), keyPrefix != null ? [credential, headerName, keyPrefix] : [credential, headerName]);
47+
48+
public override ValueExpression TokenAuthorizationPolicy(ValueExpression credential, ValueExpression scopes)
49+
=> New.Instance(typeof(BearerTokenAuthenticationPolicy), credential, scopes);
4350

4451
public override ClientPipelineApi ToExpression() => this;
4552

eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/StatusCodeClassifierProvider.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using Microsoft.Generator.CSharp.ClientModel.Providers;
66
using Microsoft.Generator.CSharp.Expressions;
77
using Microsoft.Generator.CSharp.Primitives;
8+
using System.Collections.Generic;
9+
using System.Linq;
810
using static Microsoft.Generator.CSharp.Snippets.Snippet;
911

1012
namespace Azure.Generator.Providers.Abstraction
@@ -23,6 +25,12 @@ public StatusCodeClassifierProvider(ValueExpression original) : base(typeof(Stat
2325
public override ValueExpression Create(int code)
2426
=> New.Instance(typeof(StatusCodeClassifier), [New.Array(typeof(ushort), true, true, [Literal(code)])]);
2527

28+
public override ValueExpression Create(IEnumerable<int> codes)
29+
{
30+
var codeArgs = codes.Select(Literal).ToArray();
31+
return New.Instance(typeof(StatusCodeClassifier), New.Array(typeof(ushort), true, true, codeArgs));
32+
}
33+
2634
public override StatusCodeClassifierApi FromExpression(ValueExpression original)
2735
=> new StatusCodeClassifierProvider(original);
2836

eng/packages/http-client-csharp/generator/Azure.Generator/test/Common/Helpers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

44
using System.IO;
@@ -14,17 +14,17 @@ public static string GetExpectedFromFile(
1414
[CallerMemberName] string method = "",
1515
[CallerFilePath] string filePath = "")
1616
{
17-
return File.ReadAllText(GetAssetFileOrDirectoryPath(true, parameters, method, filePath));
17+
return File.ReadAllText(GetAssetFileOrDirectoryPath(true, parameters, method, filePath)).Replace("\r\n", "\n");
1818
}
1919

20-
public static string GetAssetFileOrDirectoryPath(
20+
private static string GetAssetFileOrDirectoryPath(
2121
bool isFile,
2222
string? parameters = null,
2323
[CallerMemberName] string method = "",
2424
[CallerFilePath] string filePath = "")
2525
{
2626

27-
var callingClass = Path.GetFileName(filePath).Split('.').First();
27+
var callingClass = Path.GetFileName(filePath).Split('.').First();
2828
var paramString = parameters is null ? string.Empty : $"({parameters})";
2929
var extName = isFile ? ".cs" : string.Empty;
3030

eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/Abstractions/AzureClientResponseProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

44
using Azure.Generator.Tests.Common;

0 commit comments

Comments
 (0)