Configuration cleanup

This commit is contained in:
Jordan Brown
2018-07-22 17:28:22 -04:00
parent 2b3346af52
commit 7cf4e870b2
13 changed files with 74 additions and 46 deletions
@@ -6,11 +6,11 @@ namespace Tgstation.Server.Api.Models
/// Represents a static game file. Create and delete actions uncerimonuously overwrite/delete files
/// </summary>
#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
{
/// <summary>
/// The content of the <see cref="Configuration"/> file. Will be <see langword="null"/> if <see cref="ConfigurationFileMetadata.ReadDenied"/> is <see langword="true"/> or during listing operations
/// The content of the <see cref="ConfigurationFile"/>. Will be <see langword="null"/> if <see cref="ConfigurationFileMetadata.ReadDenied"/> is <see langword="true"/> or during listing operations
/// </summary>
public byte[] Content { get; set; }
}
@@ -0,0 +1,21 @@
namespace Tgstation.Server.Api.Models
{
/// <summary>
/// The type of configuration allowed on an <see cref="Instance"/>
/// </summary>
public enum ConfigurationType
{
/// <summary>
/// Configuration editing is not allowed
/// </summary>
Disallowed,
/// <summary>
/// Configuration editing is allowed by all users on all files
/// </summary>
HostWrite,
/// <summary>
/// Co
/// </summary>
SystemIdentityWrite
}
}
+5 -4
View File
@@ -33,13 +33,14 @@ namespace Tgstation.Server.Api.Models
/// If the <see cref="Instance"/> is online
/// </summary>
[Permissions(WriteRight = InstanceManagerRights.SetOnline)]
public bool Online { get; set; }
public bool? Online { get; set; }
/// <summary>
/// If <see cref="Configuration"/> can be used on the <see cref="Instance"/>
/// If <see cref="ConfigurationFile"/> can be used on the <see cref="Instance"/>
/// </summary>
[Permissions(WriteRight = InstanceManagerRights.SetConfiguration)]
public bool ConfigurationAllowed { get; set; }
[Required]
public ConfigurationType? ConfigurationType { get; set; }
/// <summary>
/// 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
};
}
}
@@ -3,18 +3,18 @@
namespace Tgstation.Server.Api.Models.Internal
{
/// <summary>
/// Metadata about a <see cref="Configuration"/> file
/// Metadata about a <see cref="ConfigurationFile"/> file
/// </summary>
[Model(RightsType.Configuration, CanCrud = true, CanList = true, RequiresInstance = true, ReadRight = ConfigurationRights.Read, WriteRight = ConfigurationRights.Write)]
public class ConfigurationFileMetadata
{
/// <summary>
/// The path to the <see cref="Configuration"/> file
/// The path to the <see cref="ConfigurationFile"/> file
/// </summary>
public string Path { get; set; }
/// <summary>
/// If read access to the <see cref="Configuration"/> file was denied
/// If read access to the <see cref="ConfigurationFile"/> file was denied
/// </summary>
[Permissions(DenyWrite = true)]
public bool ReadDenied { get; set; }
@@ -3,7 +3,7 @@
namespace Tgstation.Server.Api.Rights
{
/// <summary>
/// Rights for <see cref="Models.Configuration"/>
/// Rights for <see cref="Models.ConfigurationFile"/>
/// </summary>
[Flags]
public enum ConfigurationRights
@@ -20,5 +20,13 @@ namespace Tgstation.Server.Api.Rights
/// Allow write access to <see cref="Models.InstanceUser"/> for the <see cref="Models.Instance"/>
/// </summary>
WriteUsers = 2,
/// <summary>
/// User can read configuration files if the instance allows it
/// </summary>
ReadConfiguration = 4,
/// <summary>
/// Users can write configuration files if the instance allows it
/// </summary>
EditConfiguration = 8,
}
}
+12 -12
View File
@@ -114,18 +114,18 @@ namespace Tgstation.Server.Api
public static Route ServerVersion() => new Route { Path = "/", Method = HttpMethod.Get };
/// <summary>
/// Get the <see cref="Route"/> to read a <see cref="Configuration"/> file
/// Get the <see cref="Route"/> to read a <see cref="ConfigurationFile"/> file
/// </summary>
/// <param name="instance">The <see cref="Instance"/> the <see cref="Configuration"/> file resides in</param>
/// <param name="path">The path to the file in the <see cref="Configuration"/> directory</param>
/// <param name="instance">The <see cref="Instance"/> the <see cref="ConfigurationFile"/> file resides in</param>
/// <param name="path">The path to the file in the <see cref="ConfigurationFile"/> directory</param>
/// <returns>A <see cref="Route"/> to the read action</returns>
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 };
/// <summary>
/// Get the <see cref="Route"/> to list <see cref="Configuration"/> files for a <paramref name="directory"/>
/// Get the <see cref="Route"/> to list <see cref="ConfigurationFile"/> files for a <paramref name="directory"/>
/// </summary>
/// <param name="instance">The <see cref="Instance"/> the <see cref="Configuration"/> file resides in</param>
/// <param name="directory">The <see cref="Configuration"/> directory to list</param>
/// <param name="instance">The <see cref="Instance"/> the <see cref="ConfigurationFile"/> file resides in</param>
/// <param name="directory">The <see cref="ConfigurationFile"/> directory to list</param>
/// <returns>A <see cref="Route"/> to the read action</returns>
public static Route ListFiles(Instance instance, string directory)
{
@@ -135,10 +135,10 @@ namespace Tgstation.Server.Api
}
/// <summary>
/// Get the <see cref="Route"/> to create a <see cref="Configuration"/> file
/// Get the <see cref="Route"/> to create a <see cref="ConfigurationFile"/> file
/// </summary>
/// <param name="instance">The <see cref="Instance"/> the <see cref="Configuration"/> file resides in</param>
/// <param name="path">The path to the file in the <see cref="Configuration"/> directory</param>
/// <param name="instance">The <see cref="Instance"/> the <see cref="ConfigurationFile"/> file resides in</param>
/// <param name="path">The path to the file in the <see cref="ConfigurationFile"/> directory</param>
/// <returns>A <see cref="Route"/> to the create action</returns>
public static Route CreateFile(Instance instance, string path)
{
@@ -148,10 +148,10 @@ namespace Tgstation.Server.Api
}
/// <summary>
/// Get the <see cref="Route"/> to delete a <see cref="Configuration"/> file
/// Get the <see cref="Route"/> to delete a <see cref="ConfigurationFile"/> file
/// </summary>
/// <param name="instance">The <see cref="Instance"/> the <see cref="Configuration"/> file resides in</param>
/// <param name="path">The path to the file in the <see cref="Configuration"/> directory</param>
/// <param name="instance">The <see cref="Instance"/> the <see cref="ConfigurationFile"/> file resides in</param>
/// <param name="path">The path to the file in the <see cref="ConfigurationFile"/> directory</param>
/// <returns>A <see cref="Route"/> to the delete action</returns>
public static Route DeleteFile(Instance instance, string path)
{
@@ -8,7 +8,7 @@ using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Client.Components
{
/// <summary>
/// For managing <see cref="Configuration"/> files
/// For managing <see cref="ConfigurationFile"/> files
/// </summary>
public interface IConfigurationClient : IRightsClient<ConfigurationRights>
{
@@ -17,39 +17,39 @@ namespace Tgstation.Server.Client.Components
/// </summary>
/// <param name="directory">The path to the directory to list files in</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="IReadOnlyList{T}"/> of <see cref="Configuration"/>s in the <paramref name="directory"/></returns>
Task<IReadOnlyList<Configuration>> List(string directory, CancellationToken cancellationToken);
/// <returns>A <see cref="IReadOnlyList{T}"/> of <see cref="ConfigurationFile"/>s in the <paramref name="directory"/></returns>
Task<IReadOnlyList<ConfigurationFile>> List(string directory, CancellationToken cancellationToken);
/// <summary>
/// Read a <see cref="Configuration"/> file
/// Read a <see cref="ConfigurationFile"/> file
/// </summary>
/// <param name="file">The <see cref="Configuration"/> file to read</param>
/// <param name="file">The <see cref="ConfigurationFile"/> file to read</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task Read(Configuration file, CancellationToken cancellationToken);
Task Read(ConfigurationFile file, CancellationToken cancellationToken);
/// <summary>
/// Overwrite a <see cref="Configuration"/> file with integrity checks
/// Overwrite a <see cref="ConfigurationFile"/> file with integrity checks
/// </summary>
/// <param name="file">The <see cref="Configuration"/> file to write</param>
/// <param name="file">The <see cref="ConfigurationFile"/> file to write</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task Write(Configuration file, CancellationToken cancellationToken);
Task Write(ConfigurationFile file, CancellationToken cancellationToken);
/// <summary>
/// Create/overwrite a <see cref="Configuration"/> file
/// Create/overwrite a <see cref="ConfigurationFile"/> file
/// </summary>
/// <param name="file">The <see cref="Configuration"/> file to write</param>
/// <param name="file">The <see cref="ConfigurationFile"/> file to write</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task Create(Configuration file, CancellationToken cancellationToken);
Task Create(ConfigurationFile file, CancellationToken cancellationToken);
/// <summary>
/// Delete a <see cref="Configuration"/> file
/// Delete a <see cref="ConfigurationFile"/> file
/// </summary>
/// <param name="file">The <see cref="Configuration"/> file to delete</param>
/// <param name="file">The <see cref="ConfigurationFile"/> file to delete</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task Delete(Configuration file, CancellationToken cancellationToken);
Task Delete(ConfigurationFile file, CancellationToken cancellationToken);
}
}
@@ -314,8 +314,6 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
foreach (var I in hs)
client.RfcJoin(I);
return (IReadOnlyList<Channel>)channels.Select(x => {
ulong id = channelIdCounter;
if (!channelIdMap.Any(y =>
@@ -42,8 +42,8 @@ namespace Tgstation.Server.Host.Components
/// <param name="configurationRelativePath">The relative path in the Configuration directory</param>
/// <param name="systemIdentity">The <see cref="ISystemIdentity"/> for the operation. If <see langword="null"/>, the operation will be performed as the user of the <see cref="Core.Application"/></param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Api.Models.Configuration"/> of the file</returns>
Task<Api.Models.Configuration> Read(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken);
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Api.Models.ConfigurationFile"/> of the file</returns>
Task<Api.Models.ConfigurationFile> Read(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken);
/// <summary>
/// Writes to a given <paramref name="configurationRelativePath"/>
@@ -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<Task>();
await dbInstances.ForEachAsync(metadata => tasks.Add(OnlineInstance(metadata, cancellationToken)), cancellationToken).ConfigureAwait(false);
await Task.WhenAll(tasks).ConfigureAwait(false);
@@ -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,
+1 -1
View File
@@ -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,