Skip to content

Commit 389c1a5

Browse files
Add internal for setting caller as compat cmdlet (#1432)
1 parent bf37fdb commit 389c1a5

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/code/InternalHooks.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Reflection;
5+
6+
namespace Microsoft.PowerShell.PSResourceGet.UtilClasses
7+
{
8+
public class InternalHooks
9+
{
10+
internal static bool InvokedFromCompat;
11+
12+
public static void SetTestHook(string property, object value)
13+
{
14+
var fieldInfo = typeof(InternalHooks).GetField(property, BindingFlags.Static | BindingFlags.NonPublic);
15+
fieldInfo?.SetValue(null, value);
16+
}
17+
}
18+
}

src/code/ServerFactory.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ static UserAgentInfo()
2525
private static string _psResourceGetVersion;
2626
private static string _distributionChannel;
2727

28-
internal static string UserAgentString => $"PSResourceGet/{_psResourceGetVersion} PowerShell/{_psVersion} DistributionChannel/{_distributionChannel}";
28+
internal static string UserAgentString()
29+
{
30+
string psGetCompat = InternalHooks.InvokedFromCompat ? "true" : "false";
31+
return $"PSResourceGet/{_psResourceGetVersion} PowerShell/{_psVersion} DistributionChannel/{_distributionChannel} PowerShellGetCompat/{psGetCompat}";
32+
}
2933
}
3034

3135
internal class ServerFactory
@@ -34,7 +38,7 @@ public static ServerApiCall GetServer(PSRepositoryInfo repository, PSCmdlet cmdl
3438
{
3539
PSRepositoryInfo.APIVersion repoApiVersion = repository.ApiVersion;
3640
ServerApiCall currentServer = null;
37-
string userAgentString = UserAgentInfo.UserAgentString;
41+
string userAgentString = UserAgentInfo.UserAgentString();
3842

3943
switch (repoApiVersion)
4044
{

0 commit comments

Comments
 (0)