Skip to content

Commit 660e8a8

Browse files
committed
Removed hard Linux dependencies
1 parent 799a6bf commit 660e8a8

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/KubernetesClientConfiguration.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace k8s
66
using k8s.Exceptions;
77
using k8s.KubeConfigModels;
88
using YamlDotNet.Serialization;
9+
using System.Runtime.InteropServices;
910

1011
/// <summary>
1112
/// Represents a set of kubernetes client configuration settings
@@ -31,7 +32,9 @@ public KubernetesClientConfiguration(FileInfo kubeconfig = null, string currentC
3132
/// <summary>
3233
/// kubeconfig Default Location
3334
/// </summary>
34-
private static readonly string KubeConfigDefaultLocation = Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".kube/config");
35+
private static readonly string KubeConfigDefaultLocation = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
36+
Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), @".kube\config") :
37+
Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".kube/config");
3538

3639
/// <summary>
3740
/// Gets CurrentContext

src/Utils.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Diagnostics;
55
using System.Globalization;
66
using System.IO;
7+
using System.Runtime.InteropServices;
78
using System.Text;
89
using System.Threading.Tasks;
910

@@ -37,7 +38,10 @@ public static string Base64Decode(string text)
3738
/// TODO: kabhishek8260 Remplace the method with X509 Certificate with private key(in dotnet 2.0)
3839
public static async Task<string> GeneratePfxAsync(KubernetesClientConfiguration config)
3940
{
40-
var userHomeDir = Environment.GetEnvironmentVariable("HOME");
41+
var userHomeDir = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
42+
Environment.GetEnvironmentVariable("USERPROFILE") :
43+
Environment.GetEnvironmentVariable("HOME");
44+
4145
var certDirPath = Path.Combine(userHomeDir, ".k8scerts");
4246
Directory.CreateDirectory(certDirPath);
4347

@@ -61,13 +65,8 @@ public static async Task<string> GeneratePfxAsync(KubernetesClientConfiguration
6165
var process = new Process();
6266
process.StartInfo = new ProcessStartInfo()
6367
{
64-
FileName = @"/bin/bash",
65-
Arguments = string.Format(
66-
CultureInfo.InvariantCulture,
67-
"-c \"openssl pkcs12 -export -out {0} -inkey {1} -in {2} -passout pass:\"",
68-
pfxFilePath,
69-
keyFilePath,
70-
certFilePath),
68+
FileName = @"openssl",
69+
Arguments = $"pkcs12 -export -out {pfxFilePath} -inkey {keyFilePath} -in {certFilePath} -passout pass:",
7170
CreateNoWindow = true,
7271
RedirectStandardError = true,
7372
RedirectStandardOutput = true

0 commit comments

Comments
 (0)