Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 76aaaef

Browse files
Adapting to NPath changes
1 parent b31688a commit 76aaaef

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

src/GitHub.Api/Authentication/LoginManager.cs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class LoginManager : ILoginManager
3030
private readonly string fingerprint;
3131
private readonly IProcessManager processManager;
3232
private readonly ITaskManager taskManager;
33-
private readonly NPath nodeJsExecutablePath;
34-
private readonly NPath octorunScript;
33+
private readonly NPath? nodeJsExecutablePath;
34+
private readonly NPath? octorunScript;
3535

3636
/// <summary>
3737
/// Initializes a new instance of the <see cref="LoginManager"/> class.
@@ -51,7 +51,7 @@ public LoginManager(
5151
string clientSecret,
5252
string authorizationNote = null,
5353
string fingerprint = null,
54-
IProcessManager processManager = null, ITaskManager taskManager = null, NPath nodeJsExecutablePath = null, NPath octorunScript = null)
54+
IProcessManager processManager = null, ITaskManager taskManager = null, NPath? nodeJsExecutablePath = null, NPath? octorunScript = null)
5555
{
5656
Guard.ArgumentNotNull(keychain, nameof(keychain));
5757
Guard.ArgumentNotNullOrWhiteSpace(clientId, nameof(clientId));
@@ -251,10 +251,20 @@ private async Task<ApplicationAuthorization> TryLogin(
251251
string password
252252
)
253253
{
254+
if (!nodeJsExecutablePath.HasValue)
255+
{
256+
throw new InvalidOperationException("nodeJsExecutablePath must be set");
257+
}
258+
259+
if (!octorunScript.HasValue)
260+
{
261+
throw new InvalidOperationException("octorunScript must be set");
262+
}
263+
254264
ApplicationAuthorization auth;
255-
var loginTask = new OctorunTask(taskManager.Token, nodeJsExecutablePath, octorunScript,
265+
var loginTask = new OctorunTask(taskManager.Token, nodeJsExecutablePath.Value, octorunScript.Value,
256266
"login", ApplicationInfo.ClientId, ApplicationInfo.ClientSecret);
257-
loginTask.Configure(processManager, workingDirectory: octorunScript.Parent.Parent, withInput: true);
267+
loginTask.Configure(processManager, workingDirectory: octorunScript.Value.Parent.Parent, withInput: true);
258268
loginTask.OnStartProcess += proc =>
259269
{
260270
proc.StandardInput.WriteLine(username);
@@ -297,12 +307,20 @@ private async Task<ApplicationAuthorization> TryContinueLogin(
297307
string code
298308
)
299309
{
300-
logger.Info("Continue Username:{0} {1} {2}", username, password, code);
310+
if (!nodeJsExecutablePath.HasValue)
311+
{
312+
throw new InvalidOperationException("nodeJsExecutablePath must be set");
313+
}
314+
315+
if (!octorunScript.HasValue)
316+
{
317+
throw new InvalidOperationException("octorunScript must be set");
318+
}
301319

302320
ApplicationAuthorization auth;
303-
var loginTask = new OctorunTask(taskManager.Token, nodeJsExecutablePath, octorunScript,
321+
var loginTask = new OctorunTask(taskManager.Token, nodeJsExecutablePath.Value, octorunScript.Value,
304322
"login --twoFactor", ApplicationInfo.ClientId, ApplicationInfo.ClientSecret);
305-
loginTask.Configure(processManager, workingDirectory: octorunScript.Parent.Parent, withInput: true);
323+
loginTask.Configure(processManager, workingDirectory: octorunScript.Value.Parent.Parent, withInput: true);
306324
loginTask.OnStartProcess += proc =>
307325
{
308326
proc.StandardInput.WriteLine(username);
@@ -313,8 +331,6 @@ string code
313331

314332
var ret = (await loginTask.StartAwait());
315333

316-
logger.Trace("Return: {0}", string.Join(";", ret.ToArray()));
317-
318334
if (ret.Count == 0)
319335
{
320336
throw new Exception("Authentication failed");

0 commit comments

Comments
 (0)