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

Commit 757f578

Browse files
committed
Fixes #100 Use pull-secret API
1 parent ad97e0a commit 757f578

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

Diff for: CRCTray.cs

+5-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.Threading.Tasks;
55
using System.Collections.Generic;
6+
using System.IO;
67
using CRCTray.Communication;
78
using CRCTray.Helpers;
89

@@ -228,19 +229,12 @@ await TaskHelpers.TryTaskAndNotify(TaskHandlers.Stop,
228229
async private void StartMenu_Click(object sender, EventArgs e)
229230
{
230231
// Check using get-config if pullSecret is configured
231-
var configs = await TaskHelpers.TryTaskAndNotify(TaskHandlers.ConfigView,
232+
var pullsecret = await TaskHelpers.TryTaskAndNotify(TaskHandlers.GetPullSecret,
232233
String.Empty,
233234
String.Empty,
234235
String.Empty);
235236

236-
if(configs == null)
237-
{
238-
// no config was returned, does this mean a communication error?
239-
TrayIcon.NotifyError("Unable to read configuration. Is the CRC daemon running?");
240-
return;
241-
}
242-
243-
if (configs != null && configs.Configs.PullSecretFile == String.Empty)
237+
if (!pullsecret)
244238
{
245239
var pullSecretForm = new PullSecretPickerForm();
246240
var pullSecretPath = pullSecretForm.ShowFilePicker();
@@ -254,13 +248,13 @@ async private void StartMenu_Click(object sender, EventArgs e)
254248
["pull-secret-file"] = pullSecretPath
255249
};
256250

257-
await TaskHelpers.TryTaskAndNotify(TaskHandlers.SetConfig, pullSecretConfig,
251+
string data = File.ReadAllText(pullSecretPath);
252+
await TaskHelpers.TryTaskAndNotify(TaskHandlers.SetPullSecret, data,
258253
"Pull Secret stored",
259254
"Pull Secret not stored",
260255
String.Empty);
261256
}
262257

263-
264258
TrayIcon.NotifyInfo(@"Starting Cluster");
265259

266260
var startResult = await TaskHelpers.TryTaskAndNotify(TaskHandlers.Start,

Diff for: Communication/DaemonCommander.cs

+11
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ public static LogsResult GetLogs()
8181
return getResultsForBasicCommand<LogsResult>(BasicCommands.Logs);
8282
}
8383

84+
public static bool GetPullSecret()
85+
{
86+
return getResultsForBasicCommand<bool>(BasicCommands.PullSecret);
87+
}
88+
89+
public static bool SetPullSecret(string data)
90+
{
91+
var result = postResponse(BasicCommands.PullSecret, data, 30);
92+
return true;
93+
}
94+
8495
private static string SendBasicCommand(string command, int timeout)
8596
{
8697
return getResponse(command, timeout).Result;

Diff for: Communication/Enums.cs

+2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ static class BasicCommands
1414
internal const string ConfigSet = "config/set";
1515
internal const string ConfigUnset = "config/unset";
1616
internal const string Logs = "logs";
17+
18+
internal const string PullSecret = "pull-secret";
1719
}
1820
}

Diff for: Helpers/Handlers.cs

+10
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ public static SetUnsetConfig UnsetConfig(List<string> cfg)
126126
return getTypedResults(DaemonCommander.UnsetConfig, config);
127127
}
128128

129+
public static bool GetPullSecret()
130+
{
131+
return getTypedResults(DaemonCommander.GetPullSecret);
132+
}
133+
134+
public static bool SetPullSecret(string data)
135+
{
136+
return getTypedResults(DaemonCommander.SetPullSecret, data);
137+
}
138+
129139
public static ConsoleResult LoginForDeveloper()
130140
{
131141
return WebConsole();

0 commit comments

Comments
 (0)