mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-27 07:04:57 +01:00
Finish up the configuration stuff
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using Tgstation.Server.Api.Rights;
|
||||
|
||||
namespace Tgstation.Server.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a static game file. Create and delete actions uncerimonuously overwrite/delete files
|
||||
/// </summary>
|
||||
[Model(RightsType.Configuration, CanCrud = true, CanList = true, RequiresInstance = true, ReadRight = ConfigurationRights.Read, WriteRight = ConfigurationRights.Write)]
|
||||
public sealed class Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// The path to the <see cref="Configuration"/> file
|
||||
/// </summary>
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If read access to the <see cref="Configuration"/> file was denied
|
||||
/// </summary>
|
||||
[Permissions(DenyWrite = true)]
|
||||
public bool ReadDenied { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If <see cref="Path"/> represents a directory. Will only be <see langword="true"/> if <see cref="ReadDenied"/> is <see langword="true"/>
|
||||
/// </summary>
|
||||
[Permissions(DenyWrite = true)]
|
||||
public bool IsDirectory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The content of the <see cref="Configuration"/> file. Will be <see langword="null"/> if <see cref="ReadDenied"/> is <see langword="true"/> or during listing operations
|
||||
/// </summary>
|
||||
#pragma warning disable CA1819 // Properties should not return arrays
|
||||
public byte[] Content { get; set; }
|
||||
#pragma warning restore CA1819 // Properties should not return arrays
|
||||
|
||||
/// <summary>
|
||||
/// The MD5 hash of the file when last read by the user. Will be <see langword="null"/> if <see cref="ReadDenied"/> is <see langword="true"/>. If this doesn't match during update actions, the write will be denied
|
||||
/// </summary>
|
||||
public string LastReadHash { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -55,5 +55,11 @@ namespace Tgstation.Server.Api.Models
|
||||
/// </summary>
|
||||
[Permissions(WriteRight = DreamMakerRights.SetAutoCompile)]
|
||||
public int? AutoCompileInterval { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The .dme file <see cref="DreamMaker"/> tries to compile with
|
||||
/// </summary>
|
||||
[Permissions(WriteRight = DreamMakerRights.SetDme)]
|
||||
public string TargetDme { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace Tgstation.Server.Api.Rights
|
||||
{
|
||||
/// <summary>
|
||||
/// Rights for <see cref="Models.Configuration"/>
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum ConfigurationRights
|
||||
{
|
||||
/// <summary>
|
||||
/// User has no rights
|
||||
/// </summary>
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// User may read files
|
||||
/// </summary>
|
||||
Read = 1,
|
||||
/// <summary>
|
||||
/// User may write files
|
||||
/// </summary>
|
||||
Write = 2,
|
||||
/// <summary>
|
||||
/// User may list files
|
||||
/// </summary>
|
||||
List = 3
|
||||
}
|
||||
}
|
||||
@@ -28,5 +28,9 @@ namespace Tgstation.Server.Api.Rights
|
||||
/// User may modify <see cref="Models.DreamMaker.AutoCompileInterval"/>
|
||||
/// </summary>
|
||||
SetAutoCompile = 8,
|
||||
/// <summary>
|
||||
/// User may modify <see cref="Models.DreamMaker.TargetDme"/>
|
||||
/// </summary>
|
||||
SetDme = 16
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace Tgstation.Server.Api
|
||||
/// Get the <see cref="Route"/> to a given <paramref name="user"/>'s token list
|
||||
/// </summary>
|
||||
/// <param name="user">The <see cref="User"/> to list tokens for</param>
|
||||
/// <returns>A <see cref="Route"/> to the get action</returns>
|
||||
/// <returns>A <see cref="Route"/> to the list action</returns>
|
||||
public static Route ListUserTokens(User user)
|
||||
{
|
||||
var result = List<Token>(null);
|
||||
@@ -112,5 +112,39 @@ namespace Tgstation.Server.Api
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Route ServerVersion() => new Route { Path = "/", Method = HttpMethod.Get };
|
||||
|
||||
/// <summary>
|
||||
/// Get the <see cref="Route"/> to read a <see cref="Configuration"/> 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>
|
||||
/// <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 create a <see cref="Configuration"/> 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>
|
||||
/// <returns>A <see cref="Route"/> to the create action</returns>
|
||||
public static Route CreateFile(Instance instance, string path)
|
||||
{
|
||||
var result = ReadFile(instance, path);
|
||||
result.Method = HttpMethod.Put;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the <see cref="Route"/> to delete a <see cref="Configuration"/> 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>
|
||||
/// <returns>A <see cref="Route"/> to the delete action</returns>
|
||||
public static Route DeleteFile(Instance instance, string path)
|
||||
{
|
||||
var result = ReadFile(instance, path);
|
||||
result.Method = HttpMethod.Delete;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user