Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
[WIP] Use pull-secret API
Browse files Browse the repository at this point in the history
  • Loading branch information
gbraad committed Jul 13, 2021
1 parent ad97e0a commit 010eded
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
16 changes: 5 additions & 11 deletions CRCTray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.IO;
using CRCTray.Communication;
using CRCTray.Helpers;

Expand Down Expand Up @@ -228,19 +229,12 @@ await TaskHelpers.TryTaskAndNotify(TaskHandlers.Stop,
async private void StartMenu_Click(object sender, EventArgs e)
{
// Check using get-config if pullSecret is configured
var configs = await TaskHelpers.TryTaskAndNotify(TaskHandlers.ConfigView,
var pullsecret = await TaskHelpers.TryTaskAndNotify(TaskHandlers.GetPullSecret,
String.Empty,
String.Empty,
String.Empty);

if(configs == null)
{
// no config was returned, does this mean a communication error?
TrayIcon.NotifyError("Unable to read configuration. Is the CRC daemon running?");
return;
}

if (configs != null && configs.Configs.PullSecretFile == String.Empty)
if (!pullsecret)
{
var pullSecretForm = new PullSecretPickerForm();
var pullSecretPath = pullSecretForm.ShowFilePicker();
Expand All @@ -254,13 +248,13 @@ async private void StartMenu_Click(object sender, EventArgs e)
["pull-secret-file"] = pullSecretPath
};

await TaskHelpers.TryTaskAndNotify(TaskHandlers.SetConfig, pullSecretConfig,
string data = File.ReadAllText(pullSecretPath);
await TaskHelpers.TryTaskAndNotify(TaskHandlers.SetPullSecret, data,
"Pull Secret stored",
"Pull Secret not stored",
String.Empty);
}


TrayIcon.NotifyInfo(@"Starting Cluster");

var startResult = await TaskHelpers.TryTaskAndNotify(TaskHandlers.Start,
Expand Down
11 changes: 11 additions & 0 deletions Communication/DaemonCommander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ public static LogsResult GetLogs()
return getResultsForBasicCommand<LogsResult>(BasicCommands.Logs);
}

public static bool GetPullSecret()
{
return getResultsForBasicCommand<bool>(BasicCommands.PullSecret);
}

public static bool SetPullSecret(string data)
{
var result = postResponse(BasicCommands.PullSecret, data, 30);
return true;
}

private static string SendBasicCommand(string command, int timeout)
{
return getResponse(command, timeout).Result;
Expand Down
2 changes: 2 additions & 0 deletions Communication/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ static class BasicCommands
internal const string ConfigSet = "config/set";
internal const string ConfigUnset = "config/unset";
internal const string Logs = "logs";

internal const string PullSecret = "pull-secret";
}
}
10 changes: 10 additions & 0 deletions Helpers/Handlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ public static SetUnsetConfig UnsetConfig(List<string> cfg)
return getTypedResults(DaemonCommander.UnsetConfig, config);
}

public static bool GetPullSecret()
{
return getTypedResults(DaemonCommander.GetPullSecret);
}

public static bool SetPullSecret(string data)
{
return getTypedResults(DaemonCommander.SetPullSecret, data);
}

public static ConsoleResult LoginForDeveloper()
{
return WebConsole();
Expand Down

0 comments on commit 010eded

Please sign in to comment.