Merge pull request #7 from chgeuer/master

Allows execution on Windows
This commit is contained in:
Brendan Burns
2017-07-06 07:06:57 -07:00
committed by GitHub
2 changed files with 11 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ namespace k8s
using k8s.Exceptions; using k8s.Exceptions;
using k8s.KubeConfigModels; using k8s.KubeConfigModels;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
using System.Runtime.InteropServices;
/// <summary> /// <summary>
/// Represents a set of kubernetes client configuration settings /// Represents a set of kubernetes client configuration settings
@@ -31,7 +32,9 @@ namespace k8s
/// <summary> /// <summary>
/// kubeconfig Default Location /// kubeconfig Default Location
/// </summary> /// </summary>
private static readonly string KubeConfigDefaultLocation = Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".kube/config"); private static readonly string KubeConfigDefaultLocation = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), @".kube\config") :
Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".kube/config");
/// <summary> /// <summary>
/// Gets CurrentContext /// Gets CurrentContext

View File

@@ -4,6 +4,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -37,7 +38,10 @@
/// TODO: kabhishek8260 Remplace the method with X509 Certificate with private key(in dotnet 2.0) /// TODO: kabhishek8260 Remplace the method with X509 Certificate with private key(in dotnet 2.0)
public static async Task<string> GeneratePfxAsync(KubernetesClientConfiguration config) public static async Task<string> GeneratePfxAsync(KubernetesClientConfiguration config)
{ {
var userHomeDir = Environment.GetEnvironmentVariable("HOME"); var userHomeDir = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
Environment.GetEnvironmentVariable("USERPROFILE") :
Environment.GetEnvironmentVariable("HOME");
var certDirPath = Path.Combine(userHomeDir, ".k8scerts"); var certDirPath = Path.Combine(userHomeDir, ".k8scerts");
Directory.CreateDirectory(certDirPath); Directory.CreateDirectory(certDirPath);
@@ -61,13 +65,8 @@
var process = new Process(); var process = new Process();
process.StartInfo = new ProcessStartInfo() process.StartInfo = new ProcessStartInfo()
{ {
FileName = @"/bin/bash", FileName = @"openssl",
Arguments = string.Format( Arguments = $"pkcs12 -export -out {pfxFilePath} -inkey {keyFilePath} -in {certFilePath} -passout pass:",
CultureInfo.InvariantCulture,
"-c \"openssl pkcs12 -export -out {0} -inkey {1} -in {2} -passout pass:\"",
pfxFilePath,
keyFilePath,
certFilePath),
CreateNoWindow = true, CreateNoWindow = true,
RedirectStandardError = true, RedirectStandardError = true,
RedirectStandardOutput = true RedirectStandardOutput = true