Skip to content
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

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions DevProxy.Plugins/Guidance/GraphSelectGuidancePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using DevProxy.Abstractions.Data;
using DevProxy.Abstractions.Proxy;
using DevProxy.Abstractions.Plugins;
using DevProxy.Abstractions.Utils;
using Microsoft.Extensions.Logging;
using Titanium.Web.Proxy.EventArguments;
using System.Globalization;
using Titanium.Web.Proxy.EventArguments;

namespace DevProxy.Plugins.Guidance;

public sealed class GraphSelectGuidancePlugin(
ILogger<GraphSelectGuidancePlugin> logger,
ISet<UrlToWatch> urlsToWatch) : BasePlugin(logger, urlsToWatch)
ISet<UrlToWatch> urlsToWatch,
MSGraphDb msGraphDb) : BasePlugin(logger, urlsToWatch)
{
private readonly MSGraphDb _msGraphDb = msGraphDb;

public override string Name => nameof(GraphSelectGuidancePlugin);

public override async Task InitializeAsync(InitArgs e, CancellationToken cancellationToken)
{
await base.InitializeAsync(e, cancellationToken);

// let's not await so that it doesn't block the proxy startup
_ = MSGraphDbUtils.GenerateMSGraphDbAsync(Logger, true, cancellationToken);
_ = _msGraphDb.GenerateDbAsync(true, cancellationToken);
}

public override Task AfterResponseAsync(ProxyResponseArgs e, CancellationToken cancellationToken)
Expand Down Expand Up @@ -82,7 +86,7 @@ private bool EndpointSupportsSelect(string graphVersion, string relativeUrl)

try
{
var dbConnection = MSGraphDbUtils.MSGraphDbConnection;
var dbConnection = _msGraphDb.Connection;
// lookup information from the database
var selectEndpoint = dbConnection.CreateCommand();
selectEndpoint.CommandText = "SELECT hasSelect FROM endpoints WHERE path = @path AND graphVersion = @graphVersion";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public sealed class GraphMinimalPermissionsGuidancePlugin(
pluginConfigurationSection)
{
private GraphUtils? _graphUtils;
private readonly HttpClient _httpClient = httpClient;

public override string Name => nameof(GraphMinimalPermissionsGuidancePlugin);

Expand Down Expand Up @@ -240,11 +241,10 @@ private async Task EvaluateMinimalScopesAsync(
try
{
var url = $"https://devxapi-func-prod-eastus.azurewebsites.net/permissions?scopeType={GraphUtils.GetScopeTypeString(scopeType)}";
using var client = new HttpClient();
var stringPayload = JsonSerializer.Serialize(payload, ProxyUtils.JsonSerializerOptions);
Logger.LogDebug("Calling {Url} with payload{NewLine}{Payload}", url, Environment.NewLine, stringPayload);

var response = await client.PostAsJsonAsync(url, payload, cancellationToken);
var response = await _httpClient.PostAsJsonAsync(url, payload, cancellationToken);
var content = await response.Content.ReadAsStringAsync(cancellationToken);

Logger.LogDebug("Response:{NewLine}{Content}", Environment.NewLine, content);
Expand Down
4 changes: 2 additions & 2 deletions DevProxy.Plugins/Reporting/GraphMinimalPermissionsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public sealed class GraphMinimalPermissionsPlugin(
pluginConfigurationSection)
{
private GraphUtils? _graphUtils;
private readonly HttpClient _httpClient = httpClient;

public override string Name => nameof(GraphMinimalPermissionsPlugin);

Expand Down Expand Up @@ -137,11 +138,10 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation
try
{
var url = $"https://devxapi-func-prod-eastus.azurewebsites.net/permissions?scopeType={GraphUtils.GetScopeTypeString(Configuration.Type)}";
using var client = new HttpClient();
var stringPayload = JsonSerializer.Serialize(payload, ProxyUtils.JsonSerializerOptions);
Logger.LogDebug("Calling {Url} with payload\r\n{StringPayload}", url, stringPayload);

var response = await client.PostAsJsonAsync(url, payload, cancellationToken);
var response = await _httpClient.PostAsJsonAsync(url, payload, cancellationToken);
var content = await response.Content.ReadAsStringAsync(cancellationToken);

Logger.LogDebug("Response:\r\n{Content}", content);
Expand Down
2 changes: 1 addition & 1 deletion DevProxy/Announcement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static async Task ShowAsync()
}
}

public static async Task<string?> GetAsync()
private static async Task<string?> GetAsync()
{
try
{
Expand Down
10 changes: 5 additions & 5 deletions DevProxy/Commands/MsGraphDbCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using DevProxy.Abstractions.Utils;
using DevProxy.Abstractions.Data;
using System.CommandLine;

namespace DevProxy.Commands;

sealed class MsGraphDbCommand : Command
{
private readonly ILogger _logger;
private readonly MSGraphDb _msGraphDb;

public MsGraphDbCommand(ILogger<MsGraphDbCommand> logger) :
public MsGraphDbCommand(MSGraphDb msGraphDb) :
base("msgraphdb", "Generate a local SQLite database with Microsoft Graph API metadata")
{
_logger = logger;
_msGraphDb = msGraphDb;
ConfigureCommand();
}

Expand All @@ -25,6 +25,6 @@ private void ConfigureCommand()

private async Task GenerateMsGraphDbAsync(ParseResult parseResult, CancellationToken cancellationToken)
{
_ = await MSGraphDbUtils.GenerateMSGraphDbAsync(_logger, false, cancellationToken);
_ = await _msGraphDb.GenerateDbAsync(false, cancellationToken);
}
}
2 changes: 2 additions & 0 deletions DevProxy/Extensions/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using DevProxy;
using DevProxy.Abstractions.Data;
using DevProxy.Abstractions.LanguageModel;
using DevProxy.Abstractions.Proxy;
using DevProxy.Commands;
Expand Down Expand Up @@ -45,6 +46,7 @@ static IServiceCollection AddApplicationServices(
.AddSingleton<UpdateNotification>()
.AddSingleton<ProxyEngine>()
.AddSingleton<DevProxyCommand>()
.AddSingleton<MSGraphDb>()
.AddHttpClient();

_ = services.AddPlugins(configuration, options);
Expand Down
Empty file.