-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Cabazure/azure-sample
Rewrite sample to use Azure Rest API and netstandard2.0
- Loading branch information
Showing
101 changed files
with
2,123 additions
and
1,902 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...raph.Client/Microsoft.Graph.Client.csproj → .../AzureRest.Client/AzureRest.Client.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<LangVersion>9.0</LangVersion> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\Cabazure.Client.Runtime\Cabazure.Client.Runtime.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Cabazure.Client\Cabazure.Client.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
<ProjectReference Include="..\Microsoft.Graph.Contracts\Microsoft.Graph.Contracts.csproj" /> | ||
<ProjectReference Include="..\AzureRest.Contracts\AzureRest.Contracts.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
25 changes: 25 additions & 0 deletions
25
samples/AzureRest/AzureRest.Client/AzureRestClientOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using Azure.Core; | ||
using Cabazure.Client; | ||
|
||
namespace AzureRest.Client | ||
{ | ||
public class AzureRestClientOptions : ICabazureAuthClientOptions | ||
{ | ||
public TokenCredential? Credential { get; set; } | ||
|
||
Uri ICabazureClientOptions.GetBaseAddress() | ||
// Notice the trailing slash, it's important | ||
// for the client to work correctly with relative paths. | ||
=> new("https://management.azure.com/"); | ||
|
||
string ICabazureAuthClientOptions.GetScope() | ||
// The default scope for Microsoft Graph. | ||
=> "https://management.azure.com/.default"; | ||
|
||
TokenCredential ICabazureAuthClientOptions.GetCredential() | ||
=> Credential | ||
?? throw new InvalidOperationException( | ||
"No Credential configured for GraphClientOptions"); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
samples/AzureRest/AzureRest.Client/Endpoints/IGetSubscription.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AzureRest.Contracts; | ||
using Cabazure.Client; | ||
|
||
namespace AzureRest.Client.Endpoints | ||
{ | ||
[ClientEndpoint("azure-rest-client")] | ||
public interface IGetSubscription | ||
{ | ||
[Get("subscriptions/{subscriptionId}?api-version=2022-12-01")] | ||
public Task<EndpointResponse<Subscription>> ExecuteAsync( | ||
[Path] string subscriptionId, | ||
CancellationToken cancellationToken = default); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
samples/AzureRest/AzureRest.Client/Endpoints/IListSubscriptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AzureRest.Contracts; | ||
using Cabazure.Client; | ||
|
||
namespace AzureRest.Client.Endpoints | ||
{ | ||
[ClientEndpoint("azure-rest-client")] | ||
public interface IListSubscriptions | ||
{ | ||
[Get("https://management.azure.com/subscriptions?api-version=2022-12-01")] | ||
public Task<EndpointResponse<ListResponse<Subscription>>> ExecuteAsync( | ||
CancellationToken cancellationToken = default); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
samples/AzureRest/AzureRest.Client/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using AzureRest.Client; | ||
using AzureRest.Contracts.Serialization; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddAzureRestClient( | ||
this IServiceCollection services, | ||
Action<AzureRestClientOptions>? clientOptions = null) | ||
=> services.AddCabazureClient( | ||
"azure-rest-client", | ||
j => JsonSerializerOptionsFactory.Configure(j), | ||
clientOptions); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
samples/AzureRest/AzureRest.Contracts/AzureRest.Contracts.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.Text.Json" Version="8.0.4" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace AzureRest.Contracts | ||
{ | ||
public class CountValue | ||
{ | ||
public string Type { get; set; } | ||
|
||
public int Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace AzureRest.Contracts | ||
{ | ||
public class ListResponse<T> | ||
{ | ||
public CountValue Count { get; set; } | ||
|
||
public T[] Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace AzureRest.Contracts | ||
{ | ||
public class ManagedByTenant | ||
{ | ||
public string TenantId { get; set; } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
samples/AzureRest/AzureRest.Contracts/Serialization/JsonSerializerOptionsFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace AzureRest.Contracts.Serialization | ||
{ | ||
public static class JsonSerializerOptionsFactory | ||
{ | ||
public static JsonSerializerOptions Create() | ||
=> Configure(new JsonSerializerOptions()); | ||
|
||
public static JsonSerializerOptions Configure( | ||
this JsonSerializerOptions options) | ||
{ | ||
options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; | ||
options.PropertyNameCaseInsensitive = true; | ||
options.Converters.Add( | ||
new JsonStringEnumConverter( | ||
JsonNamingPolicy.CamelCase)); | ||
|
||
return options; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace AzureRest.Contracts | ||
{ | ||
public class Subscription | ||
{ | ||
public string AuthorizationSource { get; set; } | ||
|
||
public string DisplayName { get; set; } | ||
|
||
public string Id { get; set; } | ||
|
||
public ManagedByTenant[] ManagedByTenants { get; set; } | ||
|
||
public string State { get; set; } | ||
|
||
public string SubscriptionId { get; set; } | ||
|
||
public SubscriptionPolicies SubscriptionPolicies { get; set; } | ||
|
||
public string TenantId { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
samples/AzureRest/AzureRest.Contracts/SubscriptionPolicies.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace AzureRest.Contracts | ||
{ | ||
public class SubscriptionPolicies | ||
{ | ||
public string LocationPlacementId { get; set; } | ||
|
||
public string QuotaId { get; set; } | ||
|
||
public string SpendingLimit { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
samples/AzureRest/AzureRest.TestApp/Options/ConfigureAzureRestClientOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Azure.Identity; | ||
using AzureRest.Client; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace AzureRest.TestApp.Options; | ||
|
||
public class ConfigureAzureRestClientOptions | ||
: IConfigureOptions<AzureRestClientOptions> | ||
{ | ||
public void Configure(AzureRestClientOptions options) | ||
{ | ||
options.Credential = new DefaultAzureCredential(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using AzureRest.Client.Endpoints; | ||
using AzureRest.TestApp.Options; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
var builder = Host.CreateApplicationBuilder(args); | ||
|
||
builder.Services.ConfigureOptions<ConfigureAzureRestClientOptions>(); | ||
builder.Services.AddAzureRestClient(); | ||
|
||
var app = builder.Build(); | ||
|
||
var endpoint = app.Services.GetRequiredService<IListSubscriptions>(); | ||
|
||
var result = await endpoint.ExecuteAsync(); | ||
if (result.OkContent is not { } list) | ||
{ | ||
Console.WriteLine(result.StatusCode); | ||
return; | ||
} | ||
|
||
Console.WriteLine($"Found {list.Count.Value} subscriptions ({list.Count.Type}):"); | ||
foreach (var subscription in list.Value) | ||
{ | ||
Console.WriteLine($" - {subscription.DisplayName} ({subscription.SubscriptionId})"); | ||
} |
13 changes: 0 additions & 13 deletions
13
samples/Microsoft.Graph/Microsoft.Graph.Client/Endpoints/IGetUserByEmail.cs
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
samples/Microsoft.Graph/Microsoft.Graph.Client/GraphClientOptions.cs
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
samples/Microsoft.Graph/Microsoft.Graph.Client/ServiceCollectionExtensions.cs
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
samples/Microsoft.Graph/Microsoft.Graph.Contracts/Microsoft.Graph.Contracts.csproj
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.