Skip to content

Commit

Permalink
Add internal for setting caller as compat cmdlet (#1432)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapatwardhan authored Oct 4, 2023
1 parent bf37fdb commit 389c1a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/code/InternalHooks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Reflection;

namespace Microsoft.PowerShell.PSResourceGet.UtilClasses
{
public class InternalHooks
{
internal static bool InvokedFromCompat;

public static void SetTestHook(string property, object value)
{
var fieldInfo = typeof(InternalHooks).GetField(property, BindingFlags.Static | BindingFlags.NonPublic);
fieldInfo?.SetValue(null, value);
}
}
}
8 changes: 6 additions & 2 deletions src/code/ServerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ static UserAgentInfo()
private static string _psResourceGetVersion;
private static string _distributionChannel;

internal static string UserAgentString => $"PSResourceGet/{_psResourceGetVersion} PowerShell/{_psVersion} DistributionChannel/{_distributionChannel}";
internal static string UserAgentString()
{
string psGetCompat = InternalHooks.InvokedFromCompat ? "true" : "false";
return $"PSResourceGet/{_psResourceGetVersion} PowerShell/{_psVersion} DistributionChannel/{_distributionChannel} PowerShellGetCompat/{psGetCompat}";
}
}

internal class ServerFactory
Expand All @@ -34,7 +38,7 @@ public static ServerApiCall GetServer(PSRepositoryInfo repository, PSCmdlet cmdl
{
PSRepositoryInfo.APIVersion repoApiVersion = repository.ApiVersion;
ServerApiCall currentServer = null;
string userAgentString = UserAgentInfo.UserAgentString;
string userAgentString = UserAgentInfo.UserAgentString();

switch (repoApiVersion)
{
Expand Down

0 comments on commit 389c1a5

Please sign in to comment.