Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal for setting caller as compat cmdlet #1432

Merged
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
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
Loading