Skip to content

Commit 427a8f6

Browse files
committed
make CredentialModel an ICoderApiClientCredentialProvider
1 parent f02da79 commit 427a8f6

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

App/Models/CredentialModel.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using Coder.Desktop.CoderSdk.Coder;
23

34
namespace Coder.Desktop.App.Models;
45

@@ -14,7 +15,7 @@ public enum CredentialState
1415
Valid,
1516
}
1617

17-
public class CredentialModel
18+
public class CredentialModel : ICoderApiClientCredentialProvider
1819
{
1920
public CredentialState State { get; init; } = CredentialState.Unknown;
2021

@@ -33,4 +34,14 @@ public CredentialModel Clone()
3334
Username = Username,
3435
};
3536
}
37+
38+
public CoderApiClientCredential? GetCoderApiClientCredential()
39+
{
40+
if (State != CredentialState.Valid) return null;
41+
return new CoderApiClientCredential
42+
{
43+
ApiToken = ApiToken!,
44+
CoderUrl = CoderUrl!,
45+
};
46+
}
3647
}

App/Services/HostnameSuffixGetter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ private async Task Refresh()
7878
_dirty = false;
7979
}
8080

81-
var client = _clientFactory.Create(credentials.CoderUrl!.ToString());
82-
client.SetSessionToken(credentials.ApiToken!);
81+
var client = _clientFactory.Create(credentials);
8382
using var timeoutSrc = new CancellationTokenSource(TimeSpan.FromSeconds(10));
8483
var connInfo = await client.GetAgentConnectionInfoGeneric(timeoutSrc.Token);
8584

Tests.App/Services/HostnameSuffixGetterTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public void SetupMocks()
2626
_mCoderApiClientFactory = new Mock<ICoderApiClientFactory>(MockBehavior.Strict);
2727
_mCredentialManager = new Mock<ICredentialManager>(MockBehavior.Strict);
2828
_mCoderApiClient = new Mock<ICoderApiClient>(MockBehavior.Strict);
29-
_mCoderApiClientFactory.Setup(m => m.Create(coderUrl)).Returns(_mCoderApiClient.Object);
29+
_mCoderApiClientFactory.Setup(m => m.Create(It.IsAny<ICoderApiClientCredentialProvider>()))
30+
.Returns(_mCoderApiClient.Object);
3031
}
3132

3233
private Mock<ICoderApiClientFactory> _mCoderApiClientFactory;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy