mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-29 08:00:19 +01:00
InstanceManagerClient
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
namespace Tgstation.Server.Api
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Tgstation.Server.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Routes to a server actions
|
||||
@@ -19,5 +22,25 @@
|
||||
/// The <see cref="Models.User"/> controller
|
||||
/// </summary>
|
||||
public const string User = Root + nameof(Models.User);
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Models.Instance"/> controller
|
||||
/// </summary>
|
||||
public const string InstanceManager = Root + nameof(Models.Instance);
|
||||
|
||||
/// <summary>
|
||||
/// Apply an <paramref name="id"/> postfix to a <paramref name="route"/>
|
||||
/// </summary>
|
||||
/// <param name="route">The route</param>
|
||||
/// <param name="id">The ID</param>
|
||||
/// <returns>The <paramref name="route"/> with <paramref name="id"/> appended</returns>
|
||||
public static string SetID(string route, long id) => String.Format(CultureInfo.InvariantCulture, "{0}/{1}", route, id);
|
||||
|
||||
/// <summary>
|
||||
/// Get the /List postfix for a <paramref name="route"/>
|
||||
/// </summary>
|
||||
/// <param name="route">The route</param>
|
||||
/// <returns>The <paramref name="route"/> with /List appended</returns>
|
||||
public static string List(string route) => String.Format(CultureInfo.InvariantCulture, "{0}/List", route);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using Tgstation.Server.Api.Models;
|
||||
|
||||
namespace Tgstation.Server.Client.Components
|
||||
{
|
||||
/// <inheritdoc />
|
||||
sealed class InstanceClient : IInstanceClient
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public Instance Metadata { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IByondClient Byond => throw new NotImplementedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IRepositoryClient Repository => throw new NotImplementedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IDreamDaemonClient DreamDaemon => throw new NotImplementedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IConfigurationClient Configuration => throw new NotImplementedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IInstanceUserClient Users => throw new NotImplementedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IChatBotsClient ChatBots => throw new NotImplementedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IDreamMakerClient DreamMaker => throw new NotImplementedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IJobsClient Jobs => throw new NotImplementedException();
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IApiClient"/> for the <see cref="InstanceClient"/>
|
||||
/// </summary>
|
||||
readonly IApiClient apiClient;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a <see cref="InstanceClient"/>
|
||||
/// </summary>
|
||||
/// <param name="apiClient">The value of <see cref="apiClient"/></param>
|
||||
/// <param name="instance">The value of <see cref="Metadata"/></param>
|
||||
public InstanceClient(IApiClient apiClient, Instance instance)
|
||||
{
|
||||
this.apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient));
|
||||
Metadata = instance ?? throw new ArgumentNullException(nameof(instance));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Tgstation.Server.Api;
|
||||
using Tgstation.Server.Api.Models;
|
||||
using Tgstation.Server.Client.Components;
|
||||
|
||||
namespace Tgstation.Server.Client
|
||||
{
|
||||
/// <inheritdoc />
|
||||
sealed class InstanceManagerClient : IInstanceManagerClient
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="IApiClient"/> for the <see cref="InstanceManagerClient"/>
|
||||
/// </summary>
|
||||
readonly IApiClient apiClient;
|
||||
|
||||
/// <summary>
|
||||
/// Map of already created <see cref="IInstanceClient"/>s
|
||||
/// </summary>
|
||||
readonly Dictionary<long, IInstanceClient> cachedClients;
|
||||
|
||||
/// <summary>
|
||||
/// Construct an <see cref="InstanceManagerClient"/>
|
||||
/// </summary>
|
||||
/// <param name="apiClient"></param>
|
||||
public InstanceManagerClient(IApiClient apiClient)
|
||||
{
|
||||
this.apiClient = apiClient;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<Instance> Create(Instance instance, CancellationToken cancellationToken) => apiClient.Create<Instance, Instance>(Routes.InstanceManager, instance, cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task Delete(Instance instance, CancellationToken cancellationToken) => apiClient.Delete(Routes.SetID(Routes.InstanceManager, instance.Id), cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<IReadOnlyList<Instance>> List(CancellationToken cancellationToken) => apiClient.Read<IReadOnlyList<Instance>>(Routes.List(Routes.InstanceManager), cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<Instance> Update(Instance instance, CancellationToken cancellationToken) => apiClient.Update<Instance, Instance>(Routes.InstanceManager, instance, cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public IInstanceClient CreateClient(Instance instance) => new InstanceClient(apiClient, instance);
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ namespace Tgstation.Server.Client
|
||||
if (Token.Bearer != apiClient.Headers.Token)
|
||||
throw new ArgumentOutOfRangeException(nameof(token), token, "Provided token does not match apiClient headers!");
|
||||
|
||||
Instances = new InstanceManagerClient(apiClient);
|
||||
Users = new UsersClient(apiClient);
|
||||
Administration = new AdministrationClient(apiClient);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
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;
|
||||
@@ -25,7 +26,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <summary>
|
||||
/// Controller for managing <see cref="Components.Instance"/>s
|
||||
/// </summary>
|
||||
[Route("/Instance")]
|
||||
[Route(Routes.InstanceManager)]
|
||||
public sealed class InstanceController : ModelController<Api.Models.Instance>
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user