Finish stylecop cleanup on Client

This commit is contained in:
Jordan Brown
2018-11-28 10:35:59 -05:00
parent 51da02dd61
commit 6ffad8af21
17 changed files with 269 additions and 97 deletions
+3 -3
View File
@@ -1071,7 +1071,7 @@
<Rule Id="SA1113" Action="Warning" />
<Rule Id="SA1114" Action="Warning" />
<Rule Id="SA1115" Action="Warning" />
<Rule Id="SA1116" Action="Warning" />
<Rule Id="SA1116" Action="None" />
<Rule Id="SA1117" Action="Warning" />
<Rule Id="SA1118" Action="Warning" />
<Rule Id="SA1119" Action="Warning" />
@@ -1091,7 +1091,7 @@
<Rule Id="SA1134" Action="Warning" />
<Rule Id="SA1200" Action="None" />
<Rule Id="SA1201" Action="None" />
<Rule Id="SA1202" Action="Warning" />
<Rule Id="SA1202" Action="None" />
<Rule Id="SA1203" Action="Warning" />
<Rule Id="SA1204" Action="Warning" />
<Rule Id="SA1205" Action="Warning" />
@@ -1130,7 +1130,7 @@
<Rule Id="SA1410" Action="Warning" />
<Rule Id="SA1411" Action="Warning" />
<Rule Id="SA1500" Action="Warning" />
<Rule Id="SA1501" Action="Warning" />
<Rule Id="SA1501" Action="None" />
<Rule Id="SA1502" Action="None" />
<Rule Id="SA1503" Action="None" />
<Rule Id="SA1504" Action="Warning" />
+4 -1
View File
@@ -50,7 +50,10 @@ namespace Tgstation.Server.Api.Models
[NotMapped]
public Job MoveJob { get; set; }
/// <inheritdoc />
/// <summary>
/// Create a clone of the essential <see cref="Instance"/> metadata
/// </summary>
/// <returns>A clone of the essential <see cref="Instance"/> metadata</returns>
public Instance CloneMetadata() => new Instance
{
Id = Id,
@@ -13,7 +13,7 @@
/// <summary>
/// Gets the <see cref="ChatBot.ConnectionString"/> associated with the <see cref="ChatConnectionStringBuilder"/>
/// </summary>
/// <returns></returns>
/// <returns>The <see cref="ChatBot.ConnectionString"/> associated with the <see cref="ChatConnectionStringBuilder"/></returns>
public abstract override string ToString();
}
}
@@ -42,7 +42,7 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// Construct a <see cref="TestMergeBase"/> from a <paramref name="copy"/>
/// </summary>
/// <param name="copy"></param>
/// <param name="copy">The <see cref="TestMergeBase"/> to copy data from</param>
protected TestMergeBase(TestMergeBase copy)
{
if (copy == null)
+99 -85
View File
@@ -49,6 +49,79 @@ namespace Tgstation.Server.Client
/// </summary>
ApiHeaders headers;
static JsonSerializerSettings GetSerializerSettings() => new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new[] { new VersionConverter() }
};
static void HandleBadResponse(HttpResponseMessage response, string json)
{
ErrorMessage errorMessage = null;
try
{
// check if json serializes to an error message
errorMessage = JsonConvert.DeserializeObject<ErrorMessage>(json, GetSerializerSettings());
}
catch (JsonException) { }
const string BadSpecExtension = " This is not part of TGS4 communication specification and should be reported if it was returned from a TGS4 server!";
#pragma warning disable IDE0010 // Add missing cases
switch (response.StatusCode)
#pragma warning restore IDE0010 // Add missing cases
{
case HttpStatusCode.UpgradeRequired:
throw new ApiMismatchException(errorMessage ?? new ErrorMessage
{
Message = "API Mismatch but no current API version provided!" + BadSpecExtension,
SeverApiVersion = null
});
case HttpStatusCode.Unauthorized:
throw new UnauthorizedException();
case HttpStatusCode.RequestTimeout:
throw new RequestTimeoutException();
case HttpStatusCode.Forbidden:
throw new InsufficientPermissionsException();
case HttpStatusCode.ServiceUnavailable:
throw new ServiceUnavailableException();
case HttpStatusCode.Gone:
errorMessage = errorMessage ?? new ErrorMessage
{
Message = "The requested resource could not be found!",
SeverApiVersion = null
};
goto case HttpStatusCode.Conflict;
case HttpStatusCode.NotFound:
// our fault somehow
errorMessage = errorMessage ?? new ErrorMessage
{
Message = "This is not a valid route!" + BadSpecExtension,
SeverApiVersion = null
};
goto case HttpStatusCode.Conflict;
case HttpStatusCode.Conflict:
throw new ConflictException(errorMessage ?? new ErrorMessage
{
Message = "An undescribed conflict occurred!" + BadSpecExtension,
SeverApiVersion = null
}, response.StatusCode);
case HttpStatusCode.NotImplemented:
// unprocessable entity
case (HttpStatusCode)422:
throw new MethodNotSupportedException();
case HttpStatusCode.InternalServerError:
// response json is html
throw new ServerErrorException(json);
case (HttpStatusCode)429:
// rate limited
response.Headers.TryGetValues("Retry-After", out var values);
throw new RateLimitException(values?.FirstOrDefault());
default:
throw new ApiConflictException(errorMessage, response.StatusCode);
}
}
/// <summary>
/// Construct an <see cref="ApiClient"/>
/// </summary>
@@ -60,7 +133,7 @@ namespace Tgstation.Server.Client
this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
Url = url ?? throw new ArgumentNullException(nameof(url));
headers = apiHeaders ?? throw new ArgumentNullException(nameof(apiHeaders));
requestLoggers = new List<IRequestLogger>();
}
@@ -70,10 +143,11 @@ namespace Tgstation.Server.Client
/// <summary>
/// Main request method
/// </summary>
/// <typeparam name="TResult">The resulting POCO type</typeparam>
/// <param name="route">The route to run</param>
/// <param name="body">The body of the request</param>
/// <param name="method">The method of the request</param>
/// <param name="instanceId">The optional <see cref="Api.Models.Instance.Id"/> for the request</param>
/// <param name="instanceId">The optional <see cref="Instance.Id"/> for the request</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response on success</returns>
async Task<TResult> RunRequest<TResult>(string route, object body, HttpMethod method, long? instanceId, CancellationToken cancellationToken)
@@ -85,102 +159,42 @@ namespace Tgstation.Server.Client
if (body == null && (method == HttpMethod.Post || method == HttpMethod.Put))
throw new InvalidOperationException("Body cannot be null for POST or PUT!");
HttpResponseMessage response;
var fullUri = new Uri(Url, route);
var message = new HttpRequestMessage(method, fullUri);
var serializerSettings = new JsonSerializerSettings
var serializerSettings = GetSerializerSettings();
using (var request = new HttpRequestMessage(method, fullUri))
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new[] { new VersionConverter() }
};
if (body != null)
request.Content = new StringContent(JsonConvert.SerializeObject(body, serializerSettings), Encoding.UTF8, ApiHeaders.ApplicationJson);
if (body != null)
message.Content = new StringContent(JsonConvert.SerializeObject(body, serializerSettings), Encoding.UTF8, ApiHeaders.ApplicationJson);
headers.SetRequestHeaders(request.Headers, instanceId);
headers.SetRequestHeaders(message.Headers, instanceId);
await Task.WhenAll(requestLoggers.Select(x => x.LogRequest(request, cancellationToken))).ConfigureAwait(false);
await Task.WhenAll(requestLoggers.Select(x => x.LogRequest(message, cancellationToken))).ConfigureAwait(false);
response = await httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
}
var response = await httpClient.SendAsync(message, cancellationToken).ConfigureAwait(false);
await Task.WhenAll(requestLoggers.Select(x => x.LogResponse(response, cancellationToken))).ConfigureAwait(false);
var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
using (response)
{
ErrorMessage errorMessage = null;
await Task.WhenAll(requestLoggers.Select(x => x.LogResponse(response, cancellationToken))).ConfigureAwait(false);
var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
HandleBadResponse(response, json);
if (String.IsNullOrWhiteSpace(json))
json = JsonConvert.SerializeObject(new object());
try
{
//check if json serializes to an error message
errorMessage = JsonConvert.DeserializeObject<ErrorMessage>(json, serializerSettings);
return JsonConvert.DeserializeObject<TResult>(json, serializerSettings);
}
catch (JsonException) { }
const string BadSpecExtension = " This is not part of TGS4 communication specification and should be reported if it was returned from a TGS4 server!";
switch (response.StatusCode)
catch (JsonException)
{
case HttpStatusCode.UpgradeRequired:
throw new ApiMismatchException(errorMessage ?? new ErrorMessage
{
Message = "API Mismatch but no current API version provided!" + BadSpecExtension,
SeverApiVersion = null
});
case HttpStatusCode.Unauthorized:
throw new UnauthorizedException();
case HttpStatusCode.RequestTimeout:
throw new RequestTimeoutException();
case HttpStatusCode.Forbidden:
throw new InsufficientPermissionsException();
case HttpStatusCode.ServiceUnavailable:
throw new ServiceUnavailableException();
case HttpStatusCode.Gone:
errorMessage = errorMessage ?? new ErrorMessage
{
Message = "The requested resource could not be found!",
SeverApiVersion = null
};
goto case HttpStatusCode.Conflict;
case HttpStatusCode.NotFound: //our fault somehow
errorMessage = errorMessage ?? new ErrorMessage
{
Message = "This is not a valid route!" + BadSpecExtension,
SeverApiVersion = null
};
goto case HttpStatusCode.Conflict;
case HttpStatusCode.Conflict:
throw new ConflictException(errorMessage ?? new ErrorMessage
{
Message = "An undescribed conflict occurred!" + BadSpecExtension,
SeverApiVersion = null
}, response.StatusCode);
case HttpStatusCode.NotImplemented:
case (HttpStatusCode)422: //unprocessable entity
throw new MethodNotSupportedException();
case HttpStatusCode.InternalServerError:
//response
throw new ServerErrorException(json); //json is html
case (HttpStatusCode)429: //rate limited
response.Headers.TryGetValues("Retry-After", out var values);
throw new RateLimitException(values?.FirstOrDefault());
default:
throw new ApiConflictException(errorMessage, response.StatusCode);
throw new UnrecognizedResponseException(json, response.StatusCode);
}
}
if (String.IsNullOrWhiteSpace(json))
json = JsonConvert.SerializeObject(new object());
try
{
return JsonConvert.DeserializeObject<TResult>(json, serializerSettings);
}
catch (JsonException)
{
throw new UnrecognizedResponseException(json, response.StatusCode);
}
}
/// <inheritdoc />
@@ -14,6 +14,7 @@ namespace Tgstation.Server.Client.Components
/// The <see cref="IApiClient"/> for the <see cref="ByondClient"/>
/// </summary>
readonly IApiClient apiClient;
/// <summary>
/// The <see cref="Instance"/> for the <see cref="ByondClient"/>
/// </summary>
@@ -14,6 +14,7 @@ namespace Tgstation.Server.Client.Components
/// The <see cref="IApiClient"/> for the <see cref="ChatBotsClient"/>
/// </summary>
readonly IApiClient apiClient;
/// <summary>
/// The <see cref="Instance"/> for the <see cref="ChatBotsClient"/>
/// </summary>
@@ -14,6 +14,7 @@ namespace Tgstation.Server.Client.Components
/// The <see cref="IApiClient"/> for the <see cref="ConfigurationClient"/>
/// </summary>
readonly IApiClient apiClient;
/// <summary>
/// The <see cref="Instance"/> for the <see cref="ConfigurationClient"/>
/// </summary>
@@ -13,6 +13,7 @@ namespace Tgstation.Server.Client.Components
/// The <see cref="IApiClient"/> for the <see cref="DreamDaemonClient"/>
/// </summary>
readonly IApiClient apiClient;
/// <summary>
/// The <see cref="Instance"/> for the <see cref="DreamDaemonClient"/>
/// </summary>
@@ -14,6 +14,7 @@ namespace Tgstation.Server.Client.Components
/// The <see cref="IApiClient"/> for the <see cref="InstanceUserClient"/>
/// </summary>
readonly IApiClient apiClient;
/// <summary>
/// The <see cref="Instance"/> for the <see cref="InstanceUserClient"/>
/// </summary>
@@ -33,6 +34,7 @@ namespace Tgstation.Server.Client.Components
/// <inheritdoc />
public Task<InstanceUser> Create(InstanceUser instanceUser, CancellationToken cancellationToken) => apiClient.Create<InstanceUser, InstanceUser>(Routes.InstanceUser, instanceUser ?? throw new ArgumentNullException(nameof(instanceUser)), instance.Id, cancellationToken);
/// <inheritdoc />
public Task Delete(InstanceUser instanceUser, CancellationToken cancellationToken) => apiClient.Delete(Routes.SetID(Routes.InstanceUser, instanceUser.UserId.Value), instance.Id, cancellationToken);
/// <inheritdoc />
@@ -14,6 +14,7 @@ namespace Tgstation.Server.Client.Components
/// The <see cref="IApiClient"/> for the <see cref="JobsClient"/>
/// </summary>
readonly IApiClient apiClient;
/// <summary>
/// The <see cref="Instance"/> for the <see cref="JobsClient"/>
/// </summary>
@@ -13,6 +13,7 @@ namespace Tgstation.Server.Client.Components
/// The <see cref="IApiClient"/> for the <see cref="RepositoryClient"/>
/// </summary>
readonly IApiClient apiClient;
/// <summary>
/// The <see cref="Instance"/> for the <see cref="RepositoryClient"/>
/// </summary>
@@ -22,7 +23,7 @@ namespace Tgstation.Server.Client.Components
/// Construct a <see cref="RepositoryClient"/>
/// </summary>
/// <param name="apiClient">The value of <see cref="apiClient"/></param>
/// <param name="instance"></param>
/// <param name="instance">The value of <see cref="instance"/></param>
public RepositoryClient(IApiClient apiClient, Instance instance)
{
this.apiClient = apiClient;
+143
View File
@@ -10,10 +10,19 @@ namespace Tgstation.Server.Client
/// </summary>
interface IApiClient : IDisposable
{
/// <summary>
/// The <see cref="ApiHeaders"/> the <see cref="IApiClient"/> uses
/// </summary>
ApiHeaders Headers { get; set; }
/// <summary>
/// The <see cref="Uri"/> pointing the tgstation-server
/// </summary>
Uri Url { get; }
/// <summary>
/// The request timeout
/// </summary>
TimeSpan Timeout { get; set; }
/// <summary>
@@ -22,21 +31,155 @@ namespace Tgstation.Server.Client
/// <param name="requestLogger">The <see cref="IRequestLogger"/> to add</param>
void AddRequestLogger(IRequestLogger requestLogger);
/// <summary>
/// Run an HTTP PUT request
/// </summary>
/// <typeparam name="TBody">The type to of the request body</typeparam>
/// <typeparam name="TResult">The type of the response body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="body">The request body</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/></returns>
Task<TResult> Create<TBody, TResult>(string route, TBody body, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP PUT request
/// </summary>
/// <typeparam name="TResult">The type of the response body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/></returns>
Task<TResult> Create<TResult>(string route, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP GET request
/// </summary>
/// <typeparam name="TResult">The type of the response body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/></returns>
Task<TResult> Read<TResult>(string route, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP POST request
/// </summary>
/// <typeparam name="TBody">The type to of the request body</typeparam>
/// <typeparam name="TResult">The type of the response body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="body">The request body</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/></returns>
Task<TResult> Update<TBody, TResult>(string route, TBody body, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP POST request
/// </summary>
/// <typeparam name="TResult">The type of the response body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/></returns>
Task<TResult> Update<TResult>(string route, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP POST request
/// </summary>
/// <typeparam name="TBody">The type to of the request body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="body">The request body</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task Update<TBody>(string route, TBody body, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP DELETE request
/// </summary>
/// <param name="route">The server route to make the request to</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task Delete(string route, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP PUT request
/// </summary>
/// <typeparam name="TBody">The type to of the request body</typeparam>
/// <typeparam name="TResult">The type of the response body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="body">The request body</param>
/// <param name="instanceId">The <see cref="Api.Models.Instance.Id"/> to make the request to</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/></returns>
Task<TResult> Create<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP PUT request
/// </summary>
/// <typeparam name="TResult">The type of the response body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="instanceId">The <see cref="Api.Models.Instance.Id"/> to make the request to</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/></returns>
Task<TResult> Create<TResult>(string route, long instanceId, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP PATCH request
/// </summary>
/// <typeparam name="TResult">The type of the response body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="instanceId">The <see cref="Api.Models.Instance.Id"/> to make the request to</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/></returns>
Task<TResult> Patch<TResult>(string route, long instanceId, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP GET request
/// </summary>
/// <typeparam name="TResult">The type of the response body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="instanceId">The <see cref="Api.Models.Instance.Id"/> to make the request to</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/></returns>
Task<TResult> Read<TResult>(string route, long instanceId, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP POST request
/// </summary>
/// <typeparam name="TBody">The type to of the request body</typeparam>
/// <typeparam name="TResult">The type of the response body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="body">The request body</param>
/// <param name="instanceId">The <see cref="Api.Models.Instance.Id"/> to make the request to</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/></returns>
Task<TResult> Update<TBody, TResult>(string route, TBody body, long instanceId, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP DELETE request
/// </summary>
/// <param name="route">The server route to make the request to</param>
/// <param name="instanceId">The <see cref="Api.Models.Instance.Id"/> to make the request to</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task Delete(string route, long instanceId, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP DELETE request
/// </summary>
/// <typeparam name="TBody">The type to of the request body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="body">The request body</param>
/// <param name="instanceId">The <see cref="Api.Models.Instance.Id"/> to make the request to</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task Delete<TBody>(string route, TBody body, long instanceId, CancellationToken cancellationToken);
/// <summary>
/// Run an HTTP DELETE request
/// </summary>
/// <typeparam name="TResult">The type of the response body</typeparam>
/// <param name="route">The server route to make the request to</param>
/// <param name="instanceId">The <see cref="Api.Models.Instance.Id"/> to make the request to</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the response body as a <typeparamref name="TResult"/></returns>
Task<TResult> Delete<TResult>(string route, long instanceId, CancellationToken cancellationToken);
}
}
@@ -43,6 +43,8 @@ namespace Tgstation.Server.Client
/// <summary>
/// The <see cref="ServerInformation"/> of the <see cref="IServerClient"/>
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ServerInformation"/> of the target server</returns>
Task<ServerInformation> Version(CancellationToken cancellationToken);
/// <summary>
@@ -16,8 +16,8 @@ namespace Tgstation.Server.Client
/// <param name="host">The URL to access TGS</param>
/// <param name="username">The username to for the <see cref="IServerClient"/></param>
/// <param name="password">The password for the <see cref="IServerClient"/></param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <param name="timeout">The <see cref="TimeSpan"/> representing timeout for the connection</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a new <see cref="IServerClient"/></returns>
Task<IServerClient> CreateServerClient(Uri host, string username, string password, TimeSpan timeout = default, CancellationToken cancellationToken = default);
@@ -24,7 +24,7 @@ namespace Tgstation.Server.Client
/// <summary>
/// Construct an <see cref="InstanceManagerClient"/>
/// </summary>
/// <param name="apiClient"></param>
/// <param name="apiClient">The value of <see cref="apiClient"/></param>
public InstanceManagerClient(IApiClient apiClient)
{
this.apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient));
@@ -55,6 +55,7 @@ namespace Tgstation.Server.Client
client = new InstanceClient(apiClient, instance);
cachedClients.Add(instance.Id, client);
}
return client;
}
}
@@ -13,7 +13,7 @@ namespace Tgstation.Server.Client
/// <summary>
/// The <see cref="IApiClientFactory"/> for the <see cref="ServerClientFactory"/>
/// </summary>
static readonly IApiClientFactory apiClientFactory = new ApiClientFactory();
static readonly IApiClientFactory ApiClientFactory = new ApiClientFactory();
/// <summary>
/// The <see cref="ProductHeaderValue"/> for the <see cref="ServerClientFactory"/>
@@ -40,12 +40,13 @@ namespace Tgstation.Server.Client
throw new ArgumentNullException(nameof(password));
Token token;
using (var api = apiClientFactory.CreateApiClient(host, new ApiHeaders(productHeaderValue, username, password)))
using (var api = ApiClientFactory.CreateApiClient(host, new ApiHeaders(productHeaderValue, username, password)))
{
if (timeout != default)
api.Timeout = timeout;
token = await api.Update<Token>(Routes.Root, cancellationToken).ConfigureAwait(false);
}
return CreateServerClient(host, token, timeout);
}
@@ -56,7 +57,7 @@ namespace Tgstation.Server.Client
throw new ArgumentNullException(nameof(host));
if (token == null)
throw new ArgumentNullException(nameof(token));
var result = new ServerClient(apiClientFactory.CreateApiClient(host, new ApiHeaders(productHeaderValue, token.Bearer)), token);
var result = new ServerClient(ApiClientFactory.CreateApiClient(host, new ApiHeaders(productHeaderValue, token.Bearer)), token);
if (timeout != default)
result.Timeout = timeout;
return result;