2using System.Globalization;
4using Microsoft.Extensions.Logging;
33 protected ILogger<AuthorityBase>
Logger {
get; }
106 ILogger<AuthorityBase> logger)
108 AuthenticationContext = authenticationContext ??
throw new ArgumentNullException(nameof(authenticationContext));
109 DatabaseContext = databaseContext ??
throw new ArgumentNullException(nameof(databaseContext));
110 Logger = logger ??
throw new ArgumentNullException(nameof(logger));
121 Logger.LogWarning(rateLimitException,
"Exceeded GitHub rate limit!");
122 var secondsString = Math.Ceiling(rateLimitException.GetRetryAfterTimeSpan().TotalSeconds).ToString(CultureInfo.InvariantCulture);
126 AdditionalData = $
"Retry-After: {secondsString}s",
Represents an error message returned by the server.
Base implementation of IAuthority.
static AuthorityResponse< TResult > Forbid< TResult >()
Generates a HttpFailureResponse.Forbidden type AuthorityResponse<TResult>.
static AuthorityResponse< TResult > Gone< TResult >()
Generates a HttpFailureResponse.Forbidden type AuthorityResponse<TResult>.
static AuthorityResponse< TResult > NotFound< TResult >()
Generates a HttpFailureResponse.NotFound type AuthorityResponse<TResult>.
static AuthorityResponse< TResult > Unauthorized< TResult >()
Generates a HttpFailureResponse.Unauthorized type AuthorityResponse<TResult>.
AuthorityResponse< TResult > RateLimit< TResult >(RateLimitExceededException rateLimitException)
Generates a HttpFailureResponse.RateLimited type AuthorityResponse.
ILogger< AuthorityBase > Logger
Gets the ILogger for the AuthorityBase.
AuthorityBase(IAuthenticationContext authenticationContext, IDatabaseContext databaseContext, ILogger< AuthorityBase > logger)
Initializes a new instance of the AuthorityBase class.
static AuthorityResponse< TResult > Conflict< TResult >(ErrorCode errorCode)
Generates a HttpFailureResponse.Conflict type AuthorityResponse<TResult>.
static AuthorityResponse< TResult > BadRequest< TResult >(ErrorCode errorCode)
Generates a HttpFailureResponse.BadRequest type AuthorityResponse<TResult>.
Represents a response from an authority.
Backend abstract implementation of IDatabaseContext.
Business logic for interating with the server.
For creating and accessing authentication contexts.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
HttpFailureResponse
Indicates the type of HTTP status code an failing AuthorityResponse should generate.