Add project files
This commit is contained in:
parent
4dafed3553
commit
8cf01ead74
40 changed files with 3967 additions and 0 deletions
41
StalwartSimpleLoginMiddleware/Services/StalwartClient.cs
Normal file
41
StalwartSimpleLoginMiddleware/Services/StalwartClient.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using AdOrbitSDK;
|
||||
using StalwartSimpleLoginMiddleware.Constants;
|
||||
|
||||
namespace StalwartSimpleLoginMiddleware.Services;
|
||||
|
||||
public class StalwartClient() : IDisposable
|
||||
{
|
||||
private Client _userClient;
|
||||
|
||||
private static HttpClient HttpClient => new()
|
||||
{
|
||||
BaseAddress = new Uri(Environment.GetEnvironmentVariable(EnvironmentVariable.MailServerUri) + "/api/")
|
||||
};
|
||||
|
||||
public async Task<Client> GetClient()
|
||||
{
|
||||
if (_userClient != null) return _userClient;
|
||||
|
||||
return GetClient(Environment.GetEnvironmentVariable(EnvironmentVariable.MailServerApiKey) ?? string.Empty);
|
||||
}
|
||||
|
||||
private Client GetClient(string apiKey)
|
||||
{
|
||||
if (_userClient != null) return _userClient;
|
||||
|
||||
if (string.IsNullOrEmpty(HttpClient.BaseAddress?.AbsoluteUri))
|
||||
throw new NullReferenceException($"{EnvironmentVariable.MailServerUri} is missing in environment.");
|
||||
|
||||
if (string.IsNullOrEmpty(apiKey))
|
||||
throw new NullReferenceException($"{EnvironmentVariable.MailServerApiKey} is missing in environment.");
|
||||
|
||||
_userClient = new Client(HttpClient, apiKey);
|
||||
return _userClient;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
HttpClient.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue