-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1936 from tgstation/graphql
More GraphQL Work
- Loading branch information
Showing
178 changed files
with
8,128 additions
and
1,743 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
src/Tgstation.Server.Api/Models/Internal/LocalServerInformation.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/Tgstation.Server.Client.GraphQL/AuthenticatedGraphQLServerClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
using StrawberryShake; | ||
|
||
using Tgstation.Server.Common.Extensions; | ||
|
||
namespace Tgstation.Server.Client.GraphQL | ||
{ | ||
/// <inheritdoc cref="IAuthenticatedGraphQLServerClient" /> | ||
sealed class AuthenticatedGraphQLServerClient : GraphQLServerClient, IAuthenticatedGraphQLServerClient | ||
{ | ||
/// <inheritdoc /> | ||
public ITransferClient TransferClient => restClient!.Transfer; | ||
|
||
/// <summary> | ||
/// A <see cref="Func{T, TResult}"/> that takes a bearer token as input and outputs a <see cref="ITransferClient"/> that uses it. | ||
/// </summary> | ||
readonly Func<string, IRestServerClient>? getRestClientForToken; | ||
|
||
/// <summary> | ||
/// The current <see cref="IRestServerClient"/>. | ||
/// </summary> | ||
IRestServerClient? restClient; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AuthenticatedGraphQLServerClient"/> class. | ||
/// </summary> | ||
/// <param name="graphQLClient">The <see cref="IGraphQLClient"/> to use.</param> | ||
/// <param name="serviceProvider">The <see cref="IAsyncDisposable"/> to use.</param> | ||
/// <param name="logger">The <see cref="ILogger"/> to use.</param> | ||
/// <param name="restClient">The value of <see cref="restClient"/>.</param> | ||
public AuthenticatedGraphQLServerClient( | ||
IGraphQLClient graphQLClient, | ||
IAsyncDisposable serviceProvider, | ||
ILogger<GraphQLServerClient> logger, | ||
IRestServerClient restClient) | ||
: base(graphQLClient, serviceProvider, logger) | ||
{ | ||
this.restClient = restClient ?? throw new ArgumentNullException(nameof(restClient)); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AuthenticatedGraphQLServerClient"/> class. | ||
/// </summary> | ||
/// <param name="graphQLClient">The <see cref="IGraphQLClient"/> to use.</param> | ||
/// <param name="serviceProvider">The <see cref="IAsyncDisposable"/> to use.</param> | ||
/// <param name="logger">The <see cref="ILogger"/> to use.</param> | ||
/// <param name="setAuthenticationHeader">The <see cref="Action{T}"/> to call to set the async local <see cref="AuthenticationHeaderValue"/> for requests.</param> | ||
/// <param name="basicCredentialsHeader">The basic <see cref="AuthenticationHeaderValue"/> to use for reauthentication.</param> | ||
/// <param name="loginResult">The <see cref="ILoginResult"/> <see cref="IOperationResult{TResultData}"/> containing the initial JWT to use.</param> | ||
/// <param name="getRestClientForToken">The value of <see cref="getRestClientForToken"/>.</param> | ||
public AuthenticatedGraphQLServerClient( | ||
IGraphQLClient graphQLClient, | ||
IAsyncDisposable serviceProvider, | ||
ILogger<GraphQLServerClient> logger, | ||
Action<AuthenticationHeaderValue> setAuthenticationHeader, | ||
AuthenticationHeaderValue? basicCredentialsHeader, | ||
IOperationResult<ILoginResult> loginResult, | ||
Func<string, IRestServerClient> getRestClientForToken) | ||
: base( | ||
graphQLClient, | ||
serviceProvider, | ||
logger, | ||
setAuthenticationHeader, | ||
basicCredentialsHeader, | ||
loginResult) | ||
{ | ||
this.getRestClientForToken = getRestClientForToken ?? throw new ArgumentNullException(nameof(getRestClientForToken)); | ||
restClient = getRestClientForToken(loginResult.Data!.Login.Bearer!.EncodedToken); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public sealed override ValueTask DisposeAsync() | ||
#pragma warning disable CA2012 // Use ValueTasks correctly | ||
=> ValueTaskExtensions.WhenAll( | ||
base.DisposeAsync(), | ||
restClient!.DisposeAsync()); | ||
#pragma warning restore CA2012 // Use ValueTasks correctly | ||
|
||
/// <inheritdoc /> | ||
protected sealed override async ValueTask<AuthenticationHeaderValue> CreateUpdatedAuthenticationHeader(string bearer) | ||
{ | ||
var baseTask = base.CreateUpdatedAuthenticationHeader(bearer); | ||
if (restClient != null) | ||
await restClient.DisposeAsync().ConfigureAwait(false); | ||
|
||
if (getRestClientForToken != null) | ||
restClient = getRestClientForToken(bearer); | ||
|
||
return await baseTask.ConfigureAwait(false); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/Tgstation.Server.Client.GraphQL/AuthenticationException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
|
||
namespace Tgstation.Server.Client.GraphQL | ||
{ | ||
/// <summary> | ||
/// <see cref="Exception"/> thrown when automatic <see cref="IGraphQLServerClient"/> authentication fails. | ||
/// </summary> | ||
public sealed class AuthenticationException : Exception | ||
{ | ||
/// <summary> | ||
/// The <see cref="ILogin_Login_Errors_ErrorMessageError"/>. | ||
/// </summary> | ||
public ILogin_Login_Errors_ErrorMessageError? ErrorMessage { get; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AuthenticationException"/> class. | ||
/// </summary> | ||
/// <param name="errorMessage">The value of <see cref="ErrorMessage"/>.</param> | ||
public AuthenticationException(ILogin_Login_Errors_ErrorMessageError errorMessage) | ||
: base(errorMessage?.Message) | ||
{ | ||
ErrorMessage = errorMessage ?? throw new ArgumentNullException(nameof(errorMessage)); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AuthenticationException"/> class. | ||
/// </summary> | ||
public AuthenticationException() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AuthenticationException"/> class. | ||
/// </summary> | ||
/// <param name="message">The <see cref="Exception.Message"/>.</param> | ||
public AuthenticationException(string message) | ||
: base(message) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AuthenticationException"/> class. | ||
/// </summary> | ||
/// <param name="message">The <see cref="Exception.Message"/>.</param> | ||
/// <param name="innerException">The <see cref="Exception.InnerException"/>.</param> | ||
public AuthenticationException(string message, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.