From 7cf4e870b2bced7af649d4e6f814306dfb3fdc4d Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Sun, 22 Jul 2018 17:28:22 -0400 Subject: [PATCH] Configuration cleanup --- ...{Configuration.cs => ConfigurationFile.cs} | 4 +-- .../Models/ConfigurationType.cs | 21 +++++++++++++ src/Tgstation.Server.Api/Models/Instance.cs | 9 +++--- .../Internal/ConfigurationFileMetadata.cs | 6 ++-- .../Rights/ConfigurationRights.cs | 2 +- .../Rights/InstanceUserRights.cs | 8 +++++ src/Tgstation.Server.Api/RouteHelper.cs | 24 +++++++-------- .../Components/IConfigurationClient.cs | 30 +++++++++---------- .../Components/Chat/Providers/IrcProvider.cs | 2 -- .../Components/IConfiguration.cs | 4 +-- .../Components/InstanceManager.cs | 6 ++-- .../Controllers/InstanceController.cs | 2 +- src/Tgstation.Server.Host/Models/Instance.cs | 2 +- 13 files changed, 74 insertions(+), 46 deletions(-) rename src/Tgstation.Server.Api/Models/{Configuration.cs => ConfigurationFile.cs} (62%) create mode 100644 src/Tgstation.Server.Api/Models/ConfigurationType.cs diff --git a/src/Tgstation.Server.Api/Models/Configuration.cs b/src/Tgstation.Server.Api/Models/ConfigurationFile.cs similarity index 62% rename from src/Tgstation.Server.Api/Models/Configuration.cs rename to src/Tgstation.Server.Api/Models/ConfigurationFile.cs index 26f99815c9..3b3ca37e59 100644 --- a/src/Tgstation.Server.Api/Models/Configuration.cs +++ b/src/Tgstation.Server.Api/Models/ConfigurationFile.cs @@ -6,11 +6,11 @@ namespace Tgstation.Server.Api.Models /// Represents a static game file. Create and delete actions uncerimonuously overwrite/delete files /// #pragma warning disable CA1724 // System.Configuration name conflict - public sealed class Configuration : ConfigurationFileMetadata + public sealed class ConfigurationFile : ConfigurationFileMetadata #pragma warning restore CA1724 // System.Configuration name conflict { /// - /// The content of the file. Will be if is or during listing operations + /// The content of the . Will be if is or during listing operations /// public byte[] Content { get; set; } } diff --git a/src/Tgstation.Server.Api/Models/ConfigurationType.cs b/src/Tgstation.Server.Api/Models/ConfigurationType.cs new file mode 100644 index 0000000000..d322e79a75 --- /dev/null +++ b/src/Tgstation.Server.Api/Models/ConfigurationType.cs @@ -0,0 +1,21 @@ +namespace Tgstation.Server.Api.Models +{ + /// + /// The type of configuration allowed on an + /// + public enum ConfigurationType + { + /// + /// Configuration editing is not allowed + /// + Disallowed, + /// + /// Configuration editing is allowed by all users on all files + /// + HostWrite, + /// + /// Co + /// + SystemIdentityWrite + } +} diff --git a/src/Tgstation.Server.Api/Models/Instance.cs b/src/Tgstation.Server.Api/Models/Instance.cs index 74910fdf68..66e5238161 100644 --- a/src/Tgstation.Server.Api/Models/Instance.cs +++ b/src/Tgstation.Server.Api/Models/Instance.cs @@ -33,13 +33,14 @@ namespace Tgstation.Server.Api.Models /// If the is online /// [Permissions(WriteRight = InstanceManagerRights.SetOnline)] - public bool Online { get; set; } + public bool? Online { get; set; } /// - /// If can be used on the + /// If can be used on the /// [Permissions(WriteRight = InstanceManagerRights.SetConfiguration)] - public bool ConfigurationAllowed { get; set; } + [Required] + public ConfigurationType? ConfigurationType { get; set; } /// /// The time interval in minutes the repository is automatically pulled and compiles @@ -54,7 +55,7 @@ namespace Tgstation.Server.Api.Models Name = Name, Path = Path, Online = Online, - ConfigurationAllowed = ConfigurationAllowed + ConfigurationType = ConfigurationType }; } } diff --git a/src/Tgstation.Server.Api/Models/Internal/ConfigurationFileMetadata.cs b/src/Tgstation.Server.Api/Models/Internal/ConfigurationFileMetadata.cs index e402872f3d..ea8f30c484 100644 --- a/src/Tgstation.Server.Api/Models/Internal/ConfigurationFileMetadata.cs +++ b/src/Tgstation.Server.Api/Models/Internal/ConfigurationFileMetadata.cs @@ -3,18 +3,18 @@ namespace Tgstation.Server.Api.Models.Internal { /// - /// Metadata about a file + /// Metadata about a file /// [Model(RightsType.Configuration, CanCrud = true, CanList = true, RequiresInstance = true, ReadRight = ConfigurationRights.Read, WriteRight = ConfigurationRights.Write)] public class ConfigurationFileMetadata { /// - /// The path to the file + /// The path to the file /// public string Path { get; set; } /// - /// If read access to the file was denied + /// If read access to the file was denied /// [Permissions(DenyWrite = true)] public bool ReadDenied { get; set; } diff --git a/src/Tgstation.Server.Api/Rights/ConfigurationRights.cs b/src/Tgstation.Server.Api/Rights/ConfigurationRights.cs index 1246644afe..3008353ffa 100644 --- a/src/Tgstation.Server.Api/Rights/ConfigurationRights.cs +++ b/src/Tgstation.Server.Api/Rights/ConfigurationRights.cs @@ -3,7 +3,7 @@ namespace Tgstation.Server.Api.Rights { /// - /// Rights for + /// Rights for /// [Flags] public enum ConfigurationRights diff --git a/src/Tgstation.Server.Api/Rights/InstanceUserRights.cs b/src/Tgstation.Server.Api/Rights/InstanceUserRights.cs index 26ac4d26ab..7c4e7586f8 100644 --- a/src/Tgstation.Server.Api/Rights/InstanceUserRights.cs +++ b/src/Tgstation.Server.Api/Rights/InstanceUserRights.cs @@ -20,5 +20,13 @@ namespace Tgstation.Server.Api.Rights /// Allow write access to for the /// WriteUsers = 2, + /// + /// User can read configuration files if the instance allows it + /// + ReadConfiguration = 4, + /// + /// Users can write configuration files if the instance allows it + /// + EditConfiguration = 8, } } diff --git a/src/Tgstation.Server.Api/RouteHelper.cs b/src/Tgstation.Server.Api/RouteHelper.cs index 82592c0654..cfe67e00cd 100644 --- a/src/Tgstation.Server.Api/RouteHelper.cs +++ b/src/Tgstation.Server.Api/RouteHelper.cs @@ -114,18 +114,18 @@ namespace Tgstation.Server.Api public static Route ServerVersion() => new Route { Path = "/", Method = HttpMethod.Get }; /// - /// Get the to read a file + /// Get the to read a file /// - /// The the file resides in - /// The path to the file in the directory + /// The the file resides in + /// The path to the file in the directory /// A to the read action public static Route ReadFile(Instance instance, string path) => new Route { Path = String.Concat("/Configuration/", instance?.Id ?? throw new ArgumentNullException(nameof(instance)), '/', path?.TrimStart('/') ?? throw new ArgumentNullException(nameof(path))), Method = HttpMethod.Get }; /// - /// Get the to list files for a + /// Get the to list files for a /// - /// The the file resides in - /// The directory to list + /// The the file resides in + /// The directory to list /// A to the read action public static Route ListFiles(Instance instance, string directory) { @@ -135,10 +135,10 @@ namespace Tgstation.Server.Api } /// - /// Get the to create a file + /// Get the to create a file /// - /// The the file resides in - /// The path to the file in the directory + /// The the file resides in + /// The path to the file in the directory /// A to the create action public static Route CreateFile(Instance instance, string path) { @@ -148,10 +148,10 @@ namespace Tgstation.Server.Api } /// - /// Get the to delete a file + /// Get the to delete a file /// - /// The the file resides in - /// The path to the file in the directory + /// The the file resides in + /// The path to the file in the directory /// A to the delete action public static Route DeleteFile(Instance instance, string path) { diff --git a/src/Tgstation.Server.Client/Components/IConfigurationClient.cs b/src/Tgstation.Server.Client/Components/IConfigurationClient.cs index 7f7d05a477..af84c1ca73 100644 --- a/src/Tgstation.Server.Client/Components/IConfigurationClient.cs +++ b/src/Tgstation.Server.Client/Components/IConfigurationClient.cs @@ -8,7 +8,7 @@ using Tgstation.Server.Api.Rights; namespace Tgstation.Server.Client.Components { /// - /// For managing files + /// For managing files /// public interface IConfigurationClient : IRightsClient { @@ -17,39 +17,39 @@ namespace Tgstation.Server.Client.Components /// /// The path to the directory to list files in /// The for the operation - /// A of s in the - Task> List(string directory, CancellationToken cancellationToken); + /// A of s in the + Task> List(string directory, CancellationToken cancellationToken); /// - /// Read a file + /// Read a file /// - /// The file to read + /// The file to read /// The for the operation /// A representing the running operation - Task Read(Configuration file, CancellationToken cancellationToken); + Task Read(ConfigurationFile file, CancellationToken cancellationToken); /// - /// Overwrite a file with integrity checks + /// Overwrite a file with integrity checks /// - /// The file to write + /// The file to write /// The for the operation /// A representing the running operation - Task Write(Configuration file, CancellationToken cancellationToken); + Task Write(ConfigurationFile file, CancellationToken cancellationToken); /// - /// Create/overwrite a file + /// Create/overwrite a file /// - /// The file to write + /// The file to write /// The for the operation /// A representing the running operation - Task Create(Configuration file, CancellationToken cancellationToken); + Task Create(ConfigurationFile file, CancellationToken cancellationToken); /// - /// Delete a file + /// Delete a file /// - /// The file to delete + /// The file to delete /// The for the operation /// A representing the running operation - Task Delete(Configuration file, CancellationToken cancellationToken); + Task Delete(ConfigurationFile file, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs index 01e1a6964f..44966939e3 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs @@ -314,8 +314,6 @@ namespace Tgstation.Server.Host.Components.Chat.Providers foreach (var I in hs) client.RfcJoin(I); - - return (IReadOnlyList)channels.Select(x => { ulong id = channelIdCounter; if (!channelIdMap.Any(y => diff --git a/src/Tgstation.Server.Host/Components/IConfiguration.cs b/src/Tgstation.Server.Host/Components/IConfiguration.cs index da32288f4d..4d0e88e7a9 100644 --- a/src/Tgstation.Server.Host/Components/IConfiguration.cs +++ b/src/Tgstation.Server.Host/Components/IConfiguration.cs @@ -42,8 +42,8 @@ namespace Tgstation.Server.Host.Components /// The relative path in the Configuration directory /// The for the operation. If , the operation will be performed as the user of the /// The for the operation - /// A resulting in the of the file - Task Read(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken); + /// A resulting in the of the file + Task Read(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken); /// /// Writes to a given diff --git a/src/Tgstation.Server.Host/Components/InstanceManager.cs b/src/Tgstation.Server.Host/Components/InstanceManager.cs index 24dd107c18..1d49f58fa6 100644 --- a/src/Tgstation.Server.Host/Components/InstanceManager.cs +++ b/src/Tgstation.Server.Host/Components/InstanceManager.cs @@ -74,7 +74,7 @@ namespace Tgstation.Server.Host.Components { if (newPath == null) throw new ArgumentNullException(nameof(newPath)); - if (instance.Online) + if (instance.Online.Value) await OfflineInstance(instance, cancellationToken).ConfigureAwait(false); Task instanceOnlineTask = null; try @@ -87,7 +87,7 @@ namespace Tgstation.Server.Host.Components } finally { - if (instance.Online) + if (instance.Online.Value) if (instanceOnlineTask == null) await OnlineInstance(instance, default).ConfigureAwait(false); else @@ -129,7 +129,7 @@ namespace Tgstation.Server.Host.Components public Task StartAsync(CancellationToken cancellationToken) => databaseContextFactory.UseContext(async databaseContext => { await databaseContext.Initialize(cancellationToken).ConfigureAwait(false); - var dbInstances = databaseContext.Instances.Where(x => x.Online).Include(x => x.RepositorySettings).Include(x => x.ChatSettings).Include(x => x.DreamDaemonSettings).ToAsyncEnumerable(); + var dbInstances = databaseContext.Instances.Where(x => x.Online.Value).Include(x => x.RepositorySettings).Include(x => x.ChatSettings).Include(x => x.DreamDaemonSettings).ToAsyncEnumerable(); var tasks = new List(); await dbInstances.ForEachAsync(metadata => tasks.Add(OnlineInstance(metadata, cancellationToken)), cancellationToken).ConfigureAwait(false); await Task.WhenAll(tasks).ConfigureAwait(false); diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index fb18f46897..95e59d61f8 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -59,7 +59,7 @@ namespace Tgstation.Server.Host.Controllers var newInstance = new Models.Instance { ChatSettings = new ChatSettings(), - ConfigurationAllowed = model.ConfigurationAllowed, + ConfigurationType = model.ConfigurationType, DreamDaemonSettings = new DreamDaemonSettings(), DreamMakerSettings = new DreamMakerSettings(), Name = model.Name, diff --git a/src/Tgstation.Server.Host/Models/Instance.cs b/src/Tgstation.Server.Host/Models/Instance.cs index 290417b1fe..4b6b57762c 100644 --- a/src/Tgstation.Server.Host/Models/Instance.cs +++ b/src/Tgstation.Server.Host/Models/Instance.cs @@ -57,7 +57,7 @@ namespace Tgstation.Server.Host.Models public Api.Models.Instance ToApi() => new Api.Models.Instance { AutoUpdateInterval = AutoUpdateInterval, - ConfigurationAllowed = ConfigurationAllowed, + ConfigurationType = ConfigurationType, Id = Id, Name = Name, Path = Path,