Add endpoint for upgrade checks (#17026)
* Fix upgrade check repo, so it's able to check more than once :) * Add VersionCheckPeriod to server configuration output * Add upgrade check endpoint * Obsolete unused response model * Update OpenAPI JSON
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Umbraco.Cms.Api.Management.ViewModels.Server;
|
using Umbraco.Cms.Api.Management.ViewModels.Server;
|
||||||
using Umbraco.Cms.Core.Configuration.Models;
|
using Umbraco.Cms.Core.Configuration.Models;
|
||||||
|
using Umbraco.Cms.Core.DependencyInjection;
|
||||||
|
|
||||||
namespace Umbraco.Cms.Api.Management.Controllers.Server;
|
namespace Umbraco.Cms.Api.Management.Controllers.Server;
|
||||||
|
|
||||||
@@ -11,8 +13,20 @@ namespace Umbraco.Cms.Api.Management.Controllers.Server;
|
|||||||
public class ConfigurationServerController : ServerControllerBase
|
public class ConfigurationServerController : ServerControllerBase
|
||||||
{
|
{
|
||||||
private readonly SecuritySettings _securitySettings;
|
private readonly SecuritySettings _securitySettings;
|
||||||
|
private readonly GlobalSettings _globalSettings;
|
||||||
|
|
||||||
public ConfigurationServerController(IOptions<SecuritySettings> securitySettings) => _securitySettings = securitySettings.Value;
|
[Obsolete("Use the constructor that accepts all arguments. Will be removed in V16.")]
|
||||||
|
public ConfigurationServerController(IOptions<SecuritySettings> securitySettings)
|
||||||
|
: this(securitySettings, StaticServiceProvider.Instance.GetRequiredService<IOptions<GlobalSettings>>())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[ActivatorUtilitiesConstructor]
|
||||||
|
public ConfigurationServerController(IOptions<SecuritySettings> securitySettings, IOptions<GlobalSettings> globalSettings)
|
||||||
|
{
|
||||||
|
_securitySettings = securitySettings.Value;
|
||||||
|
_globalSettings = globalSettings.Value;
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("configuration")]
|
[HttpGet("configuration")]
|
||||||
[MapToApiVersion("1.0")]
|
[MapToApiVersion("1.0")]
|
||||||
@@ -22,6 +36,7 @@ public class ConfigurationServerController : ServerControllerBase
|
|||||||
var responseModel = new ServerConfigurationResponseModel
|
var responseModel = new ServerConfigurationResponseModel
|
||||||
{
|
{
|
||||||
AllowPasswordReset = _securitySettings.AllowPasswordReset,
|
AllowPasswordReset = _securitySettings.AllowPasswordReset,
|
||||||
|
VersionCheckPeriod = _globalSettings.VersionCheckPeriod
|
||||||
};
|
};
|
||||||
|
|
||||||
return Task.FromResult<IActionResult>(Ok(responseModel));
|
return Task.FromResult<IActionResult>(Ok(responseModel));
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Umbraco.Cms.Api.Management.ViewModels.Server;
|
||||||
|
using Umbraco.Cms.Core;
|
||||||
|
using Umbraco.Cms.Core.Configuration;
|
||||||
|
using Umbraco.Cms.Core.Services;
|
||||||
|
using Umbraco.Cms.Web.Common.Authorization;
|
||||||
|
using Umbraco.Extensions;
|
||||||
|
|
||||||
|
namespace Umbraco.Cms.Api.Management.Controllers.Server;
|
||||||
|
|
||||||
|
[ApiVersion("1.0")]
|
||||||
|
[Authorize(Policy = AuthorizationPolicies.RequireAdminAccess)]
|
||||||
|
public class UpgradeCheckServerController : ServerControllerBase
|
||||||
|
{
|
||||||
|
private readonly IUpgradeService _upgradeService;
|
||||||
|
private readonly IUmbracoVersion _umbracoVersion;
|
||||||
|
|
||||||
|
public UpgradeCheckServerController(IUpgradeService upgradeService, IUmbracoVersion umbracoVersion)
|
||||||
|
{
|
||||||
|
_upgradeService = upgradeService;
|
||||||
|
_umbracoVersion = umbracoVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("upgrade-check")]
|
||||||
|
[MapToApiVersion("1.0")]
|
||||||
|
[ProducesResponseType(typeof(UpgradeCheckResponseModel), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> UpgradeCheck(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
UpgradeResult upgradeResult = await _upgradeService.CheckUpgrade(_umbracoVersion.SemanticVersion);
|
||||||
|
|
||||||
|
var responseModel = new UpgradeCheckResponseModel
|
||||||
|
{
|
||||||
|
Type = upgradeResult.UpgradeType,
|
||||||
|
Comment = upgradeResult.Comment,
|
||||||
|
Url = upgradeResult.UpgradeUrl.IsNullOrWhiteSpace()
|
||||||
|
? string.Empty
|
||||||
|
: $"{upgradeResult.UpgradeUrl}?version={_umbracoVersion.Version.ToString(3)}"
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(responseModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25176,6 +25176,41 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/umbraco/management/api/v1/server/upgrade-check": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"Server"
|
||||||
|
],
|
||||||
|
"operationId": "GetServerUpgradeCheck",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/UpgradeCheckResponseModel"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "The resource is protected and requires an authentication token"
|
||||||
|
},
|
||||||
|
"403": {
|
||||||
|
"description": "The authenticated user do not have access to this resource"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Backoffice User": [ ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"/umbraco/management/api/v1/item/static-file": {
|
"/umbraco/management/api/v1/item/static-file": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
@@ -42446,12 +42481,17 @@
|
|||||||
},
|
},
|
||||||
"ServerConfigurationResponseModel": {
|
"ServerConfigurationResponseModel": {
|
||||||
"required": [
|
"required": [
|
||||||
"allowPasswordReset"
|
"allowPasswordReset",
|
||||||
|
"versionCheckPeriod"
|
||||||
],
|
],
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"allowPasswordReset": {
|
"allowPasswordReset": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"versionCheckPeriod": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
@@ -44514,6 +44554,26 @@
|
|||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
},
|
},
|
||||||
|
"UpgradeCheckResponseModel": {
|
||||||
|
"required": [
|
||||||
|
"comment",
|
||||||
|
"type",
|
||||||
|
"url"
|
||||||
|
],
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"comment": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
"UpgradeSettingsResponseModel": {
|
"UpgradeSettingsResponseModel": {
|
||||||
"required": [
|
"required": [
|
||||||
"currentState",
|
"currentState",
|
||||||
@@ -45275,4 +45335,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,6 @@
|
|||||||
public class ServerConfigurationResponseModel
|
public class ServerConfigurationResponseModel
|
||||||
{
|
{
|
||||||
public bool AllowPasswordReset { get; set; }
|
public bool AllowPasswordReset { get; set; }
|
||||||
|
|
||||||
|
public int VersionCheckPeriod { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Umbraco.Cms.Api.Management.ViewModels.Server;
|
||||||
|
|
||||||
|
public class UpgradeCheckResponseModel
|
||||||
|
{
|
||||||
|
public required string Type { get; init; }
|
||||||
|
|
||||||
|
public required string Comment { get; init; }
|
||||||
|
|
||||||
|
public required string Url { get; init; }
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Umbraco.Cms.Api.Management.ViewModels.Server;
|
namespace Umbraco.Cms.Api.Management.ViewModels.Server;
|
||||||
|
|
||||||
|
[Obsolete("Not used. Will be removed in V15.")]
|
||||||
public class VersionResponseModel
|
public class VersionResponseModel
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
|
|||||||
@@ -16,14 +16,10 @@ public class UpgradeCheckRepository : IUpgradeCheckRepository
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_httpClient == null)
|
_httpClient ??= new HttpClient { Timeout = TimeSpan.FromSeconds(1) };
|
||||||
{
|
|
||||||
_httpClient = new HttpClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
using var content = new StringContent(_jsonSerializer.Serialize(new CheckUpgradeDto(version)), Encoding.UTF8, "application/json");
|
using var content = new StringContent(_jsonSerializer.Serialize(new CheckUpgradeDto(version)), Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
_httpClient.Timeout = TimeSpan.FromSeconds(1);
|
|
||||||
using HttpResponseMessage task = await _httpClient.PostAsync(RestApiUpgradeChecklUrl, content);
|
using HttpResponseMessage task = await _httpClient.PostAsync(RestApiUpgradeChecklUrl, content);
|
||||||
var json = await task.Content.ReadAsStringAsync();
|
var json = await task.Content.ReadAsStringAsync();
|
||||||
UpgradeResult? result = _jsonSerializer.Deserialize<UpgradeResult>(json);
|
UpgradeResult? result = _jsonSerializer.Deserialize<UpgradeResult>(json);
|
||||||
|
|||||||
Reference in New Issue
Block a user