Merge pull request #782 from Cyberboss/AddTokenSet [NugetDeploy]

IServerClient can now have it's Token changed
This commit is contained in:
Jordan Brown
2018-10-13 13:52:56 -04:00
committed by GitHub
5 changed files with 32 additions and 10 deletions
+12 -3
View File
@@ -21,7 +21,11 @@ namespace Tgstation.Server.Client
public Uri Url { get; }
/// <inheritdoc />
public ApiHeaders Headers { get; }
public ApiHeaders Headers
{
get => headers;
set => headers = value ?? throw new InvalidOperationException("Cannot set null headers!");
}
/// <inheritdoc />
public TimeSpan Timeout
@@ -40,6 +44,11 @@ namespace Tgstation.Server.Client
/// </summary>
readonly List<IRequestLogger> requestLoggers;
/// <summary>
/// Backing field for <see cref="Headers"/>
/// </summary>
ApiHeaders headers;
/// <summary>
/// Construct an <see cref="ApiClient"/>
/// </summary>
@@ -50,7 +59,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));
headers = apiHeaders ?? throw new ArgumentNullException(nameof(apiHeaders));
requestLoggers = new List<IRequestLogger>();
}
@@ -89,7 +98,7 @@ namespace Tgstation.Server.Client
if (body != null)
message.Content = new StringContent(JsonConvert.SerializeObject(body, serializerSettings), Encoding.UTF8, ApiHeaders.ApplicationJson);
Headers.SetRequestHeaders(message.Headers, instanceId);
headers.SetRequestHeaders(message.Headers, instanceId);
await Task.WhenAll(requestLoggers.Select(x => x.LogRequest(message, cancellationToken))).ConfigureAwait(false);
+1 -1
View File
@@ -10,7 +10,7 @@ namespace Tgstation.Server.Client
/// </summary>
interface IApiClient : IDisposable
{
ApiHeaders Headers { get; }
ApiHeaders Headers { get; set; }
Uri Url { get; }
+2 -2
View File
@@ -16,9 +16,9 @@ namespace Tgstation.Server.Client
Uri Url { get; }
/// <summary>
/// The <see cref="Token"/> being used to access the server
/// The <see cref="Token"/> used to access the server
/// </summary>
Token Token { get; }
Token Token { get; set; }
/// <summary>
/// The connection timeout
+15 -2
View File
@@ -13,7 +13,15 @@ namespace Tgstation.Server.Client
public Uri Url => apiClient.Url;
/// <inheritdoc />
public Token Token { get; }
public Token Token
{
get => token;
set
{
token = value ?? throw new InvalidOperationException("Cannot set a null Token!");
apiClient.Headers = new ApiHeaders(apiClient.Headers.UserAgent, token.Bearer);
}
}
/// <inheritdoc />
public TimeSpan Timeout
@@ -36,6 +44,11 @@ namespace Tgstation.Server.Client
/// </summary>
readonly IApiClient apiClient;
/// <summary>
/// Backing field for <see cref="Token"/>
/// </summary>
Token token;
/// <summary>
/// Construct a <see cref="ServerClient"/>
/// </summary>
@@ -44,7 +57,7 @@ namespace Tgstation.Server.Client
public ServerClient(IApiClient apiClient, Token token)
{
this.apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient));
Token = token ?? throw new ArgumentNullException(nameof(token));
this.token = token ?? throw new ArgumentNullException(nameof(token));
if (Token.Bearer != apiClient.Headers.Token)
throw new ArgumentOutOfRangeException(nameof(token), token, "Provided token does not match apiClient headers!");
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DebugType>Full</DebugType>
<Version>4.0.1</Version>
<Version>4.0.2</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Cyberboss</Authors>
<Company>/tg/station 13</Company>
@@ -16,7 +16,7 @@
<PackageIconUrl>https://raw.githubusercontent.com/tgstation/tgstation-server/master/build/tgs.ico</PackageIconUrl>
<PackageLicenseUrl>https://github.com/tgstation/tgstation-server/blob/master/LICENSE</PackageLicenseUrl>
<PackageTags>json web api tgstation-server tgstation ss13 byond client</PackageTags>
<PackageReleaseNotes>Initial release</PackageReleaseNotes>
<PackageReleaseNotes>Added the ability to change the Token of IServerClient</PackageReleaseNotes>
<Copyright>2018</Copyright>
</PropertyGroup>