This commit is contained in:
Cyberboss
2018-04-10 11:07:30 -04:00
parent 399186874e
commit f9799ca51b
34 changed files with 145 additions and 265 deletions
+2 -37
View File
@@ -1,46 +1,11 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Tgstation.Server.Api.Models
namespace Tgstation.Server.Api.Models
{
public class CompileJob
public sealed class CompileJob : Internal.CompileJob
{
/// <summary>
/// The ID of the job
/// </summary>
public long Id { get; set; }
/// <summary>
/// The <see cref="User"/> that triggered the job
/// </summary>
public User TriggeredBy { get; set; }
/// <summary>
/// When the compilation started
/// </summary>
[Required]
public DateTimeOffset StartedAt { get; set; }
/// <summary>
/// When the compilation finished
/// </summary>
public DateTimeOffset FinishedAt { get; set; }
/// <summary>
/// If the compiler targeted the primary directory
/// </summary>
public bool? TargetedPrimaryDirectory { get; set; }
/// <summary>
/// Textual output of DM
/// </summary>
public string Output { get; set; }
/// <summary>
/// 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
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using Tgstation.Server.Api.Models.Internal;
using Tgstation.Server.Api.Models.Internal;
using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Api.Models
@@ -11,6 +9,12 @@ namespace Tgstation.Server.Api.Models
[Model(RightsType.DreamDaemon, CanCrud = true, RequiresInstance = true)]
public sealed class DreamDaemon : DreamDaemonSettings
{
/// <summary>
/// When the live revision was compiled
/// </summary>
[Permissions(DenyWrite = true, ReadRight = DreamDaemonRights.ReadRevision)]
public CompileJob CompileJob { get; set; }
/// <summary>
/// The current status of <see cref="DreamDaemon"/>
/// </summary>
@@ -0,0 +1,39 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Tgstation.Server.Api.Models.Internal
{
public class CompileJob
{
/// <summary>
/// The ID of the job
/// </summary>
public long Id { get; set; }
/// <summary>
/// When the compilation started
/// </summary>
[Required]
public DateTimeOffset StartedAt { get; set; }
/// <summary>
/// When the compilation finished
/// </summary>
public DateTimeOffset FinishedAt { get; set; }
/// <summary>
/// If the compiler targeted the primary directory
/// </summary>
public bool? TargetedPrimaryDirectory { get; set; }
/// <summary>
/// Textual output of DM
/// </summary>
public string Output { get; set; }
/// <summary>
/// Exit code of DM. If <see langword="null"/>, the job was cancelled
/// </summary>
public int? ExitCode { get; set; }
}
}
@@ -1,16 +1,9 @@
using System.ComponentModel.DataAnnotations;
using Tgstation.Server.Api.Rights;
using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Api.Models.Internal
{
public class DreamDaemonSettings
{
/// <summary>
/// When the live revision was compiled
/// </summary>
[Permissions(DenyWrite = true, ReadRight = DreamDaemonRights.ReadRevision)]
public CompileJob CompileJob { get; set; }
/// <summary>
/// If <see cref="DreamDaemon"/> starts when it's <see cref="Instance"/> starts
/// </summary>
@@ -22,9 +22,6 @@ namespace Tgstation.Server.Api.Models.Internal
[Required]
public DateTimeOffset StartedAt { get; set; }
[Required]
public User StartedBy { get; set; }
/// <summary>
/// When the <see cref="Job"/> stopped
/// </summary>
@@ -1,5 +1,4 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Api.Models.Internal
@@ -11,9 +10,6 @@ namespace Tgstation.Server.Api.Models.Internal
/// </summary>
[Permissions(WriteRight = RepositoryRights.SetOrigin)]
public string Origin { get; set; }
[Permissions(DenyWrite = true)]
public RevisionInformation RevisionInformation { get; set; }
/// <summary>
/// The name of the committer
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace Tgstation.Server.Api.Models.Internal
{
public class RevisionInformation
{
[Required, StringLength(40)]
public string Revision { get; set; }
[Required, StringLength(40)]
public string OriginRevision { get; set; }
}
}
@@ -0,0 +1,22 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Tgstation.Server.Api.Models.Internal
{
public class TestMerge
{
public long Id { get; set; }
[Required]
public DateTimeOffset MergedAt { get; set; }
[Required]
public string TitleAtMerge { get; set; }
[Required]
public string BodyAtMerge { get; set; }
[Required]
public string Author { get; set; }
}
}
@@ -1,47 +0,0 @@
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; }
}
}
+2
View File
@@ -15,5 +15,7 @@
/// If the current user has permission to cancel the job
/// </summary>
public bool UserCanCancel { get; set; }
public User StartedBy { get; set; }
}
}
@@ -15,6 +15,9 @@ namespace Tgstation.Server.Api.Models
[Permissions(WriteRight = RepositoryRights.SetSha)]
public string NewRevision { get; set; }
[Permissions(DenyWrite = true)]
public RevisionInformation RevisionInformation { get; set; }
/// <summary>
/// The branch or tag HEAD points to
/// </summary>
@@ -1,17 +1,9 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Tgstation.Server.Api.Models
{
public class RevisionInformation
{
[Required, StringLength(40)]
public string Revision { get; set; }
[Required, StringLength(40)]
public string OriginRevision { get; set; }
public sealed class RevisionInformation : Internal.RevisionInformation
{
public List<TestMerge> TestMerges { get; set; }
}
}
+2 -19
View File
@@ -1,24 +1,7 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Tgstation.Server.Api.Models
namespace Tgstation.Server.Api.Models
{
public class TestMerge : TestMergeParameters
public sealed class TestMerge : Internal.TestMerge
{
public long Id { get; set; }
[Required]
public DateTimeOffset MergedAt { get; set; }
public User MergedBy { get; set; }
[Required]
public string TitleAtMerge { get; set; }
[Required]
public string BodyAtMerge { get; set; }
[Required]
public string Author { get; set; }
}
}
+3 -17
View File
@@ -1,22 +1,8 @@
using System.Net;
namespace Tgstation.Server.Api.Models
namespace Tgstation.Server.Api.Models
{
/// <inheritdoc />
public sealed class Token : Internal.Token
public sealed class Token
{
/// <inheritdoc />
new public IPAddress IssuedTo
{
get => new IPAddress(base.IssuedTo);
set => base.IssuedTo = value.GetAddressBytes();
}
/// <inheritdoc />
new public IPAddress LastUsedBy
{
get => new IPAddress(base.LastUsedBy);
set => base.LastUsedBy = value.GetAddressBytes();
}
public string Value { get; set; }
}
}
@@ -20,12 +20,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.ComponentModel.Annotations">
<HintPath>..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\system.componentmodel.annotations\4.4.0\ref\netstandard2.0\System.ComponentModel.Annotations.dll</HintPath>
</Reference>
<PackageReference Include="System.ComponentModel.Annotations" Version="4.4.1" />
</ItemGroup>
</Project>
@@ -1,57 +0,0 @@
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
{
/// <summary>
/// <see cref="IServerClient"/> for managing <see cref="Token"/>s
/// </summary>
public interface ITokenClient: IRightsClient<TokenRights>
{
/// <summary>
/// Generate a new <see cref="Token"/> for the connected user/ipaddress, deleting the current one if applicable
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the new <see cref="Token"/></returns>
Task<Token> Read(CancellationToken cancellationToken);
/// <summary>
/// Gets all active <see cref="Token"/>s for the <see cref="IServerClient"/>
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting a <see cref="IReadOnlyList{T}"/> of active <see cref="Token"/>s for the <see cref="IServerClient"/></returns>
Task<IReadOnlyList<Token>> GetClientInfos(CancellationToken cancellationToken);
/// <summary>
/// Gets all active <see cref="Token"/>s for all users
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting a <see cref="IReadOnlyDictionary{TKey, TValue}"/> of active <see cref="Token"/>s for the <see cref="IServerClient"/> keyed by username</returns>
Task<IReadOnlyDictionary<string, Token>> GetAllInfos(CancellationToken cancellationToken);
/// <summary>
/// Invalidate the specified active <paramref name="token"/>
/// </summary>
/// <param name="token">The <see cref="Token"/> to invalidate</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task Invalidate(Token token, CancellationToken cancellationToken);
/// <summary>
/// Invalidate all active <see cref="Token"/>s for a <see cref="IServerClient"/>
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task InvalidateAllClient(CancellationToken cancellationToken);
/// <summary>
/// Invalidate all active <see cref="Token"/>s
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the running operation</returns>
Task InvalidateAll(CancellationToken cancellationToken);
}
}
@@ -30,11 +30,6 @@ namespace Tgstation.Server.Client
/// </summary>
int RequeryRate { get; set; }
/// <summary>
/// Access the <see cref="ITokenClient"/>
/// </summary>
ITokenClient Tokens { get; }
/// <summary>
/// Access the <see cref="IInstanceManagerClient"/>
/// </summary>
@@ -99,7 +99,7 @@ namespace Tgstation.Server.Host.Core
public void Dispose() => SystemIdentity.Dispose();
/// <inheritdoc />
public Task<DbUser> User(CancellationToken cancellationToken)
public Task<User> 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<DbUser> User(CancellationToken cancellationToken);
Task<User> User(CancellationToken cancellationToken);
/// <summary>
/// The <see cref="Api.Models.InstanceUser"/> represented by <see cref="User"/> and a given <paramref name="instance"/>
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace Tgstation.Server.Host.Models
{
sealed class CompileJob : Api.Models.Internal.CompileJob
{
[Required]
public User TriggeredBy { get; set; }
[Required]
public RevisionInformation RevisionInformation { get; set; }
}
}
@@ -17,7 +17,7 @@ namespace Tgstation.Server.Host.Models
public DbSet<ServerSettings> ServerSettings { get; set; }
/// <inheritdoc />
public DbSet<DbUser> Users { get; set; }
public DbSet<User> Users { get; set; }
/// <inheritdoc />
public DbSet<Instance> Instances { get; set; }
@@ -31,9 +31,8 @@ namespace Tgstation.Server.Host.Models
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<CompileJob> 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; }
@@ -75,6 +74,7 @@ namespace Tgstation.Server.Host.Models
modelBuilder.Entity<Log>().ToTable(nameof(Logs));
modelBuilder.Entity<RevisionInformation>().HasIndex(x => x.Revision).IsUnique();
modelBuilder.Entity<User>().HasIndex(x => x.SystemIdentifier).IsUnique();
}
/// <inheritdoc />
@@ -1,13 +0,0 @@
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; }
}
}
@@ -8,13 +8,13 @@ namespace Tgstation.Server.Host.Models
public int? ProcessId { get; set; }
public long InstanceId { get; set; }
public string AccessToken { get; set; }
public long InstanceId { get; set; }
[Required]
public Instance Instance { get; set; }
new public DbCompileJob CompileJob { get; set; }
public CompileJob CompileJob { get; set; }
}
}
@@ -11,6 +11,6 @@ namespace Tgstation.Server.Host.Models
[Required]
public Instance Instance { get; set; }
public DbCompileJob CompileJob { get; set; }
public CompileJob CompileJob { get; set; }
}
}
@@ -10,9 +10,9 @@ namespace Tgstation.Server.Host.Models
interface IDatabaseContext
{
/// <summary>
/// The <see cref="DbUser"/>s in the <see cref="IDatabaseContext"/>
/// The <see cref="User"/>s in the <see cref="IDatabaseContext"/>
/// </summary>
DbSet<DbUser> Users { get; }
DbSet<User> Users { get; }
/// <summary>
/// The <see cref="Instances"/>s in the <see cref="IDatabaseContext"/>
+2 -2
View File
@@ -38,9 +38,9 @@ namespace Tgstation.Server.Host.Models
public List<TestMerge> TestMerges { get; set; }
/// <summary>
/// The <see cref="DbCompileJob"/>s in the <see cref="Instance"/>
/// The <see cref="CompileJob"/>s in the <see cref="Instance"/>
/// </summary>
public List<DbCompileJob> CompileJobs { get; set; }
public List<CompileJob> CompileJobs { get; set; }
/// <summary>
/// The <see cref="Jobs"/> in the <see cref="Instance"/>
+2 -2
View File
@@ -5,9 +5,9 @@ namespace Tgstation.Server.Host.Models
sealed class Job : Api.Models.Internal.Job
{
[Required]
new public DbUser StartedBy { get; set; }
public User StartedBy { get; set; }
[Required]
Instance Instance { get; set; }
public Instance Instance { get; set; }
}
}
@@ -11,6 +11,6 @@ namespace Tgstation.Server.Host.Models
[Required]
public Instance Instance { get; set; }
new public RevisionInformation RevisionInformation { get; set; }
public RevisionInformation RevisionInformation { get; set; }
}
}
@@ -2,10 +2,10 @@
namespace Tgstation.Server.Host.Models
{
sealed class RevisionInformation : Api.Models.RevisionInformation
sealed class RevisionInformation : Api.Models.Internal.RevisionInformation
{
public long Id { get; set; }
new public List<TestMerge> TestMerges { get; set; }
public List<TestMerge> TestMerges { get; set; }
}
}
@@ -5,5 +5,11 @@ namespace Tgstation.Server.Host.Models
sealed class ServerSettings : Api.Models.Internal.ServerSettings
{
public long Id { get; set; }
/// <summary>
/// The value used for the <see cref="SymmetricSecurityKey"/> to encrypt JWTs
/// </summary>
[Required]
public byte[] TokenSecret { get; set; }
}
}
@@ -5,9 +5,9 @@ namespace Tgstation.Server.Host.Models
/// <summary>
/// Represent a merge of a live pull request
/// </summary>
sealed class TestMerge : Api.Models.TestMerge
sealed class TestMerge : Api.Models.Internal.TestMerge
{
[Required]
new public DbUser MergedBy { get; set; }
public User MergedBy { get; set; }
}
}
@@ -1,25 +1,19 @@
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
sealed class User : Api.Models.User
{
public string PasswordHash { get; set; }
public string PasswordSalt { get; set; }
/// <summary>
/// The <see cref="InstanceUser"/>s for the <see cref="DbUser"/>
/// The <see cref="InstanceUser"/>s for the <see cref="User"/>
/// </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; }
}
}
@@ -37,15 +37,14 @@
<ItemGroup>
<PackageReference Include="Byond.TopicSender" Version="1.1.0.1" />
<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" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0-preview2-final" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="6.10.6" />
<PackageReference Include="Octokit" Version="0.29.0" />
<PackageReference Include="System.Security.Principal.Windows" Version="4.4.1" />
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="1.7.16" />
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="1.7.17" />
<PackageReference Include="ZNetCS.AspNetCore.Logging.EntityFrameworkCore" Version="2.0.1" />
</ItemGroup>
@@ -75,7 +75,7 @@
<Name>Tgstation.Server.Host.Service</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Tgstation.Server.Host.Watchdog\Tgstation.Server.Host.Watchdog.csproj">
<Project>{5D2D682C-6BF0-439C-850B-6AB945BBEAEA}</Project>
<Project>{5d2d682c-6bf0-439c-850b-6ab945bbeaea}</Project>
<Name>Tgstation.Server.Host.Watchdog</Name>
</ProjectReference>
</ItemGroup>