-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
98ad667
commit b87a7cd
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
m365-developer-proxy-plugins/Guidance/ODSPSearchGuidancePlugin.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,58 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Extensions.Configuration; | ||
using Microsoft365.DeveloperProxy.Abstractions; | ||
using Titanium.Web.Proxy.Http; | ||
|
||
namespace Microsoft365.DeveloperProxy.Plugins.Guidance; | ||
|
||
public class ODSPSearchGuidancePlugin : BaseProxyPlugin | ||
{ | ||
public override string Name => nameof(ODSPSearchGuidancePlugin); | ||
|
||
public override void Register(IPluginEvents pluginEvents, | ||
IProxyContext context, | ||
ISet<UrlToWatch> urlsToWatch, | ||
IConfigurationSection? configSection = null) | ||
{ | ||
base.Register(pluginEvents, context, urlsToWatch, configSection); | ||
|
||
pluginEvents.BeforeRequest += BeforeRequest; | ||
} | ||
|
||
private async Task BeforeRequest(object sender, ProxyRequestArgs e) | ||
Check warning on line 24 in m365-developer-proxy-plugins/Guidance/ODSPSearchGuidancePlugin.cs GitHub Actions / Publish binaries (linux-x64)
Check warning on line 24 in m365-developer-proxy-plugins/Guidance/ODSPSearchGuidancePlugin.cs GitHub Actions / Publish binaries (win-x64)
Check warning on line 24 in m365-developer-proxy-plugins/Guidance/ODSPSearchGuidancePlugin.cs GitHub Actions / Publish binaries (osx-x64)
|
||
{ | ||
Request request = e.Session.HttpClient.Request; | ||
if (_urlsToWatch is not null && e.HasRequestUrlMatch(_urlsToWatch) && WarnDeprecatedSearch(request)) | ||
_logger?.LogRequest(BuildUseGraphSearchMessage(), MessageType.Warning, new LoggingContext(e.Session)); | ||
} | ||
|
||
private bool WarnDeprecatedSearch(Request request) | ||
{ | ||
if (!ProxyUtils.IsGraphRequest(request) || | ||
request.Method != "GET") | ||
{ | ||
return false; | ||
} | ||
|
||
// graph.microsoft.com/{version}/drives/{drive-id}/root/search(q='{search-text}') | ||
// graph.microsoft.com/{version}/groups/{group-id}/drive/root/search(q='{search-text}') | ||
// graph.microsoft.com/{version}/me/drive/root/search(q='{search-text}') | ||
// graph.microsoft.com/{version}/sites/{site-id}/drive/root/search(q='{search-text}') | ||
// graph.microsoft.com/{version}/users/{user-id}/drive/root/search(q='{search-text}') | ||
// graph.microsoft.com/{version}/sites?search={query} | ||
if (request.RequestUri.AbsolutePath.Contains("/search(q=", StringComparison.OrdinalIgnoreCase) || | ||
(request.RequestUri.AbsolutePath.EndsWith("/sites", StringComparison.OrdinalIgnoreCase) && | ||
request.RequestUri.Query.Contains("search=", StringComparison.OrdinalIgnoreCase))) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
private static string[] BuildUseGraphSearchMessage() => new[] { $"To get the best search experience, use the Microsoft Search APIs in Microsoft Graph.", $"More info at https://aka.ms/m365/proxy/guidance/odspsearch" }; | ||
} |
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