-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathServerFactory.cs
More file actions
68 lines (56 loc) · 2.8 KB
/
ServerFactory.cs
File metadata and controls
68 lines (56 loc) · 2.8 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections;
using System.Management.Automation;
using System.Net;
using Microsoft.PowerShell.PSResourceGet.UtilClasses;
namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
{
internal static class UserAgentInfo
{
static UserAgentInfo()
{
_psVersion = System.Management.Automation.Runspaces.Runspace.DefaultRunspace.Version.ToString();
_psResourceGetVersion = typeof(UserAgentInfo).Assembly.GetName().Version.ToString();
_distributionChannel = System.Environment.GetEnvironmentVariable("POWERSHELL_DISTRIBUTION_CHANNEL") ?? "unknown";
}
private static string _psVersion;
private static string _psResourceGetVersion;
private static string _distributionChannel;
internal static string UserAgentString()
{
string psGetCompat = InternalHooks.InvokedFromCompat ? "true" : "false";
return $"PSResourceGet/{_psResourceGetVersion} PowerShell/{_psVersion} DistributionChannel/{_distributionChannel} PowerShellGetCompat/{psGetCompat}";
}
}
internal class ServerFactory
{
public static ServerApiCall GetServer(PSRepositoryInfo repository, PSCmdlet cmdletPassedIn, NetworkCredential networkCredential, bool writeWarnings = false)
{
PSRepositoryInfo.APIVersion repoApiVersion = repository.ApiVersion;
ServerApiCall currentServer = null;
string userAgentString = UserAgentInfo.UserAgentString();
switch (repoApiVersion)
{
case PSRepositoryInfo.APIVersion.V2:
currentServer = new V2ServerAPICalls(repository, cmdletPassedIn, networkCredential, userAgentString);
break;
case PSRepositoryInfo.APIVersion.V3:
currentServer = new V3ServerAPICalls(repository, cmdletPassedIn, networkCredential, userAgentString);
break;
case PSRepositoryInfo.APIVersion.Local:
currentServer = new LocalServerAPICalls(repository, cmdletPassedIn, networkCredential, writeWarnings);
break;
case PSRepositoryInfo.APIVersion.NugetServer:
currentServer = new NuGetServerAPICalls(repository, cmdletPassedIn, networkCredential, userAgentString);
break;
case PSRepositoryInfo.APIVersion.ContainerRegistry:
currentServer = new ContainerRegistryServerAPICalls(repository, cmdletPassedIn, networkCredential, userAgentString);
break;
case PSRepositoryInfo.APIVersion.Unknown:
break;
}
return currentServer;
}
}
}