-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathPermissionHandlers.cs
More file actions
47 lines (42 loc) · 1.91 KB
/
Copy pathPermissionHandlers.cs
File metadata and controls
47 lines (42 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using GitHub.Copilot.Rpc;
namespace GitHub.Copilot;
/// <summary>Provides pre-built permission request handlers.</summary>
public static class PermissionHandler
{
/// <summary>
/// A permission handler that approves requests when managed settings are disabled.
/// </summary>
public static Func<PermissionRequest, PermissionInvocation, Task<PermissionDecision>> ApproveAll { get; } =
(request, invocation) => invocation.ManagedSettingsEnabled
? Task.FromException<PermissionDecision>(
new InvalidOperationException("ApproveAll cannot be used when managed settings are enabled"))
: RequiresManagedApproval(request)
? Task.FromResult(PermissionDecision.NoResult())
: Task.FromResult(PermissionDecision.ApproveOnce());
private static bool RequiresManagedApproval(PermissionRequest request)
{
if (request.ManagedApprovalRequired is true)
{
return true;
}
// Only reached for a request that did not deserialize into a generated
// variant. Keep this list in sync with the PermissionRequest discriminators
// so a known kind is never treated as requiring managed approval.
return request.GetType() == typeof(PermissionRequest)
&& request.Kind is not ("shell"
or "write"
or "read"
or "mcp"
or "url"
or "memory"
or "custom-tool"
or "hook"
or "extension-management"
or "factory"
or "extension-permission-access"
or "extension-env-access");
}
}