tgstation-server 6.17.0
The /tg/station 13 server suite
|
Public Member Functions | |||||||
GitHubClientFactory (IAssemblyInformationProvider assemblyInformationProvider, IHttpMessageHandlerFactory httpMessageHandlerFactory, ILogger< GitHubClientFactory > logger, IOptions< GeneralConfiguration > generalConfigurationOptions) | |||||||
Initializes a new instance of the GitHubClientFactory class. | |||||||
void | Dispose () | ||||||
async ValueTask< IGitHubClient > | CreateClient (CancellationToken cancellationToken) | ||||||
Create a IGitHubClient client. Low rate limit unless the server's GitHubAccessToken is set to bypass it.
| |||||||
async ValueTask< IGitHubClient > | CreateClient (string accessToken, CancellationToken cancellationToken) | ||||||
Create a client with authentication using a personal access token.
| |||||||
ValueTask< IGitHubClient?> | CreateClientForRepository (string accessString, RepositoryIdentifier repositoryIdentifier, CancellationToken cancellationToken) | ||||||
Creates a GitHub client that will only be used for a given repositoryIdentifier .
| |||||||
IGitHubClient? | CreateAppClient (string tgsEncodedAppPrivateKey) | ||||||
Create an App (not installation) authenticated IGitHubClient.
| |||||||
Private Member Functions | |
async ValueTask< IGitHubClient?> | GetOrCreateClient (string? accessString, RepositoryIdentifier? repositoryIdentifier, CancellationToken cancellationToken) |
Retrieve a GitHubClient from the clientCache or add a new one based on a given accessString . | |
GitHubClient? | CreateAppClientInternal (string tgsEncodedAppPrivateKey) |
Create an App (not installation) authenticated GitHubClient. | |
GitHubClient | CreateUnauthenticatedClient () |
Creates an unauthenticated GitHubClient. | |
Private Attributes | |
readonly IAssemblyInformationProvider | assemblyInformationProvider |
The IAssemblyInformationProvider for the GitHubClientFactory. | |
readonly IHttpMessageHandlerFactory | httpMessageHandlerFactory |
The IHttpMessageHandlerFactory for the GitHubClientFactory. | |
readonly ILogger< GitHubClientFactory > | logger |
The ILogger for the GitHubClientFactory. | |
readonly GeneralConfiguration | generalConfiguration |
The GeneralConfiguration for the GitHubClientFactory. | |
readonly Dictionary< string,(GitHubClient Client, DateTimeOffset LastUsed, DateTimeOffset? Expiry)> | clientCache |
Cache of created GitHubClients and last used/expiry times, keyed by access token. | |
readonly SemaphoreSlim | clientCacheSemaphore |
The SemaphoreSlim used to guard access to clientCache. | |
Static Private Attributes | |
const uint | ClientCacheHours = 1 |
Limit to the amount of hours a GitHubClient can live in the clientCache. | |
const uint | AppTokenExpiryGraceMinutes = 15 |
Minutes before tokens expire before not using them. | |
const string | DefaultCacheKey = "~!@TGS_DEFAULT_GITHUB_CLIENT_CACHE_KEY@!~" |
The clientCache KeyValuePair<TKey, TValue>.Key used in place of null when accessing a configuration-based client with no token set in GeneralConfiguration.GitHubAccessToken. | |
Definition at line 25 of file GitHubClientFactory.cs.
Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GitHubClientFactory | ( | IAssemblyInformationProvider | assemblyInformationProvider, |
IHttpMessageHandlerFactory | httpMessageHandlerFactory, | ||
ILogger< GitHubClientFactory > | logger, | ||
IOptions< GeneralConfiguration > | generalConfigurationOptions | ||
) |
Initializes a new instance of the GitHubClientFactory class.
assemblyInformationProvider | The value of assemblyInformationProvider. |
httpMessageHandlerFactory | The value of httpMessageHandlerFactory. |
logger | The value of logger. |
generalConfigurationOptions | The IOptions<TOptions> containing the value of generalConfiguration. |
Definition at line 80 of file GitHubClientFactory.cs.
References Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.assemblyInformationProvider, Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.clientCache, Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.clientCacheSemaphore, Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.generalConfiguration, Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.httpMessageHandlerFactory, and Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.logger.
IGitHubClient? Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.CreateAppClient | ( | string | tgsEncodedAppPrivateKey | ) |
Create an App (not installation) authenticated IGitHubClient.
tgsEncodedAppPrivateKey | The TGS encoded app private key string. |
null
on failure.Implements Tgstation.Server.Host.Utils.GitHub.IGitHubClientFactory.
|
private |
Create an App (not installation) authenticated GitHubClient.
tgsEncodedAppPrivateKey | The TGS encoded app private key string. |
null
on failure.Definition at line 270 of file GitHubClientFactory.cs.
References Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.CreateUnauthenticatedClient(), Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.logger, and Tgstation.Server.Api.Models.RepositorySettings.TgsAppPrivateKeyPrefix.
Referenced by Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GetOrCreateClient().
async ValueTask< IGitHubClient > Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.CreateClient | ( | CancellationToken | cancellationToken | ) |
Create a IGitHubClient client. Low rate limit unless the server's GitHubAccessToken is set to bypass it.
cancellationToken | The CancellationToken for the operation. |
Implements Tgstation.Server.Host.Utils.GitHub.IGitHubClientFactory.
async ValueTask< IGitHubClient > Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.CreateClient | ( | string | accessToken, |
CancellationToken | cancellationToken | ||
) |
Create a client with authentication using a personal access token.
accessToken | The GitHub personal access token. |
cancellationToken | The CancellationToken for the operation. |
Implements Tgstation.Server.Host.Utils.GitHub.IGitHubClientFactory.
ValueTask< IGitHubClient?> Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.CreateClientForRepository | ( | string | accessString, |
RepositoryIdentifier | repositoryIdentifier, | ||
CancellationToken | cancellationToken | ||
) |
Creates a GitHub client that will only be used for a given repositoryIdentifier .
accessString | The GitHub personal access token or TGS encoded app private key string. |
repositoryIdentifier | The RepositoryIdentifier for the GitHub ID that the client will be used to connect to. |
cancellationToken | The CancellationToken for the operation. |
null
if authentication failed.Implements Tgstation.Server.Host.Utils.GitHub.IGitHubClientFactory.
|
private |
Creates an unauthenticated GitHubClient.
Definition at line 338 of file GitHubClientFactory.cs.
References Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.assemblyInformationProvider, Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.httpMessageHandlerFactory, and Tgstation.Server.Host.System.IAssemblyInformationProvider.ProductInfoHeaderValue.
Referenced by Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.CreateAppClientInternal(), and Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GetOrCreateClient().
void Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.Dispose | ( | ) |
|
private |
Retrieve a GitHubClient from the clientCache or add a new one based on a given accessString .
accessString | Optional access token to use as credentials or GitHub App private key. If using a TGS encoded app private key, repositoryIdentifier must be set. |
repositoryIdentifier | The optional RepositoryIdentifier for the GitHub ID that the client will be used to connect to. Must be set if accessString is a TGS encoded app private key. |
cancellationToken | The CancellationToken for the operation. |
null
if authentication failed.Definition at line 128 of file GitHubClientFactory.cs.
References Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.AppTokenExpiryGraceMinutes, Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.clientCache, Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.ClientCacheHours, Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.clientCacheSemaphore, Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.CreateAppClientInternal(), Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.CreateUnauthenticatedClient(), Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.DefaultCacheKey, Tgstation.Server.Host.Utils.SemaphoreSlimContext.Lock(), Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.logger, Tgstation.Server.Host.Utils.GitHub.RepositoryIdentifier.Name, Tgstation.Server.Host.Utils.GitHub.RepositoryIdentifier.Owner, Tgstation.Server.Host.Utils.GitHub.RepositoryIdentifier.RepositoryId, and Tgstation.Server.Api.Models.RepositorySettings.TgsAppPrivateKeyPrefix.
|
staticprivate |
Minutes before tokens expire before not using them.
Definition at line 36 of file GitHubClientFactory.cs.
Referenced by Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GetOrCreateClient().
|
private |
The IAssemblyInformationProvider for the GitHubClientFactory.
Definition at line 46 of file GitHubClientFactory.cs.
Referenced by Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.CreateUnauthenticatedClient(), and Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GitHubClientFactory().
|
private |
Cache of created GitHubClients and last used/expiry times, keyed by access token.
Definition at line 66 of file GitHubClientFactory.cs.
Referenced by Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GetOrCreateClient(), and Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GitHubClientFactory().
|
staticprivate |
Limit to the amount of hours a GitHubClient can live in the clientCache.
Set to app installation token lifetime, which is the lowest. See https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app.
Definition at line 31 of file GitHubClientFactory.cs.
Referenced by Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GetOrCreateClient().
|
private |
The SemaphoreSlim used to guard access to clientCache.
Definition at line 71 of file GitHubClientFactory.cs.
Referenced by Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GetOrCreateClient(), and Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GitHubClientFactory().
|
staticprivate |
The clientCache KeyValuePair<TKey, TValue>.Key used in place of null
when accessing a configuration-based client with no token set in GeneralConfiguration.GitHubAccessToken.
Definition at line 41 of file GitHubClientFactory.cs.
Referenced by Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GetOrCreateClient().
|
private |
The GeneralConfiguration for the GitHubClientFactory.
Definition at line 61 of file GitHubClientFactory.cs.
Referenced by Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GitHubClientFactory().
|
private |
The IHttpMessageHandlerFactory for the GitHubClientFactory.
Definition at line 51 of file GitHubClientFactory.cs.
Referenced by Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.CreateUnauthenticatedClient(), and Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GitHubClientFactory().
|
private |
The ILogger for the GitHubClientFactory.
Definition at line 56 of file GitHubClientFactory.cs.
Referenced by Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.CreateAppClientInternal(), Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GetOrCreateClient(), and Tgstation.Server.Host.Utils.GitHub.GitHubClientFactory.GitHubClientFactory().