We're somewhere

This commit is contained in:
Cyberboss
2018-04-08 13:35:04 -04:00
parent c63549fa93
commit 399186874e
40 changed files with 345 additions and 231 deletions
@@ -0,0 +1,23 @@
namespace Tgstation.Server.Api.Models
{
/// <summary>
/// Indicates a chat channel
/// </summary>
public sealed class ChatChannel
{
/// <summary>
/// The column ID
/// </summary>
public long Id { get; set; }
/// <summary>
/// The IRC channel name
/// </summary>
public string IrcChannel { get; set; }
/// <summary>
/// The Discord channel ID
/// </summary>
public long DiscordChannelId { get; set; }
}
}
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Api.Models
@@ -19,6 +21,7 @@ namespace Tgstation.Server.Api.Models
/// The IRC server name
/// </summary>
[Permissions(ReadRight = ChatSettingsRights.SetIrcSettings, WriteRight = ChatSettingsRights.SetIrcSettings)]
[Required]
public string IrcHost { get; set; }
/// <summary>
@@ -33,18 +36,6 @@ namespace Tgstation.Server.Api.Models
[Permissions(ReadRight = ChatSettingsRights.SetIrcSettings, WriteRight = ChatSettingsRights.SetIrcSettings)]
public string IrcNickServPassword { get; set; }
/// <summary>
/// Channels the IRC client should join/listen/announce in and allow admin commands
/// </summary>
[Permissions(WriteRight = ChatSettingsRights.SetIrcChannels)]
public List<string> IrcAdminChannels { get; set; }
/// <summary>
/// Channels the IRC client should join/listen/announce in
/// </summary>
[Permissions(WriteRight = ChatSettingsRights.SetIrcChannels)]
public List<string> IrcGeneralChannels { get; set; }
/// <summary>
/// If the Discord bot is enabled
/// </summary>
@@ -58,14 +49,15 @@ namespace Tgstation.Server.Api.Models
public string DiscordBotToken { get; set; }
/// <summary>
/// Channels the Discord bot should listen/announce in and allow admin commands
/// Channels the bot should listen/announce in and allow admin commands
/// </summary>
[Permissions(WriteRight = ChatSettingsRights.SetDiscordChannels)]
public List<long> DiscordAdminChannels { get; set; }
public virtual List<ChatChannel> AdminChannels { get; set; }
/// <summary>
/// Channels the Discord bot should listen/announce in
/// </summary>
[Permissions(WriteRight = ChatSettingsRights.SetDiscordChannels)]
public List<long> DiscordGeneralChannels { get; set; }
public virtual List<ChatChannel> GeneralChannels { get; set; }
}
}
@@ -1,5 +1,7 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Tgstation.Server.Api.Models
{
public class CompileJob
@@ -39,17 +41,10 @@ namespace Tgstation.Server.Api.Models
/// Exit code of DM. If <see langword="null"/>, the job was cancelled
/// </summary>
public int? ExitCode { get; set; }
/// <summary>
/// Git revision the compiler ran on. Not modifiable
/// </summary>
[Required]
public RevisionInformation RevisionInformation { get; set; }
/// <summary>
/// Git revision of the origin branch the compiler ran on. Not modifiable
/// </summary>
[Required]
public string OriginRevision { get; set; }
}
}
@@ -30,9 +30,7 @@ namespace Tgstation.Server.Api.Models
/// <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 with error code 409
@@ -26,6 +26,7 @@ namespace Tgstation.Server.Api.Models
/// The path to where the <see cref="Instance"/> is located
/// </summary>
[Permissions(WriteRight = InstanceManagerRights.Relocate)]
[Required]
public string Path { get; set; }
/// <summary>
@@ -6,14 +6,8 @@ namespace Tgstation.Server.Api.Models
/// Represents a <see cref="User"/>s permissions in an <see cref="Instance"/>
/// </summary>
[Model(RightsType.InstanceUser, WriteRight = InstanceUserRights.WriteUsers, CanList = true, RequiresInstance = true)]
public sealed class InstanceUser
public class InstanceUser
{
/// <summary>
/// See definition in <see cref="User.Id"/>
/// </summary>
[Permissions(DenyWrite = true)]
public long Id { get; set; }
/// <summary>
/// The <see cref="Rights.ByondRights"/> of the <see cref="InstanceUser"/>
/// </summary>
@@ -37,7 +31,7 @@ namespace Tgstation.Server.Api.Models
/// <summary>
/// The <see cref="Rights.ChatSettingsRights"/> of the <see cref="InstanceUser"/>
/// </summary>
public ChatSettingsRights ChatRights { get; set; }
public ChatSettingsRights ChatSettingsRights { get; set; }
/// <summary>
/// The <see cref="Rights.ConfigurationRights"/> of the <see cref="InstanceUser"/>
@@ -15,49 +15,42 @@ namespace Tgstation.Server.Api.Models.Internal
/// If <see cref="DreamDaemon"/> starts when it's <see cref="Instance"/> starts
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SetAutoStart)]
[Required]
public bool? AutoStart { get; set; }
public bool AutoStart { get; set; }
/// <summary>
/// If the BYOND web client can be used to connect to the game server
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SetWebClient)]
[Required]
public bool? AllowWebClient { get; set; }
public bool AllowWebClient { get; set; }
/// <summary>
/// If the server is undergoing a soft reset. This may be automatically set by changes to other fields
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SoftRestart)]
[Required]
public bool? SoftRestart { get; set; }
public bool SoftRestart { get; set; }
/// <summary>
/// If the server is undergoing a soft shutdown
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SoftShutdown)]
[Required]
public bool? SoftShutdown { get; set; }
public bool SoftShutdown { get; set; }
/// <summary>
/// The <see cref="DreamDaemonSecurity"/> level of <see cref="DreamDaemon"/>
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SetSecurity)]
[Required]
public DreamDaemonSecurity? SecurityLevel { get; set; }
public DreamDaemonSecurity SecurityLevel { get; set; }
/// <summary>
/// The first port <see cref="DreamDaemon"/> uses. This should be the publically advertised port
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SetPorts)]
[Required]
public ushort? PrimaryPort { get; set; }
public ushort PrimaryPort { get; set; }
/// <summary>
/// The second port <see cref="DreamDaemon"/> uses
/// </summary>
[Permissions(ReadRight = DreamDaemonRights.ReadMetadata, WriteRight = DreamDaemonRights.SetPorts)]
[Required]
public ushort? SecondaryPort { get; set; }
public ushort SecondaryPort { get; set; }
}
}
@@ -22,6 +22,7 @@ namespace Tgstation.Server.Api.Models.Internal
[Required]
public DateTimeOffset StartedAt { get; set; }
[Required]
public User StartedBy { get; set; }
/// <summary>
@@ -0,0 +1,56 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Api.Models.Internal
{
public class RepositorySettings
{
/// <summary>
/// The origin URL. If <see langword="null"/>, the <see cref="Repository"/> does not exist
/// </summary>
[Permissions(WriteRight = RepositoryRights.SetOrigin)]
public string Origin { get; set; }
[Permissions(DenyWrite = true)]
public RevisionInformation RevisionInformation { get; set; }
/// <summary>
/// The name of the committer
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeCommitter)]
[Required]
public string CommitterName { get; set; }
/// <summary>
/// The e-mail of the committer
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeCommitter)]
[Required]
public string CommitterEmail { get; set; }
/// <summary>
/// The username to access the git repository with
/// </summary>
[Permissions(ReadRight = RepositoryRights.ChangeCredentials, WriteRight = RepositoryRights.ChangeCredentials)]
public string AccessUser { get; set; }
/// <summary>
/// The token/password to access the git repository with
/// </summary>
[Permissions(ReadRight = RepositoryRights.ChangeCredentials, WriteRight = RepositoryRights.ChangeCredentials)]
public string AccessToken { get; set; }
/// <summary>
/// If commits created from testmerges are pushed to the remote
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeTestMergeCommits)]
public bool PushTestMergeCommits { get; set; }
/// <summary>
/// How often the <see cref="Repository"/> automatically updates in minutes
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeAutoUpdate)]
public int? AutoUpdateInterval { get; set; }
}
}
@@ -5,7 +5,7 @@ namespace Tgstation.Server.Api.Models.Internal
public class ServerSettings
{
/// <summary>
/// Use the specified Windows/UNIX authentication to authorize users. Setting this to <see langword="null"/> enables full administrative anonymous access
/// Use the specified Windows/POSIX authentication group to authorize users. Changing this may enable or disable <see cref="User"/>s depending on how they were configured. Setting this to <see langword="null"/> changes the authentication mode to database.
/// </summary>
[Permissions(ReadRight = AdministrationRights.ChangeAuthenticationGroup, WriteRight = AdministrationRights.ChangeAuthenticationGroup)]
public string SystemAuthenticationGroup { get; set; }
@@ -0,0 +1,47 @@
using System;
using System.ComponentModel.DataAnnotations;
using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Api.Models.Internal
{
/// <summary>
/// Represents an access token for the server. Read action generates a new one. Update action expires all for user
/// </summary>
[Model(RightsType.Token, CanList = true)]
public class Token
{
/// <summary>
/// The id of the <see cref="Token"/>. Not modifiable
/// </summary>
public long Id { get; set; }
/// <summary>
/// The user agent that created the <see cref="Token"/>
/// </summary>
[Required]
public string ClientUserAgent { get; set; }
[Required, MinLength(4), MaxLength(16)]
public byte[] IssuedTo { get; set; }
[Required, MinLength(4), MaxLength(16)]
public byte[] LastUsedBy { get; set; }
/// <summary>
/// When the <see cref="Token"/> was originally issued
/// </summary>
[Required]
public DateTimeOffset IssuedAt { get; set; }
/// <summary>
/// When the <see cref="Token"/> was last used
/// </summary>
public DateTimeOffset LastUsedAt { get; set; }
/// <summary>
/// The token <see cref="string"/>. Not modifiable, only appears once
/// </summary>
[Required]
public string Value { get; set; }
}
}
+1 -52
View File
@@ -7,17 +7,8 @@ namespace Tgstation.Server.Api.Models
/// Represents a git repository
/// </summary>
[Model(RightsType.Repository, ReadRight = RepositoryRights.Read, RequiresInstance = true)]
public sealed class Repository
public sealed class Repository : Internal.RepositorySettings
{
/// <summary>
/// The origin URL. If <see langword="null"/>, the <see cref="Repository"/> does not exist
/// </summary>
[Permissions(WriteRight = RepositoryRights.SetOrigin)]
public string Origin { get; set; }
[Permissions(DenyWrite = true)]
public RevisionInformation RevisionInformation { get; set; }
/// <summary>
/// The commit HEAD points to
/// </summary>
@@ -30,49 +21,7 @@ namespace Tgstation.Server.Api.Models
[Permissions(WriteRight = RepositoryRights.SetReference)]
public string Reference { get; set; }
/// <summary>
/// The name of the committer
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeCommitter)]
public string CommitterName { get; set; }
/// <summary>
/// The e-mail of the committer
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeCommitter)]
public string CommitterEmail { get; set; }
/// <summary>
/// List of <see cref="TestMerge"/>s in the repository
/// </summary>
[Permissions(DenyWrite = true)]
public List<TestMerge> TestMerges { get; set; }
[Permissions(WriteRight = RepositoryRights.MergePullRequest)]
public List<TestMergeParameters> NewTestMerges { get; set; }
/// <summary>
/// The username to access the git repository with
/// </summary>
[Permissions(ReadRight = RepositoryRights.ChangeCredentials, WriteRight = RepositoryRights.ChangeCredentials)]
public string AccessUser { get; set; }
/// <summary>
/// The token/password to access the git repository with
/// </summary>
[Permissions(ReadRight = RepositoryRights.ChangeCredentials, WriteRight = RepositoryRights.ChangeCredentials)]
public string AccessToken { get; set; }
/// <summary>
/// If commits created from testmerges are pushed to the remote
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeTestMergeCommits)]
public bool PushTestMergeCommits { get; set; }
/// <summary>
/// How often the <see cref="Repository"/> automatically updates in minutes
/// </summary>
[Permissions(WriteRight = RepositoryRights.ChangeAutoUpdate)]
public int? AutoUpdateInterval { get; set; }
}
}
@@ -1,16 +1,17 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Tgstation.Server.Api.Models
{
public sealed class RevisionInformation
public class RevisionInformation
{
[Key]
string Revision { get; set; }
[Required, StringLength(40)]
public string Revision { get; set; }
[Required]
string OriginRevision { get; set; }
List<TestMerge> TestMerges { get; set; }
[Required, StringLength(40)]
public string OriginRevision { get; set; }
public List<TestMerge> TestMerges { get; set; }
}
}
@@ -7,14 +7,8 @@ namespace Tgstation.Server.Api.Models
{
public long Id { get; set; }
[Required]
RevisionInformation RevisionInformation { get; set; }
[Required]
public DateTimeOffset MergedAt { get; set; }
[Required]
public DateTimeOffset RemovedAt { get; set; }
public User MergedBy { get; set; }
+16 -42
View File
@@ -1,48 +1,22 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Net;
using Tgstation.Server.Api.Rights;
using System.Net;
namespace Tgstation.Server.Api.Models
{
/// <summary>
/// Represents an access token for the server. Read action generates a new one. Update action expires all for user
/// </summary>
[Model(RightsType.Token, CanList = true)]
public sealed class Token
/// <inheritdoc />
public sealed class Token : Internal.Token
{
/// <summary>
/// The id of the <see cref="Token"/>. Not modifiable
/// </summary>
public long Id { get; }
/// <inheritdoc />
new public IPAddress IssuedTo
{
get => new IPAddress(base.IssuedTo);
set => base.IssuedTo = value.GetAddressBytes();
}
/// <summary>
/// The user agent that created the <see cref="Token"/>
/// </summary>
[Required]
public string ClientUserAgent { get; set; }
/// <summary>
/// The <see cref="IPAddress"/> the <see cref="Token"/> was originally issued to
/// </summary>
[Required]
public IPAddress IssuedTo { get; set; }
/// <summary>
/// When the <see cref="Token"/> was originally issued
/// </summary>
[Required]
public DateTimeOffset IssuedAt { get; set; }
/// <summary>
/// When the <see cref="Token"/> was last used
/// </summary>
public DateTimeOffset LastUsedAt { get; set; }
/// <summary>
/// The token <see cref="string"/>. Not modifiable, only appears once
/// </summary>
[Required]
public string Value { get; set; }
/// <inheritdoc />
new public IPAddress LastUsedBy
{
get => new IPAddress(base.LastUsedBy);
set => base.LastUsedBy = value.GetAddressBytes();
}
}
}
}
+15 -3
View File
@@ -1,4 +1,6 @@
using Tgstation.Server.Api.Rights;
using System;
using System.ComponentModel.DataAnnotations;
using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Api.Models
{
@@ -14,26 +16,36 @@ namespace Tgstation.Server.Api.Models
[Permissions(DenyWrite = true)]
public long Id { get; set; }
[Permissions(DenyWrite = true)]
[Required]
public DateTimeOffset CreatedAt { get; set; }
/// <summary>
/// The SID/UID of the <see cref="User"/> on Windows/POSIX respectively
/// </summary>
[Permissions(DenyWrite = true)]
public string SystemId { get; set; }
public string SystemIdentifier { get; set; }
[Permissions(DenyWrite = true)]
public bool Enabled { get; set; }
/// <summary>
/// The name of the <see cref="User"/>
/// </summary>
[Permissions(DenyWrite = true)]
[Permissions(WriteRight = AdministrationRights.EditUsers)]
[Required]
public string Name { get; set; }
/// <summary>
/// The <see cref="Rights.AdministrationRights"/> for the <see cref="User"/>
/// </summary>
[Permissions(WriteRight = AdministrationRights.EditUsers)]
public AdministrationRights AdministrationRights { get; set; }
/// <summary>
/// The <see cref="Rights.InstanceManagerRights"/> for the <see cref="User"/>
/// </summary>
[Permissions(WriteRight = AdministrationRights.EditUsers)]
public InstanceManagerRights InstanceManagerRights { get; set; }
}
}
@@ -13,7 +13,7 @@ namespace Tgstation.Server.Api.Rights
/// </summary>
None = 0,
/// <summary>
/// User can change <see cref="Models.Administration.SystemAuthenticationGroup"/>
/// User can change <see cref="Models.Internal.ServerSettings.SystemAuthenticationGroup"/>
/// </summary>
ChangeAuthenticationGroup = 1,
/// <summary>
@@ -35,7 +35,6 @@ namespace Tgstation.Server.Api.Rights
/// <summary>
/// User can change <see cref="Models.Administration.UpstreamRepository"/>
/// </summary>
SetUpstreamRepository
SetUpstreamRepository = 32
}
}
@@ -10,12 +10,12 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<DocumentationFile>bin\Release\netstandard2.0\Tgstation.Server.Api.xml</DocumentationFile>
<NoWarn>1701;1702;1705;CA2227</NoWarn>
<NoWarn>1701;1702;1705;CA2227;CA1819</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<LangVersion>latest</LangVersion>
<NoWarn>1701;1702;1705;CA2227</NoWarn>
<NoWarn>1701;1702;1705;CA2227;CA1819</NoWarn>
</PropertyGroup>
<ItemGroup>
@@ -10,6 +10,7 @@
"profiles": {
"Tgstation.Server.Host.Console": {
"commandName": "Project",
"workingDirectory": "bin\\Debug\\netcoreapp2.0",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
+10 -5
View File
@@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Globalization;
using Tgstation.Server.Host.Configuration;
using Tgstation.Server.Host.Models;
namespace Tgstation.Server.Host.Core
@@ -36,8 +37,8 @@ namespace Tgstation.Server.Host.Core
{
if (services == null)
throw new ArgumentNullException(nameof(services));
services.Configure<DatabaseContext>(configuration.GetSection("Database"));
var workingDir = Environment.CurrentDirectory;
services.Configure<DatabaseConfiguration>(configuration.GetSection("Database"));
services.AddMvc();
services.AddOptions();
@@ -58,7 +59,7 @@ namespace Tgstation.Server.Host.Core
throw new ArgumentNullException(nameof(applicationBuilder));
if (hostingEnvironment == null)
throw new ArgumentNullException(nameof(hostingEnvironment));
if (hostingEnvironment.IsDevelopment())
applicationBuilder.UseDeveloperExceptionPage();
@@ -77,9 +78,13 @@ namespace Tgstation.Server.Host.Core
SupportedUICultures = supportedCultures,
});
applicationBuilder.UseAsyncInitialization<IDatabaseContext>((databaseContext, cancellationToken) => databaseContext.Initialize(cancellationToken));
applicationBuilder.UseAsyncInitialization(async (cancellationToken) =>
{
using (var scop = applicationBuilder.ApplicationServices.CreateScope())
await scop.ServiceProvider.GetRequiredService<IDatabaseContext>().Initialize(cancellationToken).ConfigureAwait(false);
});
applicationBuilder.UseSystemAuthentication();
applicationBuilder.UseSystemAuthentication();
applicationBuilder.UseMvc();
}
@@ -99,7 +99,7 @@ namespace Tgstation.Server.Host.Core
public void Dispose() => SystemIdentity.Dispose();
/// <inheritdoc />
public Task<User> User(CancellationToken cancellationToken)
public Task<DbUser> User(CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
@@ -20,7 +20,7 @@ namespace Tgstation.Server.Host.Core
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="User"/> represented by the <see cref="IAuthenticationContext"/></returns>
Task<User> User(CancellationToken cancellationToken);
Task<DbUser> User(CancellationToken cancellationToken);
/// <summary>
/// The <see cref="Api.Models.InstanceUser"/> represented by <see cref="User"/> and a given <paramref name="instance"/>
@@ -1,4 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Tgstation.Server.Api.Models;
namespace Tgstation.Server.Host.Models
{
@@ -1,10 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace Tgstation.Server.Host.Models
{
sealed class CompileJob : Api.Models.CompileJob
{
[Required]
new User TriggeredBy { get; set; }
}
}
@@ -5,6 +5,7 @@ using Microsoft.Extensions.Options;
using System;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Host.Configuration;
using ZNetCS.AspNetCore.Logging.EntityFrameworkCore;
@@ -12,16 +13,30 @@ namespace Tgstation.Server.Host.Models
{
sealed class DatabaseContext : DbContext, IDatabaseContext
{
/// <inheritdoc />
public DbSet<ServerSettings> ServerSettings { get; set; }
public DbSet<User> Users { get; set; }
/// <inheritdoc />
public DbSet<DbUser> Users { get; set; }
/// <inheritdoc />
public DbSet<Instance> Instances { get; set; }
/// <summary>
/// The <see cref="DbSet{TEntity}"/> for <see cref="Log"/>s
/// </summary>
public DbSet<Log> Logs { get; set; }
public DbSet<InstanceUser> InstanceUsers { get; set; }
public DbSet<ChatChannel> ChatChannels { get; set; }
public DbSet<ChatSettings> ChatSettings { get; set; }
public DbSet<DreamDaemonSettings> DreamDaemonSettings { get; set; }
public DbSet<DreamMakerSettings> DreamMakerSettings { get; set; }
public DbSet<DbCompileJob> CompileJobs { get; set; }
public DbSet<Job> Jobs { get; set; }
public DbSet<Api.Models.Internal.Token> Tokens { get; set; }
public DbSet<TestMerge> TestMerges { get; set; }
public DbSet<RevisionInformation> RevisionInformations { get; set; }
public DbSet<RepositorySettings> RepositorySettings { get; set; }
/// <summary>
/// The <see cref="DatabaseConfiguration"/> for the <see cref="DatabaseContext"/>
@@ -39,11 +54,11 @@ namespace Tgstation.Server.Host.Models
/// <summary>
/// Construct a <see cref="DatabaseContext"/>
/// </summary>
/// <param name="options">The <see cref="DbContextOptions{TContext}"/> for the <see cref="DatabaseContext"/></param>
/// <param name="dbContextOptions">The <see cref="DbContextOptions{TContext}"/> for the <see cref="DatabaseContext"/></param>
/// <param name="databaseConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="databaseConfiguration"/></param>
/// <param name="loggerFactory">The value of <see cref="loggerFactory"/></param>
/// <param name="hostingEnvironment">The value of <see cref="hostingEnvironment"/></param>
public DatabaseContext(DbContextOptions<DatabaseContext> options, IOptions<DatabaseConfiguration> databaseConfigurationOptions, ILoggerFactory loggerFactory, IHostingEnvironment hostingEnvironment) : base(options)
public DatabaseContext(DbContextOptions<DatabaseContext> dbContextOptions, IOptions<DatabaseConfiguration> databaseConfigurationOptions, ILoggerFactory loggerFactory, IHostingEnvironment hostingEnvironment) : base(dbContextOptions)
{
databaseConfiguration = databaseConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(databaseConfigurationOptions));
this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
@@ -57,8 +72,9 @@ namespace Tgstation.Server.Host.Models
// build default model.
LogModelBuilderHelper.Build(modelBuilder.Entity<Log>());
// real relation database can map table:
modelBuilder.Entity<Log>().ToTable(nameof(Log));
modelBuilder.Entity<Log>().ToTable(nameof(Logs));
modelBuilder.Entity<RevisionInformation>().HasIndex(x => x.Revision).IsUnique();
}
/// <inheritdoc />
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace Tgstation.Server.Host.Models
{
sealed class DbCompileJob : Api.Models.CompileJob
{
[Required]
new public DbUser TriggeredBy { get; set; }
[Required]
new public RevisionInformation RevisionInformation { get; set; }
}
}
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using Tgstation.Server.Api.Models.Internal;
namespace Tgstation.Server.Host.Models
{
/// <summary>
/// Represents a <see cref="Api.Models.User"/> in the database
/// </summary>
sealed class DbUser : Api.Models.User
{
public string PasswordHash { get; set; }
public string PasswordSalt { get; set; }
/// <summary>
/// The <see cref="InstanceUser"/>s for the <see cref="DbUser"/>
/// </summary>
public List<InstanceUser> InstanceUsers { get; set; }
/// <summary>
/// The <see cref="Token"/>s for the <see cref="DbUser"/>
/// </summary>
public List<Token> Tokens { get; set; }
}
}
@@ -4,13 +4,17 @@ namespace Tgstation.Server.Host.Models
{
sealed class DreamDaemonSettings : Api.Models.Internal.DreamDaemonSettings
{
long Id { get; set; }
int? ProcessId { get; set; }
public long Id { get; set; }
long InstanceId { get; set; }
public int? ProcessId { get; set; }
public long InstanceId { get; set; }
public string AccessToken { get; set; }
[Required]
Instance Instance { get; set; }
public Instance Instance { get; set; }
new public DbCompileJob CompileJob { get; set; }
}
}
@@ -4,9 +4,13 @@ namespace Tgstation.Server.Host.Models
{
sealed class DreamMakerSettings : Api.Models.Internal.DreamMakerSettings
{
long Id { get; set; }
long InstanceId { get; set; }
public long Id { get; set; }
public long InstanceId { get; set; }
[Required]
Instance Instance { get; set; }
public Instance Instance { get; set; }
public DbCompileJob CompileJob { get; set; }
}
}
@@ -10,9 +10,9 @@ namespace Tgstation.Server.Host.Models
interface IDatabaseContext
{
/// <summary>
/// The <see cref="User"/>s in the <see cref="IDatabaseContext"/>
/// The <see cref="DbUser"/>s in the <see cref="IDatabaseContext"/>
/// </summary>
DbSet<User> Users { get; }
DbSet<DbUser> Users { get; }
/// <summary>
/// The <see cref="Instances"/>s in the <see cref="IDatabaseContext"/>
+8 -5
View File
@@ -13,16 +13,19 @@ namespace Tgstation.Server.Host.Models
/// The <see cref="Models.ChatSettings"/> for the <see cref="Instance"/>
/// </summary>
[Required]
ChatSettings ChatSettings { get; set; }
public ChatSettings ChatSettings { get; set; }
/// <summary>
/// The <see cref="Models.DreamMakerSettings"/> for the <see cref="Instance"/>
/// </summary>
[Required]
DreamMakerSettings DreamMakerSettings { get; set; }
public DreamMakerSettings DreamMakerSettings { get; set; }
[Required]
DreamDaemonSettings DreamDaemonSettings { get; set; }
public DreamDaemonSettings DreamDaemonSettings { get; set; }
[Required]
public RepositorySettings RepositorySettings { get; set; }
/// <summary>
/// The <see cref="InstanceUser"/>s in the <see cref="Instance"/>
@@ -35,9 +38,9 @@ namespace Tgstation.Server.Host.Models
public List<TestMerge> TestMerges { get; set; }
/// <summary>
/// The <see cref="CompileJob"/>s in the <see cref="Instance"/>
/// The <see cref="DbCompileJob"/>s in the <see cref="Instance"/>
/// </summary>
public List<CompileJob> CompileJobs { get; set; }
public List<DbCompileJob> CompileJobs { get; set; }
/// <summary>
/// The <see cref="Jobs"/> in the <see cref="Instance"/>
@@ -0,0 +1,7 @@
namespace Tgstation.Server.Host.Models
{
sealed class InstanceUser : Api.Models.InstanceUser
{
public long Id { get; set; }
}
}
+2 -1
View File
@@ -5,8 +5,9 @@ namespace Tgstation.Server.Host.Models
sealed class Job : Api.Models.Internal.Job
{
[Required]
new public User StartedBy { get; set; }
new public DbUser StartedBy { get; set; }
[Required]
Instance Instance { get; set; }
}
}
@@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;
namespace Tgstation.Server.Host.Models
{
sealed class RepositorySettings : Api.Models.Internal.RepositorySettings
{
public long Id { get; set; }
public long InstanceId { get; set; }
[Required]
public Instance Instance { get; set; }
new public RevisionInformation RevisionInformation { get; set; }
}
}
@@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace Tgstation.Server.Host.Models
{
sealed class RevisionInformation : Api.Models.RevisionInformation
{
public long Id { get; set; }
new public List<TestMerge> TestMerges { get; set; }
}
}
@@ -1,7 +1,9 @@
namespace Tgstation.Server.Host.Models
using System.ComponentModel.DataAnnotations;
namespace Tgstation.Server.Host.Models
{
sealed class ServerSettings : Api.Models.Internal.ServerSettings
{
long Id { get; set; }
public long Id { get; set; }
}
}
@@ -8,6 +8,6 @@ namespace Tgstation.Server.Host.Models
sealed class TestMerge : Api.Models.TestMerge
{
[Required]
new User MergedBy { get; set; }
new public DbUser MergedBy { get; set; }
}
}
-21
View File
@@ -1,21 +0,0 @@
using System.Collections.Generic;
using Tgstation.Server.Api.Models;
namespace Tgstation.Server.Host.Models
{
/// <summary>
/// Represents a <see cref="Api.Models.User"/> in the database
/// </summary>
sealed class User : Api.Models.User
{
/// <summary>
/// The <see cref="InstanceUser"/>s for the <see cref="User"/>
/// </summary>
List<InstanceUser> InstanceUsers { get; set; }
/// <summary>
/// The <see cref="Token"/>s for the <see cref="User"/>
/// </summary>
List<Token> Tokens { get; set; }
}
}
@@ -23,14 +23,20 @@
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.Development.json" />
<Content Include="appsettings.Docker.json" />
<Content Include="appsettings.json" />
<Content Include="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.Docker.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Byond.TopicSender" Version="1.1.0.1" />
<PackageReference Include="Cyberboss.AspNetCore.AsyncInitializer" Version="1.0.2" />
<PackageReference Include="Cyberboss.AspNetCore.AsyncInitializer" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
@@ -19,6 +19,6 @@
},
"Database": {
"DatabaseType": "Sqlite",
"ConnectionString": "Data Source=TestDB.sqlite3;Version=3;"
"ConnectionString": "Data Source=TestDB.sqlite3"
}
}