From b75422f1ca28deb6a1f0d5ad3b941d0c0c62094b Mon Sep 17 00:00:00 2001 From: Eric Dugre Date: Wed, 9 Aug 2023 17:12:35 -0400 Subject: [PATCH] migrate "Disable enabled Web farm servers" (#212) --- .../KenticoInspector.Actions.csproj | 9 +++ .../WebFarmServerSummary/Action.cs | 78 +++++++++++++++++++ .../WebFarmServerSummary/Metadata/en-US.yaml | 12 +++ .../WebFarmServerSummary/Models/Options.cs | 7 ++ .../Models/Results/WebFarmServer.cs | 11 +++ .../WebFarmServerSummary/Models/Terms.cs | 15 ++++ .../WebFarmServerSummary/Scripts.cs | 11 +++ .../Scripts/DisableServer.sql | 2 + .../Scripts/GetWebFarmServerSummary.sql | 3 + KenticoInspector.Core/Constants/ActionTags.cs | 1 + 10 files changed, 149 insertions(+) create mode 100644 KenticoInspector.Actions/WebFarmServerSummary/Action.cs create mode 100644 KenticoInspector.Actions/WebFarmServerSummary/Metadata/en-US.yaml create mode 100644 KenticoInspector.Actions/WebFarmServerSummary/Models/Options.cs create mode 100644 KenticoInspector.Actions/WebFarmServerSummary/Models/Results/WebFarmServer.cs create mode 100644 KenticoInspector.Actions/WebFarmServerSummary/Models/Terms.cs create mode 100644 KenticoInspector.Actions/WebFarmServerSummary/Scripts.cs create mode 100644 KenticoInspector.Actions/WebFarmServerSummary/Scripts/DisableServer.sql create mode 100644 KenticoInspector.Actions/WebFarmServerSummary/Scripts/GetWebFarmServerSummary.sql diff --git a/KenticoInspector.Actions/KenticoInspector.Actions.csproj b/KenticoInspector.Actions/KenticoInspector.Actions.csproj index ebc9bd89..2af820d1 100644 --- a/KenticoInspector.Actions/KenticoInspector.Actions.csproj +++ b/KenticoInspector.Actions/KenticoInspector.Actions.csproj @@ -31,6 +31,15 @@ Always + + Always + + + Always + + + Always + diff --git a/KenticoInspector.Actions/WebFarmServerSummary/Action.cs b/KenticoInspector.Actions/WebFarmServerSummary/Action.cs new file mode 100644 index 00000000..300a0ef9 --- /dev/null +++ b/KenticoInspector.Actions/WebFarmServerSummary/Action.cs @@ -0,0 +1,78 @@ +using KenticoInspector.Actions.WebFarmServerSummary.Models; +using KenticoInspector.Core; +using KenticoInspector.Core.Constants; +using KenticoInspector.Core.Helpers; +using KenticoInspector.Core.Models; +using KenticoInspector.Core.Services.Interfaces; + +using System; +using System.Collections.Generic; + +namespace KenticoInspector.Actions.WebFarmServerSummary +{ + public class Action : AbstractAction + { + private readonly IDatabaseService databaseService; + + public override IList CompatibleVersions => VersionHelper.GetVersionList("12", "13"); + + public override IList Tags => new List { + ActionTags.Configuration + }; + + public Action(IDatabaseService databaseService, IModuleMetadataService moduleMetadataService) : base(moduleMetadataService) + { + this.databaseService = databaseService; + } + + public override ActionResults Execute(Options options) + { + // No server provided, list servers + if (options.ServerID == 0) + { + return GetListingResult(); + } + + if (options.ServerID < 0) + { + return GetInvalidOptionsResult(); + } + + // Disable provided server + databaseService.ExecuteSqlFromFileGeneric(Scripts.DisableServer, new { ServerID = options.ServerID }); + var result = GetListingResult(); + result.Summary = Metadata.Terms.ServerDisabled.With(new + { + serverId = options.ServerID + }); + + return result; + } + + public override ActionResults GetInvalidOptionsResult() + { + return new ActionResults { + Status = ResultsStatus.Error, + Summary = Metadata.Terms.InvalidOptions + }; + } + + private ActionResults GetListingResult() + { + var servers = databaseService.ExecuteSqlFromFile(Scripts.GetWebFarmServerSummary); + var data = new TableResult() + { + Name = Metadata.Terms.TableTitle, + Rows = servers + }; + + return new ActionResults + { + Type = ResultsType.Table, + Status = ResultsStatus.Information, + Summary = Metadata.Terms.ListSummary, + Data = data + }; + } + } +} diff --git a/KenticoInspector.Actions/WebFarmServerSummary/Metadata/en-US.yaml b/KenticoInspector.Actions/WebFarmServerSummary/Metadata/en-US.yaml new file mode 100644 index 00000000..242ed5b4 --- /dev/null +++ b/KenticoInspector.Actions/WebFarmServerSummary/Metadata/en-US.yaml @@ -0,0 +1,12 @@ +details: + name: Web Farm Server Summary + shortDescription: Review and disable web farm servers. + longDescription: | + Displays all web farm servers, and allows you to disable them. + + Run the action without options to view the web farm server. To disable a server, re-run the action with the server ID below. Servers disabled by this action have the *.disabled* prefix applied to their name, so you can identify which servers were disabled by this action and which were disabled manually. +terms: + tableTitle: Web farm servers + invalidOptions: The server ID must be an integer greater than zero. + listSummary: Set the server ID you wish to disable and re-run + serverDisabled: Server ID was disabled \ No newline at end of file diff --git a/KenticoInspector.Actions/WebFarmServerSummary/Models/Options.cs b/KenticoInspector.Actions/WebFarmServerSummary/Models/Options.cs new file mode 100644 index 00000000..e503b37e --- /dev/null +++ b/KenticoInspector.Actions/WebFarmServerSummary/Models/Options.cs @@ -0,0 +1,7 @@ +namespace KenticoInspector.Actions.WebFarmServerSummary.Models +{ + public class Options + { + public int ServerID { get; set; } + } +} diff --git a/KenticoInspector.Actions/WebFarmServerSummary/Models/Results/WebFarmServer.cs b/KenticoInspector.Actions/WebFarmServerSummary/Models/Results/WebFarmServer.cs new file mode 100644 index 00000000..d842c8e8 --- /dev/null +++ b/KenticoInspector.Actions/WebFarmServerSummary/Models/Results/WebFarmServer.cs @@ -0,0 +1,11 @@ +namespace KenticoInspector.Actions.WebFarmServerSummary.Models +{ + public class WebFarmServer + { + public int ID { get; internal set; } + + public string Name { get; internal set; } + + public string Enabled { get; internal set; } + } +} diff --git a/KenticoInspector.Actions/WebFarmServerSummary/Models/Terms.cs b/KenticoInspector.Actions/WebFarmServerSummary/Models/Terms.cs new file mode 100644 index 00000000..a0fb64a5 --- /dev/null +++ b/KenticoInspector.Actions/WebFarmServerSummary/Models/Terms.cs @@ -0,0 +1,15 @@ +using KenticoInspector.Core.Models; + +namespace KenticoInspector.Actions.WebFarmServerSummary.Models +{ + public class Terms + { + public Term InvalidOptions { get; internal set; } + + public Term TableTitle { get; internal set; } + + public Term ListSummary { get; internal set; } + + public Term ServerDisabled { get; internal set; } + } +} diff --git a/KenticoInspector.Actions/WebFarmServerSummary/Scripts.cs b/KenticoInspector.Actions/WebFarmServerSummary/Scripts.cs new file mode 100644 index 00000000..66af370f --- /dev/null +++ b/KenticoInspector.Actions/WebFarmServerSummary/Scripts.cs @@ -0,0 +1,11 @@ +namespace KenticoInspector.Actions.WebFarmServerSummary +{ + public static class Scripts + { + public static string BaseDirectory => $"{nameof(WebFarmServerSummary)}/Scripts"; + + public static string GetWebFarmServerSummary => $"{BaseDirectory}/{nameof(GetWebFarmServerSummary)}.sql"; + + public static string DisableServer => $"{BaseDirectory}/{nameof(DisableServer)}.sql"; + } +} diff --git a/KenticoInspector.Actions/WebFarmServerSummary/Scripts/DisableServer.sql b/KenticoInspector.Actions/WebFarmServerSummary/Scripts/DisableServer.sql new file mode 100644 index 00000000..e44ac945 --- /dev/null +++ b/KenticoInspector.Actions/WebFarmServerSummary/Scripts/DisableServer.sql @@ -0,0 +1,2 @@ +UPDATE CMS_WebFarmServer SET ServerDisplayName = ServerDisplayName + N'.disabled', ServerEnabled = 0 +WHERE ServerID = @ServerID \ No newline at end of file diff --git a/KenticoInspector.Actions/WebFarmServerSummary/Scripts/GetWebFarmServerSummary.sql b/KenticoInspector.Actions/WebFarmServerSummary/Scripts/GetWebFarmServerSummary.sql new file mode 100644 index 00000000..407cae6a --- /dev/null +++ b/KenticoInspector.Actions/WebFarmServerSummary/Scripts/GetWebFarmServerSummary.sql @@ -0,0 +1,3 @@ +SELECT ServerID AS 'ID', ServerName AS 'Name', + CASE WHEN ServerEnabled = 1 THEN 'true' ELSE 'false' END AS 'Enabled' +FROM CMS_WebFarmServer \ No newline at end of file diff --git a/KenticoInspector.Core/Constants/ActionTags.cs b/KenticoInspector.Core/Constants/ActionTags.cs index 77c3d251..506e08e0 100644 --- a/KenticoInspector.Core/Constants/ActionTags.cs +++ b/KenticoInspector.Core/Constants/ActionTags.cs @@ -5,6 +5,7 @@ public static class ActionTags public const string Reset = "Reset"; public const string User = "User"; public const string Site = "Site"; + public const string Configuration = "Configuration"; } } \ No newline at end of file