From 74c81a00a9de6a4e5f7a5711be41b9f306516203 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 13 Aug 2018 18:38:47 -0400 Subject: [PATCH] ConfigurationClient --- src/Tgstation.Server.Api/Routes.cs | 5 ++ .../Components/ByondClient.cs | 9 ++-- .../Components/ConfigurationClient.cs | 52 +++++++++++++++++++ .../Components/DreamDaemonClient.cs | 9 ++-- .../Components/InstanceClient.cs | 3 +- .../Controllers/ConfigurationController.cs | 3 +- 6 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 src/Tgstation.Server.Client/Components/ConfigurationClient.cs diff --git a/src/Tgstation.Server.Api/Routes.cs b/src/Tgstation.Server.Api/Routes.cs index b6b023a8e1..1d185b9610 100644 --- a/src/Tgstation.Server.Api/Routes.cs +++ b/src/Tgstation.Server.Api/Routes.cs @@ -43,6 +43,11 @@ namespace Tgstation.Server.Api /// public const string DreamDaemon = Root + nameof(Models.DreamDaemon); + /// + /// The controller + /// + public const string Configuration = Root + "Config"; + /// /// Apply an postfix to a /// diff --git a/src/Tgstation.Server.Client/Components/ByondClient.cs b/src/Tgstation.Server.Client/Components/ByondClient.cs index e066407afe..ec311873c7 100644 --- a/src/Tgstation.Server.Client/Components/ByondClient.cs +++ b/src/Tgstation.Server.Client/Components/ByondClient.cs @@ -1,4 +1,5 @@ -using System.Threading; +using System; +using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api; using Tgstation.Server.Api.Models; @@ -21,11 +22,11 @@ namespace Tgstation.Server.Client.Components /// Construct a /// /// The value of - /// + /// The value of public ByondClient(IApiClient apiClient, Instance instance) { - this.apiClient = apiClient; - this.instance = instance; + this.apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient)); + this.instance = instance ?? throw new ArgumentNullException(nameof(instance)); } /// diff --git a/src/Tgstation.Server.Client/Components/ConfigurationClient.cs b/src/Tgstation.Server.Client/Components/ConfigurationClient.cs new file mode 100644 index 0000000000..6eac9582bc --- /dev/null +++ b/src/Tgstation.Server.Client/Components/ConfigurationClient.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Tgstation.Server.Api; +using Tgstation.Server.Api.Models; + +namespace Tgstation.Server.Client.Components +{ + /// + sealed class ConfigurationClient : IConfigurationClient + { + /// + /// The for the + /// + readonly IApiClient apiClient; + /// + /// The for the + /// + readonly Instance instance; + + /// + /// Construct a + /// + /// The value of + /// The value of + public ConfigurationClient(IApiClient apiClient, Instance instance) + { + this.apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient)); + this.instance = instance ?? throw new ArgumentNullException(nameof(instance)); + } + + /// + public Task> List(string directory, CancellationToken cancellationToken) + { + if (directory == null) + directory = String.Empty; + return apiClient.Read>(Routes.List(Routes.Configuration) + directory, instance.Id, cancellationToken); + } + + /// + public Task Read(ConfigurationFile file, CancellationToken cancellationToken) + { + if (file == null) + throw new ArgumentNullException(nameof(file)); + return apiClient.Read(Routes.Configuration + file.Path, instance.Id, cancellationToken); + } + + /// + public Task Write(ConfigurationFile file, CancellationToken cancellationToken) => apiClient.Update(Routes.Configuration, file, instance.Id, cancellationToken); + } +} \ No newline at end of file diff --git a/src/Tgstation.Server.Client/Components/DreamDaemonClient.cs b/src/Tgstation.Server.Client/Components/DreamDaemonClient.cs index ed2a51d013..810590d809 100644 --- a/src/Tgstation.Server.Client/Components/DreamDaemonClient.cs +++ b/src/Tgstation.Server.Client/Components/DreamDaemonClient.cs @@ -1,4 +1,5 @@ -using System.Threading; +using System; +using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api; using Tgstation.Server.Api.Models; @@ -21,11 +22,11 @@ namespace Tgstation.Server.Client.Components /// Construct a /// /// The value of - /// + /// The value of public DreamDaemonClient(IApiClient apiClient, Instance instance) { - this.apiClient = apiClient; - this.instance = instance; + this.apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient)); + this.instance = instance ?? throw new ArgumentNullException(nameof(instance)); } /// diff --git a/src/Tgstation.Server.Client/Components/InstanceClient.cs b/src/Tgstation.Server.Client/Components/InstanceClient.cs index 90d25ed881..65f0bf9056 100644 --- a/src/Tgstation.Server.Client/Components/InstanceClient.cs +++ b/src/Tgstation.Server.Client/Components/InstanceClient.cs @@ -19,7 +19,7 @@ namespace Tgstation.Server.Client.Components public IDreamDaemonClient DreamDaemon { get; } /// - public IConfigurationClient Configuration => throw new NotImplementedException(); + public IConfigurationClient Configuration { get; } /// public IInstanceUserClient Users => throw new NotImplementedException(); @@ -51,6 +51,7 @@ namespace Tgstation.Server.Client.Components Byond = new ByondClient(apiClient, instance); Repository = new RepositoryClient(apiClient, instance); DreamDaemon = new DreamDaemonClient(apiClient, instance); + Configuration = new ConfigurationClient(apiClient, instance); } } } \ No newline at end of file diff --git a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs index 3920cbb321..ceac94794d 100644 --- a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs +++ b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs @@ -4,6 +4,7 @@ using System; using System.Net; using System.Threading; using System.Threading.Tasks; +using Tgstation.Server.Api; using Tgstation.Server.Api.Models; using Tgstation.Server.Api.Rights; using Tgstation.Server.Host.Components; @@ -15,7 +16,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The for s /// - [Route("/" + nameof(Configuration))] + [Route(Routes.Configuration)] public sealed class ConfigurationController : ModelController { ///