|
|
|
@ -9,6 +9,7 @@ using Microsoft.AspNetCore.HttpOverrides;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
|
using NLog.Extensions.Logging;
|
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
|
using NzbDrone.Common.Instrumentation;
|
|
|
|
@ -91,6 +92,73 @@ namespace NzbDrone.Host
|
|
|
|
|
})
|
|
|
|
|
.AddControllersAsServices();
|
|
|
|
|
|
|
|
|
|
services.AddSwaggerGen(c =>
|
|
|
|
|
{
|
|
|
|
|
c.SwaggerDoc("v3", new OpenApiInfo
|
|
|
|
|
{
|
|
|
|
|
Version = "3.0.0",
|
|
|
|
|
Title = "Sonarr",
|
|
|
|
|
Description = "Sonarr API docs",
|
|
|
|
|
License = new OpenApiLicense
|
|
|
|
|
{
|
|
|
|
|
Name = "GPL-3.0",
|
|
|
|
|
Url = new Uri("https://github.com/Sonarr/Sonarr/blob/develop/LICENSE")
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var apiKeyHeader = new OpenApiSecurityScheme
|
|
|
|
|
{
|
|
|
|
|
Name = "X-Api-Key",
|
|
|
|
|
Type = SecuritySchemeType.ApiKey,
|
|
|
|
|
Scheme = "apiKey",
|
|
|
|
|
Description = "Apikey passed as header",
|
|
|
|
|
In = ParameterLocation.Header,
|
|
|
|
|
Reference = new OpenApiReference
|
|
|
|
|
{
|
|
|
|
|
Type = ReferenceType.SecurityScheme,
|
|
|
|
|
Id = "X-Api-Key"
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
c.AddSecurityDefinition("X-Api-Key", apiKeyHeader);
|
|
|
|
|
|
|
|
|
|
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
|
|
|
|
{
|
|
|
|
|
{ apiKeyHeader, new string[] { } }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var apikeyQuery = new OpenApiSecurityScheme
|
|
|
|
|
{
|
|
|
|
|
Name = "apikey",
|
|
|
|
|
Type = SecuritySchemeType.ApiKey,
|
|
|
|
|
Scheme = "apiKey",
|
|
|
|
|
Description = "Apikey passed as header",
|
|
|
|
|
In = ParameterLocation.Query,
|
|
|
|
|
Reference = new OpenApiReference
|
|
|
|
|
{
|
|
|
|
|
Type = ReferenceType.SecurityScheme,
|
|
|
|
|
Id = "apikey"
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
c.AddServer(new OpenApiServer
|
|
|
|
|
{
|
|
|
|
|
Url = "{protocol}://{hostpath}",
|
|
|
|
|
Variables = new Dictionary<string, OpenApiServerVariable>
|
|
|
|
|
{
|
|
|
|
|
{ "protocol", new OpenApiServerVariable { Default = "http", Enum = new List<string> { "http", "https" } } },
|
|
|
|
|
{ "hostpath", new OpenApiServerVariable { Default = "localhost:8989" } }
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
c.AddSecurityDefinition("apikey", apikeyQuery);
|
|
|
|
|
|
|
|
|
|
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
|
|
|
|
{
|
|
|
|
|
{ apikeyQuery, new string[] { } }
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
services
|
|
|
|
|
.AddSignalR()
|
|
|
|
|
.AddJsonProtocol(options =>
|
|
|
|
@ -184,6 +252,15 @@ namespace NzbDrone.Host
|
|
|
|
|
|
|
|
|
|
app.UseWebSockets();
|
|
|
|
|
|
|
|
|
|
// Enable middleware to serve generated Swagger as a JSON endpoint.
|
|
|
|
|
if (BuildInfo.IsDebug)
|
|
|
|
|
{
|
|
|
|
|
app.UseSwagger(c =>
|
|
|
|
|
{
|
|
|
|
|
c.RouteTemplate = "docs/{documentName}/openapi.json";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseEndpoints(x =>
|
|
|
|
|
{
|
|
|
|
|
x.MapHub<MessageHub>("/signalr/messages").RequireAuthorization("SignalR");
|
|
|
|
|