From a3531de91f259ee3b63fc4512a84b6a2023846d5 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Wed, 4 Apr 2018 16:29:04 -0400 Subject: [PATCH] IConfigurationClient --- .../Models/Configuration.cs | 2 +- src/Tgstation.Server.Api/RouteHelper.cs | 13 +++++ .../Components/IConfigurationClient.cs | 55 +++++++++++++++++++ .../Components/IInstanceClient.cs | 5 ++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/Tgstation.Server.Client/Components/IConfigurationClient.cs diff --git a/src/Tgstation.Server.Api/Models/Configuration.cs b/src/Tgstation.Server.Api/Models/Configuration.cs index 198956a00d..8497408366 100644 --- a/src/Tgstation.Server.Api/Models/Configuration.cs +++ b/src/Tgstation.Server.Api/Models/Configuration.cs @@ -33,7 +33,7 @@ namespace Tgstation.Server.Api.Models #pragma warning restore CA1819 // Properties should not return arrays /// - /// The MD5 hash of the file when last read by the user. Will be if is . If this doesn't match during update actions, the write will be denied + /// The MD5 hash of the file when last read by the user. Will be if is . If this doesn't match during update actions, the write will be denied with error code 409 /// public string LastReadHash { get; set; } } diff --git a/src/Tgstation.Server.Api/RouteHelper.cs b/src/Tgstation.Server.Api/RouteHelper.cs index b833a3f630..82592c0654 100644 --- a/src/Tgstation.Server.Api/RouteHelper.cs +++ b/src/Tgstation.Server.Api/RouteHelper.cs @@ -121,6 +121,19 @@ namespace Tgstation.Server.Api /// 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 + /// + /// The the file resides in + /// The directory to list + /// A to the read action + public static Route ListFiles(Instance instance, string directory) + { + var result = ReadFile(instance, directory); + result.Path = String.Concat("/ConfigurationList", result.Path.Substring(result.Path.IndexOf('/', 1))); + return result; + } + /// /// Get the to create a file /// diff --git a/src/Tgstation.Server.Client/Components/IConfigurationClient.cs b/src/Tgstation.Server.Client/Components/IConfigurationClient.cs new file mode 100644 index 0000000000..7f7d05a477 --- /dev/null +++ b/src/Tgstation.Server.Client/Components/IConfigurationClient.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Tgstation.Server.Api.Models; +using Tgstation.Server.Api.Rights; + +namespace Tgstation.Server.Client.Components +{ + /// + /// For managing files + /// + public interface IConfigurationClient : IRightsClient + { + /// + /// List configuration files + /// + /// The path to the directory to list files in + /// The for the operation + /// A of s in the + Task> List(string directory, CancellationToken cancellationToken); + + /// + /// Read a file + /// + /// The file to read + /// The for the operation + /// A representing the running operation + Task Read(Configuration file, CancellationToken cancellationToken); + + /// + /// Overwrite a file with integrity checks + /// + /// The file to write + /// The for the operation + /// A representing the running operation + Task Write(Configuration file, CancellationToken cancellationToken); + + /// + /// Create/overwrite a file + /// + /// The file to write + /// The for the operation + /// A representing the running operation + Task Create(Configuration file, CancellationToken cancellationToken); + + /// + /// Delete a file + /// + /// The file to delete + /// The for the operation + /// A representing the running operation + Task Delete(Configuration file, CancellationToken cancellationToken); + } +} diff --git a/src/Tgstation.Server.Client/Components/IInstanceClient.cs b/src/Tgstation.Server.Client/Components/IInstanceClient.cs index 0e891f674f..12f2eda8c1 100644 --- a/src/Tgstation.Server.Client/Components/IInstanceClient.cs +++ b/src/Tgstation.Server.Client/Components/IInstanceClient.cs @@ -24,6 +24,11 @@ namespace Tgstation.Server.Client.Components /// IDreamDaemonClient DreamDaemon { get; } + /// + /// Access the + /// + IConfigurationClient Configuration { get; } + /// /// Access the ///