syntax updates

This commit is contained in:
Kevin Kai Berthold 2023-09-22 22:16:56 +02:00
parent 283fa1abc2
commit 1e05d4576d
75 changed files with 3821 additions and 3905 deletions

View file

@ -1,14 +1,13 @@
namespace Insight.Infrastructure
{
public class Appsettings
{
public const string Database = "database";
public const string JwtKey = "jwt.key";
public const string JwtAudience = "jwt.audience";
public const string JwtIssuer = "jwt.issuer";
public const string JwtExp = "jwt.exp";
namespace Insight.Infrastructure;
public const string ServerHost = "server.host";
public const string ServerPort = "server.port";
}
public class Appsettings
{
public const string Database = "database";
public const string JwtKey = "jwt.key";
public const string JwtAudience = "jwt.audience";
public const string JwtIssuer = "jwt.issuer";
public const string JwtExp = "jwt.exp";
public const string ServerHost = "server.host";
public const string ServerPort = "server.port";
}

View file

@ -1,8 +1,7 @@
namespace Insight.Infrastructure
namespace Insight.Infrastructure;
public static class Monitoring
{
public static class Monitoring
{
public static readonly Uri StatusUri = new("https://admin.webmatic.de/monitoring/computer/send/status");
public static readonly Uri LogUri = new("https://admin.webmatic.de/monitoring/computer/send/log");
}
public static readonly Uri StatusUri = new("https://admin.webmatic.de/monitoring/computer/send/status");
public static readonly Uri LogUri = new("https://admin.webmatic.de/monitoring/computer/send/log");
}

View file

@ -1,7 +1,6 @@
namespace Insight.Infrastructure
namespace Insight.Infrastructure;
public class Settings
{
public class Settings
{
public const string Database = "insight";
}
public const string Database = "insight";
}

View file

@ -3,60 +3,59 @@ using MongoDB.Bson.Serialization.Attributes;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class AgentEntity
{
[BsonIgnoreExtraElements]
public class AgentEntity
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("serial"), Required]
public string? Serial { get; set; }
[BsonElement("hostname")]
public string? Hostname { get; set; }
[BsonElement("version"), BsonRepresentation(BsonType.String)]
public Version? Version { get; set; }
[BsonElement("endpoint"), BsonRepresentation(BsonType.String)]
public string? Endpoint { get; set; }
[BsonElement("connected")]
public DateTime? Connected { get; set; }
[BsonElement("activity")]
public DateTime? Activity { get; set; }
[BsonElement("bytes_sent")]
public long SentBytes { get; set; }
[BsonElement("bytes_received")]
public long ReceivedBytes { get; set; }
[BsonElement("packets_sent")]
public long SentPackets { get; set; }
[BsonElement("packets_received")]
public long ReceivedPackets { get; set; }
//[BsonElement("latency")]
//public TimeSpan? Latency { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<HostEntity>? Hosts { get; set; }
public bool GetOnlineState()
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("serial"), Required]
public string? Serial { get; set; }
[BsonElement("hostname")]
public string? Hostname { get; set; }
[BsonElement("version"), BsonRepresentation(BsonType.String)]
public Version? Version { get; set; }
[BsonElement("endpoint"), BsonRepresentation(BsonType.String)]
public string? Endpoint { get; set; }
[BsonElement("connected")]
public DateTime? Connected { get; set; }
[BsonElement("activity")]
public DateTime? Activity { get; set; }
[BsonElement("bytes_sent")]
public long SentBytes { get; set; }
[BsonElement("bytes_received")]
public long ReceivedBytes { get; set; }
[BsonElement("packets_sent")]
public long SentPackets { get; set; }
[BsonElement("packets_received")]
public long ReceivedPackets { get; set; }
//[BsonElement("latency")]
//public TimeSpan? Latency { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<HostEntity>? Hosts { get; set; }
public bool GetOnlineState()
{
if (Activity is null) return false;
return Activity.Value.ToLocalTime().Add(TimeSpan.FromSeconds(60)).Subtract(DateTime.Now).Seconds > 0;
}
if (Activity is null) return false;
return Activity.Value.ToLocalTime().Add(TimeSpan.FromSeconds(60)).Subtract(DateTime.Now).Seconds > 0;
}
}

View file

@ -2,36 +2,35 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class AgentLogEntity
{
[BsonIgnoreExtraElements]
public class AgentLogEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_agent"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("agent")]
public string? Agent { get; set; }
[BsonElement("_agent"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("agent")]
public string? Agent { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("eventid")]
public string? EventId { get; set; }
[BsonElement("eventid")]
public string? EventId { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("source")]
public string? Source { get; set; }
[BsonElement("source")]
public string? Source { get; set; }
[BsonElement("category")]
public string? Category { get; set; }
[BsonElement("category")]
public string? Category { get; set; }
[BsonElement("message")]
public string? Message { get; set; }
[BsonElement("message")]
public string? Message { get; set; }
[BsonElement("timestamp")]
public DateTime? Timestamp { get; set; }
}
[BsonElement("timestamp")]
public DateTime? Timestamp { get; set; }
}

View file

@ -3,27 +3,26 @@ using MongoDB.Bson.Serialization.Attributes;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class CustomerEntity
{
[BsonIgnoreExtraElements]
public class CustomerEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("name"), Required]
public string? Name { get; set; }
[BsonElement("name"), Required]
public string? Name { get; set; }
[BsonElement("tag")]
public string? Tag { get; set; }
[BsonElement("tag")]
public string? Tag { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<HostEntity>? Hosts { get; set; }
}
[BsonIgnoreIfNull, JsonIgnore]
public List<HostEntity>? Hosts { get; set; }
}

View file

@ -3,36 +3,35 @@ using MongoDB.Bson.Serialization.Attributes;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostEntity
{
[BsonIgnoreExtraElements]
public class HostEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_customer"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("customer")]
public string? Customer { get; set; }
[BsonElement("_customer"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("customer")]
public string? Customer { get; set; }
[BsonElement("_agent"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("agent")]
public string? Agent { get; set; }
[BsonElement("_agent"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("agent")]
public string? Agent { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("name"), Required]
public string? Name { get; set; }
[BsonElement("name"), Required]
public string? Name { get; set; }
[BsonElement("description")]
public string? Description { get; set; }
[BsonElement("description")]
public string? Description { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<CustomerEntity>? Customers { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<CustomerEntity>? Customers { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<AgentEntity>? Agents { get; set; }
}
[BsonIgnoreIfNull, JsonIgnore]
public List<AgentEntity>? Agents { get; set; }
}

View file

@ -2,39 +2,38 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostApplicationEntity
{
[BsonIgnoreExtraElements]
public class HostApplicationEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("architecture")]
public string? Architecture { get; set; }
[BsonElement("architecture")]
public string? Architecture { get; set; }
[BsonElement("version")]
public string? Version { get; set; }
[BsonElement("version")]
public string? Version { get; set; }
[BsonElement("installdate")]
public DateTime? InstallDate { get; set; }
}
[BsonElement("installdate")]
public DateTime? InstallDate { get; set; }
}

View file

@ -2,51 +2,50 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostDriveEntity
{
[BsonIgnoreExtraElements]
public class HostDriveEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("index")]
public uint? Index { get; set; }
[BsonElement("index")]
public uint? Index { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("size")]
public ulong? Size { get; set; }
[BsonElement("size")]
public ulong? Size { get; set; }
[BsonElement("type")]
public string? Type { get; set; }
[BsonElement("type")]
public string? Type { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; }
[BsonElement("firmware")]
public string? Firmware { get; set; }
[BsonElement("firmware")]
public string? Firmware { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("pnp")]
public string? Pnp { get; set; }
}
[BsonElement("pnp")]
public string? Pnp { get; set; }
}

View file

@ -2,187 +2,186 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostHypervisorVirtualMaschineEntity
{
[BsonIgnoreExtraElements]
public class HostHypervisorVirtualMaschineEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("uniqueid")]
public string? UniqueId { get; set; }
[BsonElement("uniqueid")]
public string? UniqueId { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("notes")]
public string? Notes { get; set; }
[BsonElement("notes")]
public string? Notes { get; set; }
[BsonElement("enabled")]
public string? Enabled { get; set; }
[BsonElement("enabled")]
public string? Enabled { get; set; }
[BsonElement("enabled_default")]
public string? EnabledDefault { get; set; }
[BsonElement("enabled_default")]
public string? EnabledDefault { get; set; }
[BsonElement("health")]
public string? Health { get; set; }
[BsonElement("health")]
public string? Health { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("ontime")]
public ulong? OnTime { get; set; }
[BsonElement("ontime")]
public ulong? OnTime { get; set; }
[BsonElement("replication_state")]
public string? ReplicationState { get; set; }
[BsonElement("replication_state")]
public string? ReplicationState { get; set; }
[BsonElement("replication_health")]
public string? ReplicationHealth { get; set; }
[BsonElement("replication_health")]
public string? ReplicationHealth { get; set; }
[BsonElement("version_configuration")]
public string? ConfigurationVersion { get; set; }
[BsonElement("version_configuration")]
public string? ConfigurationVersion { get; set; }
[BsonElement("version_integrated_services")]
public string? IntegrationServicesVersionState { get; set; }
[BsonElement("version_integrated_services")]
public string? IntegrationServicesVersionState { get; set; }
[BsonElement("processid")]
public uint? ProcessId { get; set; }
[BsonElement("processid")]
public uint? ProcessId { get; set; }
[BsonElement("processor_count")]
public uint? NumberOfProcessors { get; set; }
[BsonElement("processor_count")]
public uint? NumberOfProcessors { get; set; }
[BsonElement("processor_load")]
public uint? ProcessorLoad { get; set; }
[BsonElement("processor_load")]
public uint? ProcessorLoad { get; set; }
[BsonElement("memory_available")]
public int? MemoryAvailable { get; set; }
[BsonElement("memory_available")]
public int? MemoryAvailable { get; set; }
[BsonElement("memory_usage")]
public ulong? MemoryUsage { get; set; }
[BsonElement("memory_usage")]
public ulong? MemoryUsage { get; set; }
[BsonElement("installdate")]
public DateTime? InstallDate { get; set; }
[BsonElement("installdate")]
public DateTime? InstallDate { get; set; }
[BsonElement("configuration_changed")]
public DateTime? TimeOfLastConfigurationChange { get; set; }
[BsonElement("configuration_changed")]
public DateTime? TimeOfLastConfigurationChange { get; set; }
[BsonElement("state_changed")]
public DateTime? TimeOfLastStateChange { get; set; }
[BsonElement("state_changed")]
public DateTime? TimeOfLastStateChange { get; set; }
[BsonElement("replication_last")]
public DateTime? LastReplicationTime { get; set; }
[BsonElement("replication_last")]
public DateTime? LastReplicationTime { get; set; }
[BsonElement("guest_os")]
public string? Os { get; set; }
[BsonElement("guest_os")]
public string? Os { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<HostHypervisorVirtualMaschineConfigEntity>? Configs { get; set; }
}
[BsonIgnoreIfNull, JsonIgnore]
public List<HostHypervisorVirtualMaschineConfigEntity>? Configs { get; set; }
}
[BsonIgnoreExtraElements]
public class HostHypervisorVirtualMaschineConfigEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonIgnoreExtraElements]
public class HostHypervisorVirtualMaschineConfigEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("virtualmaschine"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("virtualmaschine")]
public string? VirtualMaschine { get; set; }
[BsonElement("virtualmaschine"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("virtualmaschine")]
public string? VirtualMaschine { get; set; }
[BsonElement("batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("uniqueid")]
public string? UniqueId { get; set; }
[BsonElement("uniqueid")]
public string? UniqueId { get; set; }
[BsonElement("parentid")]
public string? ParentId { get; set; }
[BsonElement("parentid")]
public string? ParentId { get; set; }
[BsonElement("type")]
public string? Type { get; set; }
[BsonElement("type")]
public string? Type { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("notes")]
public string? Notes { get; set; }
[BsonElement("notes")]
public string? Notes { get; set; }
[BsonElement("creationtime")]
public DateTime? CreationTime { get; set; }
[BsonElement("creationtime")]
public DateTime? CreationTime { get; set; }
[BsonElement("generation")]
public string? Generation { get; set; }
[BsonElement("generation")]
public string? Generation { get; set; }
[BsonElement("architecture")]
public string? Architecture { get; set; }
[BsonElement("architecture")]
public string? Architecture { get; set; }
[BsonElement("secureboot")]
public bool? SecureBootEnabled { get; set; }
[BsonElement("secureboot")]
public bool? SecureBootEnabled { get; set; }
[BsonElement("automatic_snapshot")]
public bool? IsAutomaticSnapshot { get; set; }
[BsonElement("automatic_snapshot")]
public bool? IsAutomaticSnapshot { get; set; }
[BsonElement("action_start")]
public string? AutomaticStartupAction { get; set; }
[BsonElement("action_start")]
public string? AutomaticStartupAction { get; set; }
[BsonElement("action_shutdown")]
public string? AutomaticShutdownAction { get; set; }
[BsonElement("action_shutdown")]
public string? AutomaticShutdownAction { get; set; }
[BsonElement("action_recovery")]
public string? AutomaticRecoveryAction { get; set; }
[BsonElement("action_recovery")]
public string? AutomaticRecoveryAction { get; set; }
[BsonElement("auto_snapshots")]
public bool? AutomaticSnapshotsEnabled { get; set; }
[BsonElement("auto_snapshots")]
public bool? AutomaticSnapshotsEnabled { get; set; }
[BsonElement("serial_mainboard")]
public string? BaseBoardSerialNumber { get; set; }
[BsonElement("serial_mainboard")]
public string? BaseBoardSerialNumber { get; set; }
[BsonElement("serial_bios")]
public string? BIOSSerialNumber { get; set; }
[BsonElement("serial_bios")]
public string? BIOSSerialNumber { get; set; }
[BsonElement("bios_guid")]
public string? BIOSGUID { get; set; }
[BsonElement("bios_guid")]
public string? BIOSGUID { get; set; }
[BsonElement("data_root")]
public string? ConfigurationDataRoot { get; set; }
[BsonElement("data_root")]
public string? ConfigurationDataRoot { get; set; }
[BsonElement("file")]
public string? ConfigurationFile { get; set; }
[BsonElement("file")]
public string? ConfigurationFile { get; set; }
[BsonElement("guest_data_root")]
public string? GuestStateDataRoot { get; set; }
[BsonElement("guest_data_root")]
public string? GuestStateDataRoot { get; set; }
[BsonElement("guest_state_file")]
public string? GuestStateFile { get; set; }
[BsonElement("guest_state_file")]
public string? GuestStateFile { get; set; }
[BsonElement("snapshot_data_root")]
public string? SnapshotDataRoot { get; set; }
[BsonElement("snapshot_data_root")]
public string? SnapshotDataRoot { get; set; }
[BsonElement("suspend_data_root")]
public string? SuspendDataRoot { get; set; }
[BsonElement("suspend_data_root")]
public string? SuspendDataRoot { get; set; }
[BsonElement("swap_data_root")]
public string? SwapFileDataRoot { get; set; }
}
[BsonElement("swap_data_root")]
public string? SwapFileDataRoot { get; set; }
}

View file

@ -2,217 +2,216 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostInterfaceEntity
{
[BsonIgnoreExtraElements]
public class HostInterfaceEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("index")]
public uint? Index { get; set; }
[BsonElement("index")]
public uint? Index { get; set; }
[BsonElement("mac")]
public string? Mac { get; set; }
[BsonElement("mac")]
public string? Mac { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("description")]
public string? Description { get; set; }
[BsonElement("description")]
public string? Description { get; set; }
[BsonElement("physical")]
public bool? Physical { get; set; }
[BsonElement("physical")]
public bool? Physical { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("suffix")]
public string? Suffix { get; set; }
[BsonElement("suffix")]
public string? Suffix { get; set; }
[BsonElement("speed")]
public long? Speed { get; set; }
[BsonElement("speed")]
public long? Speed { get; set; }
[BsonElement("ipv4_mtu")]
public long? Ipv4Mtu { get; set; }
[BsonElement("ipv4_mtu")]
public long? Ipv4Mtu { get; set; }
[BsonElement("ipv4_dhcp")]
public bool? Ipv4Dhcp { get; set; }
[BsonElement("ipv4_dhcp")]
public bool? Ipv4Dhcp { get; set; }
[BsonElement("ipv4_forwarding")]
public bool? Ipv4Forwarding { get; set; }
[BsonElement("ipv4_forwarding")]
public bool? Ipv4Forwarding { get; set; }
[BsonElement("ipv6_mtu")]
public long? Ipv6Mtu { get; set; }
[BsonElement("ipv6_mtu")]
public long? Ipv6Mtu { get; set; }
[BsonElement("sent")]
public long? Sent { get; set; }
[BsonElement("sent")]
public long? Sent { get; set; }
[BsonElement("received")]
public long? Received { get; set; }
[BsonElement("received")]
public long? Received { get; set; }
[BsonElement("packets_incoming_discarded")]
public long? IncomingPacketsDiscarded { get; set; }
[BsonElement("packets_incoming_discarded")]
public long? IncomingPacketsDiscarded { get; set; }
[BsonElement("packets_incoming_errors")]
public long? IncomingPacketsWithErrors { get; set; }
[BsonElement("packets_incoming_errors")]
public long? IncomingPacketsWithErrors { get; set; }
[BsonElement("packets_incoming_unknown")]
public long? IncomingUnknownProtocolPackets { get; set; }
[BsonElement("packets_incoming_unknown")]
public long? IncomingUnknownProtocolPackets { get; set; }
[BsonElement("packets_outgoing_discarded")]
public long? OutgoingPacketsDiscarded { get; set; }
[BsonElement("packets_outgoing_discarded")]
public long? OutgoingPacketsDiscarded { get; set; }
[BsonElement("packets_outgoing_errors")]
public long? OutgoingPacketsWithErrors { get; set; }
}
[BsonElement("packets_outgoing_errors")]
public long? OutgoingPacketsWithErrors { get; set; }
}
[BsonIgnoreExtraElements]
public class HostInterfaceAddressEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonIgnoreExtraElements]
public class HostInterfaceAddressEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_interface"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("interface")]
public string? Interface { get; set; }
[BsonElement("_interface"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("interface")]
public string? Interface { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("address")]
public string? Address { get; set; }
[BsonElement("address")]
public string? Address { get; set; }
[BsonElement("mask")]
public string? Mask { get; set; }
[BsonElement("mask")]
public string? Mask { get; set; }
//public string? State { get; set; }
//public long? PreferredLifetime { get; set; }
//public long? ValidLifetime { get; set; }
//public long? LeaseLifetime { get; set; }
//public int? PrefixLength { get; set; }
//public string? State { get; set; }
//public long? PreferredLifetime { get; set; }
//public long? ValidLifetime { get; set; }
//public long? LeaseLifetime { get; set; }
//public int? PrefixLength { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<HostInterfaceEntity>? Interfaces { get; set; }
}
[BsonIgnoreIfNull, JsonIgnore]
public List<HostInterfaceEntity>? Interfaces { get; set; }
}
[BsonIgnoreExtraElements]
public class HostInterfaceGatewayEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonIgnoreExtraElements]
public class HostInterfaceGatewayEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_interface"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("interface")]
public string? Interface { get; set; }
[BsonElement("_interface"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("interface")]
public string? Interface { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("address")]
public string? Address { get; set; }
[BsonElement("address")]
public string? Address { get; set; }
[BsonElement("mask")]
public string? Mask { get; set; }
[BsonElement("mask")]
public string? Mask { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<HostInterfaceEntity>? Interfaces { get; set; }
}
[BsonIgnoreIfNull, JsonIgnore]
public List<HostInterfaceEntity>? Interfaces { get; set; }
}
[BsonIgnoreExtraElements]
public class HostInterfaceNameserverEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonIgnoreExtraElements]
public class HostInterfaceNameserverEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_interface"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("interface")]
public string? Interface { get; set; }
[BsonElement("_interface"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("interface")]
public string? Interface { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("address")]
public string? Address { get; set; }
[BsonElement("address")]
public string? Address { get; set; }
[BsonElement("mask")]
public string? Mask { get; set; }
[BsonElement("mask")]
public string? Mask { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<HostInterfaceEntity>? Interfaces { get; set; }
}
[BsonIgnoreIfNull, JsonIgnore]
public List<HostInterfaceEntity>? Interfaces { get; set; }
}
[BsonIgnoreExtraElements]
public class HostInterfaceRouteEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonIgnoreExtraElements]
public class HostInterfaceRouteEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_interface"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("interface")]
public string? Interface { get; set; }
[BsonElement("_interface"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("interface")]
public string? Interface { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("destination")]
public string? Destination { get; set; }
[BsonElement("destination")]
public string? Destination { get; set; }
[BsonElement("mask")]
public string? Mask { get; set; }
[BsonElement("mask")]
public string? Mask { get; set; }
[BsonElement("gateway")]
public string? Gateway { get; set; }
[BsonElement("gateway")]
public string? Gateway { get; set; }
[BsonElement("metric")]
public int? Metric { get; set; }
[BsonElement("metric")]
public int? Metric { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<HostInterfaceEntity>? Interfaces { get; set; }
}
[BsonIgnoreIfNull, JsonIgnore]
public List<HostInterfaceEntity>? Interfaces { get; set; }
}

View file

@ -2,36 +2,35 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostLogEntity
{
[BsonIgnoreExtraElements]
public class HostLogEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("eventid")]
public string? EventId { get; set; }
[BsonElement("eventid")]
public string? EventId { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("source")]
public string? Source { get; set; }
[BsonElement("source")]
public string? Source { get; set; }
[BsonElement("category")]
public string? Category { get; set; }
[BsonElement("category")]
public string? Category { get; set; }
[BsonElement("message")]
public string? Message { get; set; }
[BsonElement("message")]
public string? Message { get; set; }
[BsonElement("timestamp")]
public DateTime? Timestamp { get; set; }
}
[BsonElement("timestamp")]
public DateTime? Timestamp { get; set; }
}

View file

@ -2,42 +2,41 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostLogMonitoringEntity
{
[BsonIgnoreExtraElements]
public class HostLogMonitoringEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("hostname")]
public string? Hostname { get; set; }
[BsonElement("hostname")]
public string? Hostname { get; set; }
[BsonElement("category")]
public string? Category { get; set; }
[BsonElement("category")]
public string? Category { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("task")]
public string? Task { get; set; }
[BsonElement("task")]
public string? Task { get; set; }
[BsonElement("message")]
public string? Message { get; set; }
[BsonElement("message")]
public string? Message { get; set; }
[BsonElement("dispatch")]
public string? Dispatch { get; set; }
[BsonElement("dispatch")]
public string? Dispatch { get; set; }
[BsonElement("timestamp")]
public DateTime? Timestamp { get; set; }
}
[BsonElement("timestamp")]
public DateTime? Timestamp { get; set; }
}

View file

@ -2,39 +2,38 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostMainboardEntity
{
[BsonIgnoreExtraElements]
public class HostMainboardEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; }
[BsonElement("bios")]
public string? Bios { get; set; }
[BsonElement("bios")]
public string? Bios { get; set; }
[BsonElement("version")]
public string? Version { get; set; }
[BsonElement("version")]
public string? Version { get; set; }
[BsonElement("Date")]
public DateTime? Date { get; set; }
}
[BsonElement("Date")]
public DateTime? Date { get; set; }
}

View file

@ -2,57 +2,56 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostMemoryEntity
{
[BsonIgnoreExtraElements]
public class HostMemoryEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("index")]
public uint? Index { get; set; }
[BsonElement("index")]
public uint? Index { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("tag")]
public string? Tag { get; set; }
[BsonElement("tag")]
public string? Tag { get; set; }
[BsonElement("location")]
public string? Location { get; set; }
[BsonElement("location")]
public string? Location { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; }
[BsonElement("capacity")]
public ulong? Capacity { get; set; }
[BsonElement("capacity")]
public ulong? Capacity { get; set; }
[BsonElement("clock")]
public uint? Clock { get; set; }
[BsonElement("clock")]
public uint? Clock { get; set; }
[BsonElement("clock_current")]
public uint? CurrentClock { get; set; }
[BsonElement("clock_current")]
public uint? CurrentClock { get; set; }
[BsonElement("voltage")]
public uint? Voltage { get; set; }
[BsonElement("voltage")]
public uint? Voltage { get; set; }
[BsonElement("voltage_current")]
public uint? CurrentVoltage { get; set; }
}
[BsonElement("voltage_current")]
public uint? CurrentVoltage { get; set; }
}

View file

@ -2,39 +2,38 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostOsEntity
{
[BsonIgnoreExtraElements]
public class HostOsEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("version")]
public string? Version { get; set; }
[BsonElement("version")]
public string? Version { get; set; }
[BsonElement("architecture")]
public string? Architecture { get; set; }
[BsonElement("architecture")]
public string? Architecture { get; set; }
[BsonElement("serialnumber")]
public string? SerialNumber { get; set; }
[BsonElement("serialnumber")]
public string? SerialNumber { get; set; }
[BsonElement("virtual")]
public bool? Virtual { get; set; }
[BsonElement("virtual")]
public bool? Virtual { get; set; }
[BsonElement("installed")]
public DateTime? Installed { get; set; }
}
[BsonElement("installed")]
public DateTime? Installed { get; set; }
}

View file

@ -2,39 +2,38 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostPrinterEntity
{
[BsonIgnoreExtraElements]
public class HostPrinterEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("port")]
public string? Port { get; set; }
[BsonElement("port")]
public string? Port { get; set; }
[BsonElement("location")]
public string? Location { get; set; }
[BsonElement("location")]
public string? Location { get; set; }
[BsonElement("comment")]
public string? Comment { get; set; }
}
[BsonElement("comment")]
public string? Comment { get; set; }
}

View file

@ -2,69 +2,68 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostProcessorEntity
{
[BsonIgnoreExtraElements]
public class HostProcessorEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("index")]
public uint? Index { get; set; }
[BsonElement("index")]
public uint? Index { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("socket")]
public string? Socket { get; set; }
[BsonElement("socket")]
public string? Socket { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; }
[BsonElement("version")]
public string? Version { get; set; }
[BsonElement("version")]
public string? Version { get; set; }
[BsonElement("cores")]
public uint? Cores { get; set; }
[BsonElement("cores")]
public uint? Cores { get; set; }
[BsonElement("logicalcores")]
public uint? LogicalCores { get; set; }
[BsonElement("logicalcores")]
public uint? LogicalCores { get; set; }
[BsonElement("clock")]
public uint? Clock { get; set; }
[BsonElement("clock")]
public uint? Clock { get; set; }
[BsonElement("clock_current")]
public uint? CurrentClock { get; set; }
[BsonElement("clock_current")]
public uint? CurrentClock { get; set; }
[BsonElement("l1")]
public uint? L1Size { get; set; }
[BsonElement("l1")]
public uint? L1Size { get; set; }
[BsonElement("l2")]
public uint? L2Size { get; set; }
[BsonElement("l2")]
public uint? L2Size { get; set; }
[BsonElement("l3")]
public uint? L3Size { get; set; }
[BsonElement("l3")]
public uint? L3Size { get; set; }
[BsonElement("virtualization")]
public bool? Virtualization { get; set; }
[BsonElement("virtualization")]
public bool? Virtualization { get; set; }
[BsonElement("pnp")]
public string? PNP { get; set; }
}
[BsonElement("pnp")]
public string? PNP { get; set; }
}

View file

@ -2,54 +2,53 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostServiceEntity
{
[BsonIgnoreExtraElements]
public class HostServiceEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("displayname")]
public string? DisplayName { get; set; }
[BsonElement("displayname")]
public string? DisplayName { get; set; }
[BsonElement("description")]
public string? Description { get; set; }
[BsonElement("description")]
public string? Description { get; set; }
[BsonElement("startmode")]
public string? StartMode { get; set; }
[BsonElement("startmode")]
public string? StartMode { get; set; }
[BsonElement("state")]
public string? State { get; set; }
[BsonElement("state")]
public string? State { get; set; }
[BsonElement("processid")]
public uint? ProcessId { get; set; }
[BsonElement("processid")]
public uint? ProcessId { get; set; }
[BsonElement("delay")]
public bool? Delay { get; set; }
[BsonElement("delay")]
public bool? Delay { get; set; }
[BsonElement("path")]
public string? Path { get; set; }
[BsonElement("path")]
public string? Path { get; set; }
[BsonElement("account")]
public string? Account { get; set; }
}
[BsonElement("account")]
public string? Account { get; set; }
}

View file

@ -2,39 +2,38 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostSessionEntity
{
[BsonIgnoreExtraElements]
public class HostSessionEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("sid")]
public string? Sid { get; set; }
[BsonElement("sid")]
public string? Sid { get; set; }
[BsonElement("user")]
public string? User { get; set; }
[BsonElement("user")]
public string? User { get; set; }
[BsonElement("remote")]
public string? Remote { get; set; }
[BsonElement("remote")]
public string? Remote { get; set; }
[BsonElement("type")]
public string? Type { get; set; }
[BsonElement("type")]
public string? Type { get; set; }
[BsonElement("state")]
public string? State { get; set; }
}
[BsonElement("state")]
public string? State { get; set; }
}

View file

@ -2,206 +2,205 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostStoragePoolEntity
{
[BsonIgnoreExtraElements]
public class HostStoragePoolEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("uniqueid")]
public string? UniqueId { get; set; }
[BsonElement("uniqueid")]
public string? UniqueId { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("health")]
public string? Health { get; set; }
[BsonElement("health")]
public string? Health { get; set; }
[BsonElement("resiliency")]
public string? Resiliency { get; set; }
[BsonElement("resiliency")]
public string? Resiliency { get; set; }
[BsonElement("primordial")]
public bool? Primordial { get; set; }
[BsonElement("primordial")]
public bool? Primordial { get; set; }
[BsonElement("readonly")]
public bool? ReadOnly { get; set; }
[BsonElement("readonly")]
public bool? ReadOnly { get; set; }
[BsonElement("clustered")]
public bool? Clustered { get; set; }
[BsonElement("clustered")]
public bool? Clustered { get; set; }
[BsonElement("size")]
public ulong? Size { get; set; }
[BsonElement("size")]
public ulong? Size { get; set; }
[BsonElement("size_allocated")]
public ulong? AllocatedSize { get; set; }
[BsonElement("size_allocated")]
public ulong? AllocatedSize { get; set; }
[BsonElement("sectorsize")]
public ulong? SectorSize { get; set; }
[BsonElement("sectorsize")]
public ulong? SectorSize { get; set; }
[BsonElement("states")]
public List<string>? States { get; set; }
[BsonElement("states")]
public List<string>? States { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<HostStoragePoolPhysicalDiskEntity>? PhysicalDisks { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<HostStoragePoolPhysicalDiskEntity>? PhysicalDisks { get; set; }
[BsonIgnoreIfNull, JsonIgnore]
public List<HostStoragePoolVirtualDiskEntity>? VirtualDisks { get; set; }
}
[BsonIgnoreIfNull, JsonIgnore]
public List<HostStoragePoolVirtualDiskEntity>? VirtualDisks { get; set; }
}
[BsonIgnoreExtraElements]
public class HostStoragePoolVirtualDiskEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonIgnoreExtraElements]
public class HostStoragePoolVirtualDiskEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_storagepool"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("storagepool")]
public string? StoragePool { get; set; }
[BsonElement("_storagepool"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("storagepool")]
public string? StoragePool { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("uniqueid")]
public string? UniqueId { get; set; }
[BsonElement("uniqueid")]
public string? UniqueId { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("health")]
public string? Health { get; set; }
[BsonElement("health")]
public string? Health { get; set; }
[BsonElement("access")]
public string? Access { get; set; }
[BsonElement("access")]
public string? Access { get; set; }
[BsonElement("provisioning")]
public string? Provisioning { get; set; }
[BsonElement("provisioning")]
public string? Provisioning { get; set; }
[BsonElement("redundancy")]
public uint? PhysicalRedundancy { get; set; }
[BsonElement("redundancy")]
public uint? PhysicalRedundancy { get; set; }
[BsonElement("resiliency")]
public string? Resiliency { get; set; }
[BsonElement("resiliency")]
public string? Resiliency { get; set; }
[BsonElement("deduplication")]
public bool? Deduplication { get; set; }
[BsonElement("deduplication")]
public bool? Deduplication { get; set; }
[BsonElement("snapshot")]
public bool? Snapshot { get; set; }
[BsonElement("snapshot")]
public bool? Snapshot { get; set; }
[BsonElement("size")]
public ulong? Size { get; set; }
[BsonElement("size")]
public ulong? Size { get; set; }
[BsonElement("size_allocated")]
public ulong? AllocatedSize { get; set; }
[BsonElement("size_allocated")]
public ulong? AllocatedSize { get; set; }
[BsonElement("footprint")]
public ulong? Footprint { get; set; }
[BsonElement("footprint")]
public ulong? Footprint { get; set; }
[BsonElement("cache_read_size")]
public ulong? ReadCacheSize { get; set; }
[BsonElement("cache_read_size")]
public ulong? ReadCacheSize { get; set; }
[BsonElement("cache_write_size")]
public ulong? WriteCacheSize { get; set; }
[BsonElement("cache_write_size")]
public ulong? WriteCacheSize { get; set; }
[BsonElement("states")]
public List<string>? States { get; set; }
}
[BsonElement("states")]
public List<string>? States { get; set; }
}
[BsonIgnoreExtraElements]
public class HostStoragePoolPhysicalDiskEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonIgnoreExtraElements]
public class HostStoragePoolPhysicalDiskEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_storagepool"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("storagepool")]
public string? StoragePool { get; set; }
[BsonElement("_storagepool"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("storagepool")]
public string? StoragePool { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("uniqueid")]
public string? UniqueId { get; set; }
[BsonElement("uniqueid")]
public string? UniqueId { get; set; }
[BsonElement("deviceid")]
public string? DeviceId { get; set; }
[BsonElement("deviceid")]
public string? DeviceId { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("manufacturer")]
public string? Manufacturer { get; set; }
[BsonElement("manufacturer")]
public string? Manufacturer { get; set; }
[BsonElement("Model")]
public string? Model { get; set; }
[BsonElement("Model")]
public string? Model { get; set; }
[BsonElement("media")]
public string? Media { get; set; }
[BsonElement("media")]
public string? Media { get; set; }
[BsonElement("bus")]
public string? Bus { get; set; }
[BsonElement("bus")]
public string? Bus { get; set; }
[BsonElement("health")]
public string? Health { get; set; }
[BsonElement("health")]
public string? Health { get; set; }
[BsonElement("usage")]
public ushort? Usage { get; set; }
[BsonElement("usage")]
public ushort? Usage { get; set; }
[BsonElement("location")]
public string? Location { get; set; }
[BsonElement("location")]
public string? Location { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; }
[BsonElement("firmware")]
public string? Firmware { get; set; }
[BsonElement("firmware")]
public string? Firmware { get; set; }
[BsonElement("size")]
public ulong? Size { get; set; }
[BsonElement("size")]
public ulong? Size { get; set; }
[BsonElement("size_allocated")]
public ulong? AllocatedSize { get; set; }
[BsonElement("size_allocated")]
public ulong? AllocatedSize { get; set; }
[BsonElement("footprint")]
public ulong? Footprint { get; set; }
[BsonElement("footprint")]
public ulong? Footprint { get; set; }
[BsonElement("sector_size_physical")]
public ulong? PhysicalSectorSize { get; set; }
[BsonElement("sector_size_physical")]
public ulong? PhysicalSectorSize { get; set; }
[BsonElement("sector_size_logical")]
public ulong? LogicalSectorSize { get; set; }
[BsonElement("sector_size_logical")]
public ulong? LogicalSectorSize { get; set; }
[BsonElement("states")]
public List<string>? States { get; set; }
}
[BsonElement("states")]
public List<string>? States { get; set; }
}

View file

@ -2,33 +2,32 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostSystemEntity
{
[BsonIgnoreExtraElements]
public class HostSystemEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("localtime")]
public DateTime? LocalTime { get; set; }
[BsonElement("localtime")]
public DateTime? LocalTime { get; set; }
[BsonElement("bootuptime")]
public DateTime? BootUpTime { get; set; }
[BsonElement("bootuptime")]
public DateTime? BootUpTime { get; set; }
[BsonElement("processes")]
public uint? Processes { get; set; }
[BsonElement("processes")]
public uint? Processes { get; set; }
[BsonElement("license")]
public string? License { get; set; }
}
[BsonElement("license")]
public string? License { get; set; }
}

View file

@ -2,60 +2,59 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostUpdateEntity
{
[BsonIgnoreExtraElements]
public class HostUpdateEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; } // os update id
[BsonElement("serial")]
public string? Serial { get; set; } // os update id
[BsonElement("description")]
public string? Description { get; set; }
[BsonElement("description")]
public string? Description { get; set; }
[BsonElement("supporturl")]
public string? SupportUrl { get; set; }
[BsonElement("supporturl")]
public string? SupportUrl { get; set; }
[BsonElement("date")]
public DateTime? Date { get; set; }
[BsonElement("date")]
public DateTime? Date { get; set; }
[BsonElement("pending")]
public bool? Pending { get; set; }
[BsonElement("pending")]
public bool? Pending { get; set; }
[BsonElement("result"), BsonIgnoreIfNull] // installed only
public string? Result { get; set; }
[BsonElement("result"), BsonIgnoreIfNull] // installed only
public string? Result { get; set; }
[BsonElement("type"), BsonIgnoreIfNull] // pending only
public string? Type { get; set; }
[BsonElement("type"), BsonIgnoreIfNull] // pending only
public string? Type { get; set; }
[BsonElement("size"), BsonIgnoreIfNull] // pending only
public decimal? Size { get; set; }
[BsonElement("size"), BsonIgnoreIfNull] // pending only
public decimal? Size { get; set; }
[BsonElement("downloaded"), BsonIgnoreIfNull] // pending only
public bool? IsDownloaded { get; set; }
[BsonElement("downloaded"), BsonIgnoreIfNull] // pending only
public bool? IsDownloaded { get; set; }
[BsonElement("inputrequest"), BsonIgnoreIfNull] // pending only
public bool? CanRequestUserInput { get; set; }
[BsonElement("inputrequest"), BsonIgnoreIfNull] // pending only
public bool? CanRequestUserInput { get; set; }
[BsonElement("reboot"), BsonIgnoreIfNull] // pending only
public string? RebootBehavior { get; set; }
}
[BsonElement("reboot"), BsonIgnoreIfNull] // pending only
public string? RebootBehavior { get; set; }
}

View file

@ -2,119 +2,118 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostUserEntity
{
[BsonIgnoreExtraElements]
public class HostUserEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("sid")]
public string? Sid { get; set; }
[BsonElement("sid")]
public string? Sid { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("domain")]
public string? Domain { get; set; }
[BsonElement("domain")]
public string? Domain { get; set; }
[BsonElement("fullname")]
public string? FullName { get; set; }
[BsonElement("fullname")]
public string? FullName { get; set; }
[BsonElement("description")]
public string? Description { get; set; }
[BsonElement("description")]
public string? Description { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("status")]
public string? Status { get; set; }
[BsonElement("localaccount")]
public bool? LocalAccount { get; set; }
[BsonElement("localaccount")]
public bool? LocalAccount { get; set; }
[BsonElement("disabled")]
public bool? Disabled { get; set; }
[BsonElement("disabled")]
public bool? Disabled { get; set; }
[BsonElement("lockout")]
public bool? Lockout { get; set; }
[BsonElement("lockout")]
public bool? Lockout { get; set; }
[BsonElement("password_changeable")]
public bool? PasswordChangeable { get; set; }
[BsonElement("password_changeable")]
public bool? PasswordChangeable { get; set; }
[BsonElement("password_expires")]
public bool? PasswordExpires { get; set; }
[BsonElement("password_expires")]
public bool? PasswordExpires { get; set; }
[BsonElement("password_required")]
public bool? PasswordRequired { get; set; }
}
[BsonElement("password_required")]
public bool? PasswordRequired { get; set; }
}
[BsonIgnoreExtraElements]
public class HostGroupEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonIgnoreExtraElements]
public class HostGroupEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("sid")]
public string? Sid { get; set; }
[BsonElement("sid")]
public string? Sid { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("domain")]
public string? Domain { get; set; }
[BsonElement("domain")]
public string? Domain { get; set; }
[BsonElement("description")]
public string? Description { get; set; }
[BsonElement("description")]
public string? Description { get; set; }
[BsonElement("localaccount")]
public bool? LocalAccount { get; set; }
}
[BsonElement("localaccount")]
public bool? LocalAccount { get; set; }
}
[BsonIgnoreExtraElements]
public class HostUserGroupEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonIgnoreExtraElements]
public class HostUserGroupEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_user"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("user")]
public string? User { get; set; }
[BsonElement("_user"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("user")]
public string? User { get; set; }
[BsonElement("_group"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("group")]
public string? Group { get; set; }
[BsonElement("_group"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("group")]
public string? Group { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
}
[BsonElement("update")]
public DateTime? Update { get; set; }
}

View file

@ -2,39 +2,38 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostVideocardEntity
{
[BsonIgnoreExtraElements]
public class HostVideocardEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("company")]
public string? Company { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("memory")]
public ulong? Memory { get; set; }
[BsonElement("memory")]
public ulong? Memory { get; set; }
[BsonElement("driver")]
public string? Driver { get; set; }
[BsonElement("driver")]
public string? Driver { get; set; }
[BsonElement("date")]
public DateTime? Date { get; set; }
}
[BsonElement("date")]
public DateTime? Date { get; set; }
}

View file

@ -2,75 +2,74 @@
using MongoDB.Bson.Serialization.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[BsonIgnoreExtraElements]
public class HostVolumeEntity
{
[BsonIgnoreExtraElements]
public class HostVolumeEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_host"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("host")]
public string? Host { get; set; }
[BsonElement("_drive"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("drive")]
public string? Drive { get; set; }
[BsonElement("_drive"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("drive")]
public string? Drive { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("_batch"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("batch")]
public string? Batch { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("index")]
public uint? Index { get; set; }
[BsonElement("index")]
public uint? Index { get; set; }
[BsonElement("label")]
public string? Label { get; set; }
[BsonElement("label")]
public string? Label { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("name")]
public string? Name { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; }
[BsonElement("serial")]
public string? Serial { get; set; }
[BsonElement("size")]
public ulong? Size { get; set; }
[BsonElement("size")]
public ulong? Size { get; set; }
[BsonElement("freespace")]
public ulong? FreeSpace { get; set; }
[BsonElement("freespace")]
public ulong? FreeSpace { get; set; }
[BsonElement("type")]
public string? Type { get; set; }
[BsonElement("type")]
public string? Type { get; set; }
[BsonElement("filesystem")]
public string? FileSystem { get; set; }
[BsonElement("filesystem")]
public string? FileSystem { get; set; }
[BsonElement("compressed")]
public bool? Compressed { get; set; }
[BsonElement("compressed")]
public bool? Compressed { get; set; }
[BsonElement("bootable")]
public bool? Bootable { get; set; }
[BsonElement("bootable")]
public bool? Bootable { get; set; }
[BsonElement("primary")]
public bool? Primary { get; set; }
[BsonElement("primary")]
public bool? Primary { get; set; }
[BsonElement("boot")]
public bool? Boot { get; set; }
[BsonElement("boot")]
public bool? Boot { get; set; }
[BsonElement("blocksize")]
public ulong? BlockSize { get; set; }
[BsonElement("blocksize")]
public ulong? BlockSize { get; set; }
[BsonElement("blocks")]
public ulong? Blocks { get; set; }
[BsonElement("blocks")]
public ulong? Blocks { get; set; }
[BsonElement("startoffset")]
public ulong? StartingOffset { get; set; }
[BsonElement("startoffset")]
public ulong? StartingOffset { get; set; }
[BsonElement("provider")]
public string? Provider { get; set; }
}
[BsonElement("provider")]
public string? Provider { get; set; }
}

View file

@ -4,96 +4,92 @@ using MongoDB.Bson.Serialization.Attributes;
using MongoDbGenericRepository.Attributes;
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Entities
namespace Insight.Infrastructure.Entities;
[CollectionName("user"), BsonIgnoreExtraElements]
public class InsightUser : MongoIdentityUser<ObjectId>
{
[CollectionName("user"), BsonIgnoreExtraElements]
public class InsightUser : MongoIdentityUser<ObjectId>
{
public InsightUser() : base() { }
public InsightUser() : base() { }
public InsightUser(string userName, string email) : base(userName, email) { }
public InsightUser(string userName, string email) : base(userName, email) { }
[JsonPropertyName("refresh_tokens")]
public List<RefreshToken>? RefreshTokens { get; set; }
}
[JsonPropertyName("refresh_tokens")]
public List<RefreshToken>? RefreshTokens { get; set; }
}
[BsonIgnoreExtraElements]
public class InsightUserLogEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonIgnoreExtraElements]
public class InsightUserLogEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_user"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("user")]
public string? User { get; set; }
[BsonElement("_user"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("user")]
public string? User { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("timestamp")]
public DateTime? Timestamp { get; set; }
[BsonElement("timestamp")]
public DateTime? Timestamp { get; set; }
[BsonElement("message")]
public string? Message { get; set; }
}
[BsonElement("message")]
public string? Message { get; set; }
}
[CollectionName("user_pref"), BsonIgnoreExtraElements]
public class InsightUserPreferences
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[CollectionName("user_pref"), BsonIgnoreExtraElements]
public class InsightUserPreferences
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
[BsonElement("_user"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("user")]
public string? User { get; set; }
[BsonElement("_user"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("user")]
public string? User { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("insert")]
public DateTime? Insert { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("darkmode")]
public bool DarkMode { get; set; }
}
[BsonElement("darkmode")]
public bool DarkMode { get; set; }
}
[CollectionName("role")]
public class InsightRole : MongoIdentityRole<ObjectId>
{
[CollectionName("role")]
public class InsightRole : MongoIdentityRole<ObjectId>
{
public InsightRole() : base() { }
}
public InsightRole(string roleName) : base(roleName) { }
}
[BsonIgnoreExtraElements]
public class RefreshToken
{
[BsonElement("token")]
public string? Token { get; set; }
[BsonIgnoreExtraElements]
public class RefreshToken
{
[BsonElement("token")]
public string? Token { get; set; }
[BsonElement("created")]
public DateTime Created { get; set; }
[BsonElement("created")]
public DateTime Created { get; set; }
[BsonElement("created_ip")]
public string? CreatedByIp { get; set; }
[BsonElement("created_ip")]
public string? CreatedByIp { get; set; }
[BsonElement("expires")]
public DateTime Expires { get; set; }
[BsonElement("expires")]
public DateTime Expires { get; set; }
[BsonElement("revoked")]
public DateTime? Revoked { get; set; }
[BsonElement("revoked")]
public DateTime? Revoked { get; set; }
[BsonElement("revoked_ip")]
public string? RevokedByIp { get; set; }
[BsonElement("revoked_ip")]
public string? RevokedByIp { get; set; }
[BsonElement("revoked_reason")]
public string? ReasonRevoked { get; set; }
[BsonElement("revoked_reason")]
public string? ReasonRevoked { get; set; }
[BsonIgnore, JsonIgnore]
public bool IsExpired => DateTime.Now >= Expires.ToLocalTime();
[BsonIgnore, JsonIgnore]
public bool IsExpired => DateTime.Now >= Expires.ToLocalTime();
[BsonIgnore, JsonIgnore]
public bool IsRevoked => Revoked != null;
[BsonIgnore, JsonIgnore]
public bool IsRevoked => Revoked != null;
[BsonIgnore, JsonIgnore]
public bool IsActive => !IsRevoked && !IsExpired;
}
[BsonIgnore, JsonIgnore]
public bool IsActive => !IsRevoked && !IsExpired;
}

View file

@ -2,46 +2,45 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
namespace Insight.Infrastructure
namespace Insight.Infrastructure;
public static class HttpRequestExtensions
{
public static class HttpRequestExtensions
public static void AddPagination<TData>(this HttpRequest request, PagedList<TData> pagelist)
{
public static void AddPagination<TData>(this HttpRequest request, PagedList<TData> pagelist)
var builder = new QueryBuilder();
foreach (var item in request.Query.Where(p => p.Key.ToLower() != "limit" || p.Key.ToLower() != "offset"))
{
var builder = new QueryBuilder();
builder.Add(item.Key.ToLower(), item.Value.ToString());
}
foreach (var item in request.Query.Where(p => p.Key.ToLower() != "limit" || p.Key.ToLower() != "offset"))
builder.Add("limit", pagelist.Meta.Limit.ToString());
if (pagelist.Meta.Offset > 0)
{
var qb = new QueryBuilder(builder);
if (pagelist.Meta.Offset > pagelist.Meta.Limit)
{
builder.Add(item.Key.ToLower(), item.Value.ToString());
qb.Add("offset", (pagelist.Meta.Offset - pagelist.Meta.Limit).ToString());
}
else
{
qb.Add("offset", 0.ToString());
}
builder.Add("limit", pagelist.Meta.Limit.ToString());
pagelist.Meta.Previous = $"{request.Scheme}://{request.Host}{request.PathBase}{request.Path}{qb}";
}
if (pagelist.Meta.Offset > 0)
if ((pagelist.Meta.Offset + pagelist.Meta.Count) < pagelist.Meta.Total)
{
var qb = new QueryBuilder(builder)
{
var qb = new QueryBuilder(builder);
{ "offset", (pagelist.Meta.Offset + pagelist.Meta.Count).ToString() }
};
if (pagelist.Meta.Offset > pagelist.Meta.Limit)
{
qb.Add("offset", (pagelist.Meta.Offset - pagelist.Meta.Limit).ToString());
}
else
{
qb.Add("offset", 0.ToString());
}
pagelist.Meta.Previous = $"{request.Scheme}://{request.Host}{request.PathBase}{request.Path}{qb}";
}
if ((pagelist.Meta.Offset + pagelist.Meta.Count) < pagelist.Meta.Total)
{
var qb = new QueryBuilder(builder)
{
{ "offset", (pagelist.Meta.Offset + pagelist.Meta.Count).ToString() }
};
pagelist.Meta.Next = $"{request.Scheme}://{request.Host}{request.PathBase}{request.Path}{qb}";
}
pagelist.Meta.Next = $"{request.Scheme}://{request.Host}{request.PathBase}{request.Path}{qb}";
}
}
}

View file

@ -2,16 +2,15 @@
using Microsoft.AspNetCore.Http;
using System.Text.Json;
namespace Insight.Infrastructure
namespace Insight.Infrastructure;
public static class HttpResponseExtensions
{
public static class HttpResponseExtensions
public static void AddPagination<TData>(this HttpResponse response, PagedList<TData> pagelist)
{
public static void AddPagination<TData>(this HttpResponse response, PagedList<TData> pagelist)
response.Headers.Add("X-Pagination", JsonSerializer.Serialize(pagelist.Meta as PagedHeaderData, new JsonSerializerOptions
{
response.Headers.Add("X-Pagination", JsonSerializer.Serialize(pagelist.Meta as PagedHeaderData, new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
}));
}
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
}));
}
}

View file

@ -4,80 +4,79 @@ using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
namespace Insight.Infrastructure
namespace Insight.Infrastructure;
public static class MongoCollectionExtensions
{
public static class MongoCollectionExtensions
private const int _maximumLimit = 100;
public static async Task<PagedList<TData>> GetPagedAsync<TData>(
this IMongoCollection<TData> collection,
FilterDefinition<TData>? filter = null,
SortDefinition<TData>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default)
{
private const int _maximumLimit = 100;
if (limit > _maximumLimit) throw new InvalidOperationException("invalid limit value > 100");
public static async Task<PagedList<TData>> GetPagedAsync<TData>(
this IMongoCollection<TData> collection,
FilterDefinition<TData>? filter = null,
SortDefinition<TData>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default)
{
if (limit > _maximumLimit) throw new InvalidOperationException("invalid limit value > 100");
var query = collection.Find(filter ?? Builders<TData>.Filter.Empty);
var query = collection.Find(filter ?? Builders<TData>.Filter.Empty);
if (sort is not null) query = query.Sort(sort);
if (sort is not null) query = query.Sort(sort);
var data = await query.Skip(offset).Limit(limit).ToListAsync(cancellationToken).ConfigureAwait(false);
var total = await collection.EstimatedDocumentCountAsync(null, cancellationToken).ConfigureAwait(false);
var data = await query.Skip(offset).Limit(limit).ToListAsync(cancellationToken).ConfigureAwait(false);
var total = await collection.EstimatedDocumentCountAsync(null, cancellationToken).ConfigureAwait(false);
return new PagedList<TData>(data, offset, limit, total);
}
return new PagedList<TData>(data, offset, limit, total);
}
public static async Task<PagedList<TData>> GetPagedAsync<TData>(
this IMongoCollection<TData> collection,
HttpRequest request,
HttpResponse response,
FilterDefinition<TData>? filter = null,
SortDefinition<TData>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default)
{
var result = await GetPagedAsync(collection, filter, sort, offset, limit, cancellationToken).ConfigureAwait(false);
public static async Task<PagedList<TData>> GetPagedAsync<TData>(
this IMongoCollection<TData> collection,
HttpRequest request,
HttpResponse response,
FilterDefinition<TData>? filter = null,
SortDefinition<TData>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default)
{
var result = await GetPagedAsync(collection, filter, sort, offset, limit, cancellationToken).ConfigureAwait(false);
request?.AddPagination(result);
response?.AddPagination(result);
request?.AddPagination(result);
response?.AddPagination(result);
return result;
}
return result;
}
public static async Task<PagedList<TResult>> GetPagedAsync<TData, TResult>(
this IMongoCollection<TData> collection,
IAggregateFluent<BsonDocument> query,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default)
{
if (limit > _maximumLimit) throw new InvalidOperationException("invalid limit value");
public static async Task<PagedList<TResult>> GetPagedAsync<TData, TResult>(
this IMongoCollection<TData> collection,
IAggregateFluent<BsonDocument> query,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default)
{
if (limit > _maximumLimit) throw new InvalidOperationException("invalid limit value");
var data = await query.Skip(offset).Limit(limit).ToListAsync(cancellationToken).ConfigureAwait(false);
var total = await collection.EstimatedDocumentCountAsync(null, cancellationToken).ConfigureAwait(false);
var data = await query.Skip(offset).Limit(limit).ToListAsync(cancellationToken).ConfigureAwait(false);
var total = await collection.EstimatedDocumentCountAsync(null, cancellationToken).ConfigureAwait(false);
return new PagedList<TResult>(data.Select(x => BsonSerializer.Deserialize<TResult>(x)), offset, limit, total);
}
return new PagedList<TResult>(data.Select(x => BsonSerializer.Deserialize<TResult>(x)), offset, limit, total);
}
public static async Task<PagedList<TResult>> GetPagedAsync<TData, TResult>(
this IMongoCollection<TData> collection,
HttpRequest request,
HttpResponse response,
IAggregateFluent<BsonDocument> query,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default)
{
var result = await GetPagedAsync<TData, TResult>(collection, query, offset, limit, cancellationToken).ConfigureAwait(false);
public static async Task<PagedList<TResult>> GetPagedAsync<TData, TResult>(
this IMongoCollection<TData> collection,
HttpRequest request,
HttpResponse response,
IAggregateFluent<BsonDocument> query,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default)
{
var result = await GetPagedAsync<TData, TResult>(collection, query, offset, limit, cancellationToken).ConfigureAwait(false);
request?.AddPagination(result);
response?.AddPagination(result);
request?.AddPagination(result);
response?.AddPagination(result);
return result;
}
return result;
}
}

View file

@ -1,57 +1,56 @@
using Insight.Infrastructure.Entities;
using MongoDB.Driver;
namespace Insight.Infrastructure
namespace Insight.Infrastructure;
public static class MongoDatabaseExtensions
{
public static class MongoDatabaseExtensions
{
// internal users (roles), groups...
public static IMongoCollection<InsightUser> User(this IMongoDatabase database) => database.GetCollection<InsightUser>("user");
public static IMongoCollection<InsightUserLogEntity> UserLog(this IMongoDatabase database) => database.GetCollection<InsightUserLogEntity>("user_log");
public static IMongoCollection<InsightUserPreferences> UserPreference(this IMongoDatabase database) => database.GetCollection<InsightUserPreferences>("user_pref");
public static IMongoCollection<InsightRole> Role(this IMongoDatabase database) => database.GetCollection<InsightRole>("role");
// internal users (roles), groups...
public static IMongoCollection<InsightUser> User(this IMongoDatabase database) => database.GetCollection<InsightUser>("user");
public static IMongoCollection<InsightUserLogEntity> UserLog(this IMongoDatabase database) => database.GetCollection<InsightUserLogEntity>("user_log");
public static IMongoCollection<InsightUserPreferences> UserPreference(this IMongoDatabase database) => database.GetCollection<InsightUserPreferences>("user_pref");
public static IMongoCollection<InsightRole> Role(this IMongoDatabase database) => database.GetCollection<InsightRole>("role");
// customers
public static IMongoCollection<CustomerEntity> Customer(this IMongoDatabase database) => database.GetCollection<CustomerEntity>("customer");
// customers
public static IMongoCollection<CustomerEntity> Customer(this IMongoDatabase database) => database.GetCollection<CustomerEntity>("customer");
// agents
public static IMongoCollection<AgentEntity> Agent(this IMongoDatabase database) => database.GetCollection<AgentEntity>("agent");
public static IMongoCollection<AgentLogEntity> AgentLog(this IMongoDatabase database) => database.GetCollection<AgentLogEntity>("agent_log");
// agents
public static IMongoCollection<AgentEntity> Agent(this IMongoDatabase database) => database.GetCollection<AgentEntity>("agent");
public static IMongoCollection<AgentLogEntity> AgentLog(this IMongoDatabase database) => database.GetCollection<AgentLogEntity>("agent_log");
// host groups
public static IMongoCollection<HostEntity> HostGroup(this IMongoDatabase database) => database.GetCollection<HostEntity>("host");
// host groups
public static IMongoCollection<HostEntity> HostGroup(this IMongoDatabase database) => database.GetCollection<HostEntity>("host");
// hosts
public static IMongoCollection<HostEntity> Host(this IMongoDatabase database) => database.GetCollection<HostEntity>("host");
public static IMongoCollection<HostLogEntity> HostLog(this IMongoDatabase database) => database.GetCollection<HostLogEntity>("host_log");
// hosts
public static IMongoCollection<HostEntity> Host(this IMongoDatabase database) => database.GetCollection<HostEntity>("host");
public static IMongoCollection<HostLogEntity> HostLog(this IMongoDatabase database) => database.GetCollection<HostLogEntity>("host_log");
// hosts extensions
public static IMongoCollection<HostLogMonitoringEntity> HostLogMonitoring(this IMongoDatabase database) => database.GetCollection<HostLogMonitoringEntity>("host_log_mon");
public static IMongoCollection<HostApplicationEntity> HostApplication(this IMongoDatabase database) => database.GetCollection<HostApplicationEntity>("host_app");
public static IMongoCollection<HostDriveEntity> HostDrive(this IMongoDatabase database) => database.GetCollection<HostDriveEntity>("host_drv");
public static IMongoCollection<HostVolumeEntity> HostVolume(this IMongoDatabase database) => database.GetCollection<HostVolumeEntity>("host_vol");
public static IMongoCollection<HostOsEntity> HostOs(this IMongoDatabase database) => database.GetCollection<HostOsEntity>("host_os");
public static IMongoCollection<HostUpdateEntity> HostUpdate(this IMongoDatabase database) => database.GetCollection<HostUpdateEntity>("host_upd");
public static IMongoCollection<HostSessionEntity> HostSession(this IMongoDatabase database) => database.GetCollection<HostSessionEntity>("host_session");
public static IMongoCollection<HostServiceEntity> HostService(this IMongoDatabase database) => database.GetCollection<HostServiceEntity>("host_svc");
public static IMongoCollection<HostPrinterEntity> HostPrinter(this IMongoDatabase database) => database.GetCollection<HostPrinterEntity>("host_prn");
public static IMongoCollection<HostMainboardEntity> HostMainboard(this IMongoDatabase database) => database.GetCollection<HostMainboardEntity>("host_board");
public static IMongoCollection<HostProcessorEntity> HostProcessor(this IMongoDatabase database) => database.GetCollection<HostProcessorEntity>("host_cpu");
public static IMongoCollection<HostMemoryEntity> HostMemory(this IMongoDatabase database) => database.GetCollection<HostMemoryEntity>("host_mem");
public static IMongoCollection<HostVideocardEntity> HostVideocard(this IMongoDatabase database) => database.GetCollection<HostVideocardEntity>("host_gpu");
public static IMongoCollection<HostUserEntity> HostSystemUser(this IMongoDatabase database) => database.GetCollection<HostUserEntity>("host_sysusr");
public static IMongoCollection<HostGroupEntity> HostSystemGroup(this IMongoDatabase database) => database.GetCollection<HostGroupEntity>("host_sysgrp");
public static IMongoCollection<HostUserGroupEntity> HostSystemUserSystemGroup(this IMongoDatabase database) => database.GetCollection<HostUserGroupEntity>("host_sysusr_sysgrp");
public static IMongoCollection<HostSystemEntity> HostSystem(this IMongoDatabase database) => database.GetCollection<HostSystemEntity>("host_sys");
public static IMongoCollection<HostStoragePoolEntity> HostStoragePool(this IMongoDatabase database) => database.GetCollection<HostStoragePoolEntity>("host_sp");
public static IMongoCollection<HostStoragePoolPhysicalDiskEntity> HostStoragePoolPhysicalDisk(this IMongoDatabase database) => database.GetCollection<HostStoragePoolPhysicalDiskEntity>("host_sp.pd");
public static IMongoCollection<HostStoragePoolVirtualDiskEntity> HostStoragePoolVirtualDisk(this IMongoDatabase database) => database.GetCollection<HostStoragePoolVirtualDiskEntity>("host_sp.vd");
public static IMongoCollection<HostHypervisorVirtualMaschineEntity> HostHypervisorVirtualMaschine(this IMongoDatabase database) => database.GetCollection<HostHypervisorVirtualMaschineEntity>("host_hv_vm");
public static IMongoCollection<HostHypervisorVirtualMaschineConfigEntity> HostVirtualMaschineConfig(this IMongoDatabase database) => database.GetCollection<HostHypervisorVirtualMaschineConfigEntity>("host_hv_vm_cfg");
public static IMongoCollection<HostInterfaceEntity> HostInterface(this IMongoDatabase database) => database.GetCollection<HostInterfaceEntity>("host_if");
public static IMongoCollection<HostInterfaceAddressEntity> HostInterfaceAddress(this IMongoDatabase database) => database.GetCollection<HostInterfaceAddressEntity>("host_if_addr");
public static IMongoCollection<HostInterfaceGatewayEntity> HostInterfaceGateway(this IMongoDatabase database) => database.GetCollection<HostInterfaceGatewayEntity>("host_if_gw");
public static IMongoCollection<HostInterfaceNameserverEntity> HostInterfaceNameserver(this IMongoDatabase database) => database.GetCollection<HostInterfaceNameserverEntity>("host_if_ns");
public static IMongoCollection<HostInterfaceRouteEntity> HostInterfaceRoute(this IMongoDatabase database) => database.GetCollection<HostInterfaceRouteEntity>("host_if_rt");
}
// hosts extensions
public static IMongoCollection<HostLogMonitoringEntity> HostLogMonitoring(this IMongoDatabase database) => database.GetCollection<HostLogMonitoringEntity>("host_log_mon");
public static IMongoCollection<HostApplicationEntity> HostApplication(this IMongoDatabase database) => database.GetCollection<HostApplicationEntity>("host_app");
public static IMongoCollection<HostDriveEntity> HostDrive(this IMongoDatabase database) => database.GetCollection<HostDriveEntity>("host_drv");
public static IMongoCollection<HostVolumeEntity> HostVolume(this IMongoDatabase database) => database.GetCollection<HostVolumeEntity>("host_vol");
public static IMongoCollection<HostOsEntity> HostOs(this IMongoDatabase database) => database.GetCollection<HostOsEntity>("host_os");
public static IMongoCollection<HostUpdateEntity> HostUpdate(this IMongoDatabase database) => database.GetCollection<HostUpdateEntity>("host_upd");
public static IMongoCollection<HostSessionEntity> HostSession(this IMongoDatabase database) => database.GetCollection<HostSessionEntity>("host_session");
public static IMongoCollection<HostServiceEntity> HostService(this IMongoDatabase database) => database.GetCollection<HostServiceEntity>("host_svc");
public static IMongoCollection<HostPrinterEntity> HostPrinter(this IMongoDatabase database) => database.GetCollection<HostPrinterEntity>("host_prn");
public static IMongoCollection<HostMainboardEntity> HostMainboard(this IMongoDatabase database) => database.GetCollection<HostMainboardEntity>("host_board");
public static IMongoCollection<HostProcessorEntity> HostProcessor(this IMongoDatabase database) => database.GetCollection<HostProcessorEntity>("host_cpu");
public static IMongoCollection<HostMemoryEntity> HostMemory(this IMongoDatabase database) => database.GetCollection<HostMemoryEntity>("host_mem");
public static IMongoCollection<HostVideocardEntity> HostVideocard(this IMongoDatabase database) => database.GetCollection<HostVideocardEntity>("host_gpu");
public static IMongoCollection<HostUserEntity> HostSystemUser(this IMongoDatabase database) => database.GetCollection<HostUserEntity>("host_sysusr");
public static IMongoCollection<HostGroupEntity> HostSystemGroup(this IMongoDatabase database) => database.GetCollection<HostGroupEntity>("host_sysgrp");
public static IMongoCollection<HostUserGroupEntity> HostSystemUserSystemGroup(this IMongoDatabase database) => database.GetCollection<HostUserGroupEntity>("host_sysusr_sysgrp");
public static IMongoCollection<HostSystemEntity> HostSystem(this IMongoDatabase database) => database.GetCollection<HostSystemEntity>("host_sys");
public static IMongoCollection<HostStoragePoolEntity> HostStoragePool(this IMongoDatabase database) => database.GetCollection<HostStoragePoolEntity>("host_sp");
public static IMongoCollection<HostStoragePoolPhysicalDiskEntity> HostStoragePoolPhysicalDisk(this IMongoDatabase database) => database.GetCollection<HostStoragePoolPhysicalDiskEntity>("host_sp.pd");
public static IMongoCollection<HostStoragePoolVirtualDiskEntity> HostStoragePoolVirtualDisk(this IMongoDatabase database) => database.GetCollection<HostStoragePoolVirtualDiskEntity>("host_sp.vd");
public static IMongoCollection<HostHypervisorVirtualMaschineEntity> HostHypervisorVirtualMaschine(this IMongoDatabase database) => database.GetCollection<HostHypervisorVirtualMaschineEntity>("host_hv_vm");
public static IMongoCollection<HostHypervisorVirtualMaschineConfigEntity> HostVirtualMaschineConfig(this IMongoDatabase database) => database.GetCollection<HostHypervisorVirtualMaschineConfigEntity>("host_hv_vm_cfg");
public static IMongoCollection<HostInterfaceEntity> HostInterface(this IMongoDatabase database) => database.GetCollection<HostInterfaceEntity>("host_if");
public static IMongoCollection<HostInterfaceAddressEntity> HostInterfaceAddress(this IMongoDatabase database) => database.GetCollection<HostInterfaceAddressEntity>("host_if_addr");
public static IMongoCollection<HostInterfaceGatewayEntity> HostInterfaceGateway(this IMongoDatabase database) => database.GetCollection<HostInterfaceGatewayEntity>("host_if_gw");
public static IMongoCollection<HostInterfaceNameserverEntity> HostInterfaceNameserver(this IMongoDatabase database) => database.GetCollection<HostInterfaceNameserverEntity>("host_if_ns");
public static IMongoCollection<HostInterfaceRouteEntity> HostInterfaceRoute(this IMongoDatabase database) => database.GetCollection<HostInterfaceRouteEntity>("host_if_rt");
}

View file

@ -16,248 +16,247 @@ using MongoDB.Driver;
using MongoDB.Driver.Core.Configuration;
using System.Text;
namespace Insight.Infrastructure
namespace Insight.Infrastructure;
public static class ServiceExtensions
{
public static class ServiceExtensions
public static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration, ILoggerFactory? loggerFactory = null)
{
public static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration, ILoggerFactory? loggerFactory = null)
var connectionString = configuration.GetValue<string?>(Appsettings.Database) ?? throw new Exception($"{Appsettings.Database} value not set (appsettings)");
var settings = MongoClientSettings.FromUrl(new MongoUrl(connectionString));
settings.ConnectTimeout = TimeSpan.FromSeconds(3);
settings.IPv6 = false;
if (loggerFactory is not null)
{
var connectionString = configuration.GetValue<string?>(Appsettings.Database) ?? throw new Exception($"{Appsettings.Database} value not set (appsettings)");
var settings = MongoClientSettings.FromUrl(new MongoUrl(connectionString));
settings.ConnectTimeout = TimeSpan.FromSeconds(3);
settings.IPv6 = false;
if (loggerFactory is not null)
{
settings.LoggingSettings = new LoggingSettings(loggerFactory);
}
services.AddSingleton(new MongoClient(settings));
services.AddSingleton<IMongoClient>(provider => provider.GetRequiredService<MongoClient>());
return services.AddSingleton(provider => provider.GetRequiredService<MongoClient>().GetDatabase(Settings.Database));
settings.LoggingSettings = new LoggingSettings(loggerFactory);
}
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services)
services.AddSingleton(new MongoClient(settings));
services.AddSingleton<IMongoClient>(provider => provider.GetRequiredService<MongoClient>());
return services.AddSingleton(provider => provider.GetRequiredService<MongoClient>().GetDatabase(Settings.Database));
}
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services)
{
services.AddTransient<IdentityService>();
services.AddTransient<AuthenticatorService>();
services.AddTransient<AccountService>();
services.AddTransient<CustomerService>();
services.AddTransient<HostService>();
services.AddTransient<AgentService>();
services.AddTransient<InventoryService>();
return services;
}
public static IServiceCollection AddIdentityServices(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration.GetValue<string?>(Appsettings.Database) ?? throw new Exception($"{Appsettings.Database} value not set (appsettings)");
services.AddIdentity<InsightUser, InsightRole>(options =>
{
services.AddTransient<IdentityService>();
services.AddTransient<AuthenticatorService>();
services.AddTransient<AccountService>();
services.AddTransient<CustomerService>();
services.AddTransient<HostService>();
services.AddTransient<AgentService>();
services.AddTransient<InventoryService>();
return services;
}
public static IServiceCollection AddIdentityServices(this IServiceCollection services, IConfiguration configuration)
})
.AddMongoDbStores<InsightUser, InsightRole, ObjectId>(connectionString, Settings.Database)
.AddDefaultTokenProviders()
.AddSignInManager();
return services;
}
public static IServiceCollection AddTokenServices(this IServiceCollection services, IConfiguration configuration)
{
var options = new Models.TokenOptions(
key: configuration.GetValue<string?>(Appsettings.JwtKey) ?? throw new Exception($"{Appsettings.JwtKey} value not set (appsettings)"),
expires: configuration.GetValue<int?>(Appsettings.JwtExp) ?? throw new Exception($"{Appsettings.JwtExp} value not set (appsettings)"),
audience: configuration.GetValue<Uri?>(Appsettings.JwtAudience) ?? throw new Exception($"{Appsettings.JwtAudience} value not set (appsettings)"),
issuer: configuration.GetValue<Uri?>(Appsettings.JwtIssuer) ?? throw new Exception($"{Appsettings.JwtIssuer} value not set (appsettings)"));
services.AddSingleton(options);
services.AddTransient<TokenService>();
return services;
}
public static IServiceCollection AddCustomAuthentication(this IServiceCollection services, IConfiguration configuration)
{
// REWRITE TO COOKIE ONLY FOR WEB
services.AddAuthentication(options =>
{
var connectionString = configuration.GetValue<string?>(Appsettings.Database) ?? throw new Exception($"{Appsettings.Database} value not set (appsettings)");
services.AddIdentity<InsightUser, InsightRole>(options =>
{
})
.AddMongoDbStores<InsightUser, InsightRole, ObjectId>(connectionString, Settings.Database)
.AddDefaultTokenProviders()
.AddSignInManager();
return services;
}
public static IServiceCollection AddTokenServices(this IServiceCollection services, IConfiguration configuration)
options.DefaultScheme = "Custom";
options.DefaultChallengeScheme = "Custom";
})
.AddCookie("Cookies", options =>
{
var options = new Models.TokenOptions(
key: configuration.GetValue<string?>(Appsettings.JwtKey) ?? throw new Exception($"{Appsettings.JwtKey} value not set (appsettings)"),
expires: configuration.GetValue<int?>(Appsettings.JwtExp) ?? throw new Exception($"{Appsettings.JwtExp} value not set (appsettings)"),
audience: configuration.GetValue<Uri?>(Appsettings.JwtAudience) ?? throw new Exception($"{Appsettings.JwtAudience} value not set (appsettings)"),
issuer: configuration.GetValue<Uri?>(Appsettings.JwtIssuer) ?? throw new Exception($"{Appsettings.JwtIssuer} value not set (appsettings)"));
//options.Cookie.Domain = "insight.webmatic.de";
options.Cookie.Name = "insight";
options.LoginPath = "/account/login";
options.LogoutPath = "/account/logout";
options.ExpireTimeSpan = TimeSpan.FromHours(1);
options.SlidingExpiration = true;
services.AddSingleton(options);
services.AddTransient<TokenService>();
return services;
}
public static IServiceCollection AddCustomAuthentication(this IServiceCollection services, IConfiguration configuration)
{
// REWRITE TO COOKIE ONLY FOR WEB
services.AddAuthentication(options =>
options.Events.OnRedirectToLogin = options =>
{
options.DefaultScheme = "Custom";
options.DefaultChallengeScheme = "Custom";
})
.AddCookie("Cookies", options =>
{
//options.Cookie.Domain = "insight.webmatic.de";
options.Cookie.Name = "insight";
options.LoginPath = "/account/login";
options.LogoutPath = "/account/logout";
options.ExpireTimeSpan = TimeSpan.FromHours(1);
options.SlidingExpiration = true;
if (options.Request.Path.StartsWithSegments("/api") && options.Response.StatusCode == 200)
options.Response.StatusCode = 401;
else
options.Response.Redirect(options.RedirectUri);
options.Events.OnRedirectToLogin = options =>
{
if (options.Request.Path.StartsWithSegments("/api") && options.Response.StatusCode == 200)
options.Response.StatusCode = 401;
else
options.Response.Redirect(options.RedirectUri);
return Task.CompletedTask;
};
})
.AddJwtBearer("Bearer", options =>
{
options.RequireHttpsMetadata = false;
options.SaveToken = true;
options.TokenValidationParameters.ValidateActor = false;
options.TokenValidationParameters.ValidAudience = configuration.GetSection("Jwt:Audience").Value;
options.TokenValidationParameters.ValidateAudience = true;
options.TokenValidationParameters.ValidIssuer = configuration.GetSection("Jwt:Issuer").Value;
options.TokenValidationParameters.ValidateIssuer = true;
options.TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(configuration.GetSection("Jwt:Key").Value ?? throw new ArgumentNullException(nameof(TokenValidationParameters), "Jwt:Key"))
);
options.TokenValidationParameters.ValidateIssuerSigningKey = true;
options.TokenValidationParameters.ValidateLifetime = true;
})
.AddPolicyScheme("Custom", "Custom", options =>
{
options.ForwardDefaultSelector = context =>
{
string authorization = context.Request.Headers[HeaderNames.Authorization];
if (!string.IsNullOrEmpty(authorization) && authorization.StartsWith("Bearer ")) return "Bearer";
return "Cookies";
};
});
return services;
}
public static IServiceCollection AddBearerAuthentication(this IServiceCollection services, IConfiguration configuration)
{
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultSignInScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.RequireHttpsMetadata = false;
options.SaveToken = true;
options.TokenValidationParameters.ValidateActor = false;
options.TokenValidationParameters.ValidAudience = configuration.GetValue<string?>(Appsettings.JwtAudience) ?? throw new Exception($"{Appsettings.JwtAudience} value not set (appsettings)");
options.TokenValidationParameters.ValidateAudience = true;
options.TokenValidationParameters.ValidIssuer = configuration.GetValue<string?>(Appsettings.JwtIssuer) ?? throw new Exception($"{Appsettings.JwtIssuer} value not set (appsettings)");
options.TokenValidationParameters.ValidateIssuer = true;
options.TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(configuration.GetValue<string?>(Appsettings.JwtKey) ?? throw new Exception($"{Appsettings.JwtKey} value not set (appsettings)"))
);
options.TokenValidationParameters.ValidateIssuerSigningKey = true;
options.TokenValidationParameters.ValidateLifetime = true;
});
return services;
}
public static IServiceCollection AddProxyServices(this IServiceCollection services, IConfiguration configuration)
{
// add before routing
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
return services;
}
public static IServiceCollection AddRoutingServices(this IServiceCollection services, IConfiguration configuration)
{
// add after proxy
services.AddRouting(options =>
{
options.LowercaseUrls = true;
});
return services;
}
private static IServiceCollection AddIdentityServices2(this IServiceCollection services, IConfiguration configuration)
{
var identityOptions = new MongoDbIdentityConfiguration
{
MongoDbSettings = new MongoDbSettings
{
ConnectionString = configuration.GetSection("ConnectionStrings:Mongo").Value,
DatabaseName = "insight"
},
IdentityOptionsAction = options =>
{
options.User.RequireUniqueEmail = true;
options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@.-_";
options.Password.RequireDigit = false;
options.Password.RequiredLength = 8;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequireLowercase = false;
options.SignIn.RequireConfirmedAccount = false;
options.SignIn.RequireConfirmedEmail = false;
options.SignIn.RequireConfirmedPhoneNumber = false;
options.Lockout.MaxFailedAccessAttempts = 5;
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
}
return Task.CompletedTask;
};
services.ConfigureMongoDbIdentity<InsightUser, InsightRole, ObjectId>(identityOptions)
.AddDefaultTokenProviders()
.AddSignInManager<InsightUser>();
return services;
}
private static IServiceCollection AddIdentityAuthentication(this IServiceCollection services, IConfiguration configuration)
})
.AddJwtBearer("Bearer", options =>
{
services.AddAuthentication(options =>
options.RequireHttpsMetadata = false;
options.SaveToken = true;
options.TokenValidationParameters.ValidateActor = false;
options.TokenValidationParameters.ValidAudience = configuration.GetSection("Jwt:Audience").Value;
options.TokenValidationParameters.ValidateAudience = true;
options.TokenValidationParameters.ValidIssuer = configuration.GetSection("Jwt:Issuer").Value;
options.TokenValidationParameters.ValidateIssuer = true;
options.TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(configuration.GetSection("Jwt:Key").Value ?? throw new ArgumentNullException(nameof(TokenValidationParameters), "Jwt:Key"))
);
options.TokenValidationParameters.ValidateIssuerSigningKey = true;
options.TokenValidationParameters.ValidateLifetime = true;
})
.AddPolicyScheme("Custom", "Custom", options =>
{
options.ForwardDefaultSelector = context =>
{
//options.DefaultAuthenticateScheme =
});
//cookieBuilder.ApplicationCookie = builder.AddApplicationCookie();
//cookieBuilder.ExternalCookie = builder.AddExternalCookie();
//cookieBuilder.TwoFactorRememberMeCookie = builder.AddTwoFactorRememberMeCookie();
//cookieBuilder.TwoFactorUserIdCookie = builder.AddTwoFactorUserIdCookie();
//.AddCookie(options =>
//{
// options.
//};
//.AddIdentityCookies();
//.AddCookie(options =>
//{
// // Specify where to redirect un-authenticated users
// options.LoginPath = "/account/login";
string authorization = context.Request.Headers[HeaderNames.Authorization];
// // Specify the name of the auth cookie.
// // ASP.NET picks a dumb name by default.
// options.Cookie.Name = "insight";
//});
if (!string.IsNullOrEmpty(authorization) && authorization.StartsWith("Bearer ")) return "Bearer";
return services;
}
return "Cookies";
};
});
return services;
}
public static IServiceCollection AddBearerAuthentication(this IServiceCollection services, IConfiguration configuration)
{
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultSignInScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.RequireHttpsMetadata = false;
options.SaveToken = true;
options.TokenValidationParameters.ValidateActor = false;
options.TokenValidationParameters.ValidAudience = configuration.GetValue<string?>(Appsettings.JwtAudience) ?? throw new Exception($"{Appsettings.JwtAudience} value not set (appsettings)");
options.TokenValidationParameters.ValidateAudience = true;
options.TokenValidationParameters.ValidIssuer = configuration.GetValue<string?>(Appsettings.JwtIssuer) ?? throw new Exception($"{Appsettings.JwtIssuer} value not set (appsettings)");
options.TokenValidationParameters.ValidateIssuer = true;
options.TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(configuration.GetValue<string?>(Appsettings.JwtKey) ?? throw new Exception($"{Appsettings.JwtKey} value not set (appsettings)"))
);
options.TokenValidationParameters.ValidateIssuerSigningKey = true;
options.TokenValidationParameters.ValidateLifetime = true;
});
return services;
}
public static IServiceCollection AddProxyServices(this IServiceCollection services, IConfiguration configuration)
{
// add before routing
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
return services;
}
public static IServiceCollection AddRoutingServices(this IServiceCollection services, IConfiguration configuration)
{
// add after proxy
services.AddRouting(options =>
{
options.LowercaseUrls = true;
});
return services;
}
private static IServiceCollection AddIdentityServices2(this IServiceCollection services, IConfiguration configuration)
{
var identityOptions = new MongoDbIdentityConfiguration
{
MongoDbSettings = new MongoDbSettings
{
ConnectionString = configuration.GetSection("ConnectionStrings:Mongo").Value,
DatabaseName = "insight"
},
IdentityOptionsAction = options =>
{
options.User.RequireUniqueEmail = true;
options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@.-_";
options.Password.RequireDigit = false;
options.Password.RequiredLength = 8;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequireLowercase = false;
options.SignIn.RequireConfirmedAccount = false;
options.SignIn.RequireConfirmedEmail = false;
options.SignIn.RequireConfirmedPhoneNumber = false;
options.Lockout.MaxFailedAccessAttempts = 5;
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
}
};
services.ConfigureMongoDbIdentity<InsightUser, InsightRole, ObjectId>(identityOptions)
.AddDefaultTokenProviders()
.AddSignInManager<InsightUser>();
return services;
}
private static IServiceCollection AddIdentityAuthentication(this IServiceCollection services, IConfiguration configuration)
{
services.AddAuthentication(options =>
{
//options.DefaultAuthenticateScheme =
});
//cookieBuilder.ApplicationCookie = builder.AddApplicationCookie();
//cookieBuilder.ExternalCookie = builder.AddExternalCookie();
//cookieBuilder.TwoFactorRememberMeCookie = builder.AddTwoFactorRememberMeCookie();
//cookieBuilder.TwoFactorUserIdCookie = builder.AddTwoFactorUserIdCookie();
//.AddCookie(options =>
//{
// options.
//};
//.AddIdentityCookies();
//.AddCookie(options =>
//{
// // Specify where to redirect un-authenticated users
// options.LoginPath = "/account/login";
// // Specify the name of the auth cookie.
// // ASP.NET picks a dumb name by default.
// options.Cookie.Name = "insight";
//});
return services;
}
}

View file

@ -1,49 +1,48 @@
using System.Text.Json.Serialization;
namespace Insight.Infrastructure.Models
namespace Insight.Infrastructure.Models;
public class PagedList<T>
{
public class PagedList<T>
{
public PagedMetaData Meta { get; } = new();
public IEnumerable<T> Data { get; }
public PagedMetaData Meta { get; } = new();
public IEnumerable<T> Data { get; }
public PagedList(IEnumerable<T> data, int offset, int limit, long total)
public PagedList(IEnumerable<T> data, int offset, int limit, long total)
{
Data = data;
Meta = new()
{
Data = data;
Meta = new()
{
Offset = offset,
Limit = limit,
Count = data?.Count() ?? 0,
Total = total,
};
}
Offset = offset,
Limit = limit,
Count = data?.Count() ?? 0,
Total = total,
};
}
}
public class PagedDataRequest
{
[JsonPropertyName("offset")]
public int Offset { get; set; } = 0;
public class PagedDataRequest
{
[JsonPropertyName("offset")]
public int Offset { get; set; } = 0;
[JsonPropertyName("limit")]
public int Limit { get; set; } = 10;
}
[JsonPropertyName("limit")]
public int Limit { get; set; } = 10;
}
public class PagedHeaderData : PagedDataRequest
{
[JsonPropertyName("count")]
public int Count { get; set; } = 0;
public class PagedHeaderData : PagedDataRequest
{
[JsonPropertyName("count")]
public int Count { get; set; } = 0;
[JsonPropertyName("total")]
public long Total { get; set; } = 0;
}
[JsonPropertyName("total")]
public long Total { get; set; } = 0;
}
public class PagedMetaData : PagedHeaderData
{
[JsonPropertyName("next")]
public string? Next { get; set; }
public class PagedMetaData : PagedHeaderData
{
[JsonPropertyName("next")]
public string? Next { get; set; }
[JsonPropertyName("previous")]
public string? Previous { get; set; }
}
[JsonPropertyName("previous")]
public string? Previous { get; set; }
}

View file

@ -1,18 +1,17 @@
namespace Insight.Infrastructure.Models
{
public class TokenOptions
{
public string Key { get; set; }
public int Expires { get; set; }
public Uri? Audience { get; set; }
public Uri? Issuer { get; set; }
namespace Insight.Infrastructure.Models;
public TokenOptions(string key, int expires, Uri? audience = null, Uri? issuer = null)
{
Key = key;
Expires = expires;
Audience = audience;
Issuer = issuer;
}
public class TokenOptions
{
public string Key { get; set; }
public int Expires { get; set; }
public Uri? Audience { get; set; }
public Uri? Issuer { get; set; }
public TokenOptions(string key, int expires, Uri? audience = null, Uri? issuer = null)
{
Key = key;
Expires = expires;
Audience = audience;
Issuer = issuer;
}
}

View file

@ -4,33 +4,32 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using MongoDB.Driver;
namespace Insight.Infrastructure.Services
namespace Insight.Infrastructure.Services;
public class AccountService
{
public class AccountService
private readonly IMongoDatabase _database;
private readonly ILogger<AccountService> _logger;
public AccountService(IMongoDatabase database, ILogger<AccountService> logger)
{
private readonly IMongoDatabase _database;
private readonly ILogger<AccountService> _logger;
public AccountService(IMongoDatabase database, ILogger<AccountService> logger)
{
_database = database;
_logger = logger;
}
public Task<PagedList<InsightUser>> GetAsync(
FilterDefinition<InsightUser>? filter = null,
SortDefinition<InsightUser>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.User().GetPagedAsync(filter, sort, offset, limit, cancellationToken);
public Task<PagedList<InsightUser>> GetAsync(
HttpRequest request,
HttpResponse response,
FilterDefinition<InsightUser>? filter = null,
SortDefinition<InsightUser>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.User().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
_database = database;
_logger = logger;
}
public Task<PagedList<InsightUser>> GetAsync(
FilterDefinition<InsightUser>? filter = null,
SortDefinition<InsightUser>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.User().GetPagedAsync(filter, sort, offset, limit, cancellationToken);
public Task<PagedList<InsightUser>> GetAsync(
HttpRequest request,
HttpResponse response,
FilterDefinition<InsightUser>? filter = null,
SortDefinition<InsightUser>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.User().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
}

View file

@ -4,33 +4,32 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using MongoDB.Driver;
namespace Insight.Infrastructure.Services
namespace Insight.Infrastructure.Services;
public class AgentService
{
public class AgentService
private readonly IMongoDatabase _database;
private readonly ILogger<AgentService> _logger;
public AgentService(IMongoDatabase database, ILogger<AgentService> logger)
{
private readonly IMongoDatabase _database;
private readonly ILogger<AgentService> _logger;
public AgentService(IMongoDatabase database, ILogger<AgentService> logger)
{
_database = database;
_logger = logger;
}
public Task<PagedList<AgentEntity>> GetAsync(
FilterDefinition<AgentEntity>? filter = null,
SortDefinition<AgentEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Agent().GetPagedAsync(filter, sort, offset, limit, cancellationToken);
public Task<PagedList<AgentEntity>> GetAsync(
HttpRequest request,
HttpResponse response,
FilterDefinition<AgentEntity>? filter = null,
SortDefinition<AgentEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Agent().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
_database = database;
_logger = logger;
}
public Task<PagedList<AgentEntity>> GetAsync(
FilterDefinition<AgentEntity>? filter = null,
SortDefinition<AgentEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Agent().GetPagedAsync(filter, sort, offset, limit, cancellationToken);
public Task<PagedList<AgentEntity>> GetAsync(
HttpRequest request,
HttpResponse response,
FilterDefinition<AgentEntity>? filter = null,
SortDefinition<AgentEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Agent().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
}

View file

@ -5,108 +5,107 @@ using System.Globalization;
using System.Text;
using System.Text.Encodings.Web;
namespace Insight.Infrastructure.Services
namespace Insight.Infrastructure.Services;
public class AuthenticatorService
{
public class AuthenticatorService
private readonly IMongoDatabase _database;
private readonly UserManager<InsightUser> _userManager;
public AuthenticatorService(IMongoDatabase database, UserManager<InsightUser> userManager)
{
private readonly IMongoDatabase _database;
private readonly UserManager<InsightUser> _userManager;
_database = database;
_userManager = userManager;
}
public AuthenticatorService(IMongoDatabase database, UserManager<InsightUser> userManager)
public async Task<bool> GetStatusAsync(InsightUser user)
{
return await _userManager.GetTwoFactorEnabledAsync(user).ConfigureAwait(false);
}
public async Task<string?> GetKeyAsync(InsightUser user)
{
return await _userManager.GetAuthenticatorKeyAsync(user).ConfigureAwait(false);
}
public async Task<bool> ResetKeyAsync(InsightUser user)
{
var result = await _userManager.ResetAuthenticatorKeyAsync(user).ConfigureAwait(false);
return result.Succeeded;
}
public async Task<bool> VerifyAsync(InsightUser user, string code)
{
code = code.Replace(" ", string.Empty).Replace("-", string.Empty);
return await _userManager.VerifyTwoFactorTokenAsync(user, _userManager.Options.Tokens.AuthenticatorTokenProvider, code).ConfigureAwait(false);
}
public async Task<bool> EnableAsync(InsightUser user)
{
var result = await _userManager.SetTwoFactorEnabledAsync(user, true).ConfigureAwait(false);
return result.Succeeded;
}
public async Task<bool> DisableAsync(InsightUser user)
{
var result = await _userManager.SetTwoFactorEnabledAsync(user, false).ConfigureAwait(false);
return result.Succeeded;
}
public async Task<bool> DeleteAsync(InsightUser user)
{
var result = await _userManager.SetTwoFactorEnabledAsync(user, false).ConfigureAwait(false);
if (result.Succeeded is false) return false;
result = await _userManager.RemoveAuthenticationTokenAsync(user, "[AspNetUserStore]", "AuthenticatorKey").ConfigureAwait(false);
if (result.Succeeded is false) return false;
return true;
}
public async Task<int> CountRecoveryCodesAsync(InsightUser user)
{
return await _userManager.CountRecoveryCodesAsync(user).ConfigureAwait(false);
}
public async Task<bool> UseRecoveryCodeAsync(InsightUser user, string recoveryCode)
{
var result = await _userManager.RedeemTwoFactorRecoveryCodeAsync(user, recoveryCode).ConfigureAwait(false);
return result.Succeeded;
}
public async Task<IEnumerable<string>?> ResetRecoveryCodesAsync(InsightUser user, int count = 3)
{
return await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, count).ConfigureAwait(false);
}
public string GenerateQrCode(string email, string unformattedKey)
{
var encoder = UrlEncoder.Default;
return string.Format(CultureInfo.InvariantCulture,
@"otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6",
encoder.Encode("Insight"),
encoder.Encode(email),
unformattedKey);
}
public static string HumanizeKey(string unformattedKey)
{
var result = new StringBuilder();
int currentPosition = 0;
while (currentPosition + 4 < unformattedKey.Length)
{
_database = database;
_userManager = userManager;
result.Append(unformattedKey.AsSpan(currentPosition, 4)).Append(' ');
currentPosition += 4;
}
public async Task<bool> GetStatusAsync(InsightUser user)
if (currentPosition < unformattedKey.Length)
{
return await _userManager.GetTwoFactorEnabledAsync(user).ConfigureAwait(false);
result.Append(unformattedKey.AsSpan(currentPosition));
}
public async Task<string?> GetKeyAsync(InsightUser user)
{
return await _userManager.GetAuthenticatorKeyAsync(user).ConfigureAwait(false);
}
public async Task<bool> ResetKeyAsync(InsightUser user)
{
var result = await _userManager.ResetAuthenticatorKeyAsync(user).ConfigureAwait(false);
return result.Succeeded;
}
public async Task<bool> VerifyAsync(InsightUser user, string code)
{
code = code.Replace(" ", string.Empty).Replace("-", string.Empty);
return await _userManager.VerifyTwoFactorTokenAsync(user, _userManager.Options.Tokens.AuthenticatorTokenProvider, code).ConfigureAwait(false);
}
public async Task<bool> EnableAsync(InsightUser user)
{
var result = await _userManager.SetTwoFactorEnabledAsync(user, true).ConfigureAwait(false);
return result.Succeeded;
}
public async Task<bool> DisableAsync(InsightUser user)
{
var result = await _userManager.SetTwoFactorEnabledAsync(user, false).ConfigureAwait(false);
return result.Succeeded;
}
public async Task<bool> DeleteAsync(InsightUser user)
{
var result = await _userManager.SetTwoFactorEnabledAsync(user, false).ConfigureAwait(false);
if (result.Succeeded is false) return false;
result = await _userManager.RemoveAuthenticationTokenAsync(user, "[AspNetUserStore]", "AuthenticatorKey").ConfigureAwait(false);
if (result.Succeeded is false) return false;
return true;
}
public async Task<int> CountRecoveryCodesAsync(InsightUser user)
{
return await _userManager.CountRecoveryCodesAsync(user).ConfigureAwait(false);
}
public async Task<bool> UseRecoveryCodeAsync(InsightUser user, string recoveryCode)
{
var result = await _userManager.RedeemTwoFactorRecoveryCodeAsync(user, recoveryCode).ConfigureAwait(false);
return result.Succeeded;
}
public async Task<IEnumerable<string>?> ResetRecoveryCodesAsync(InsightUser user, int count = 3)
{
return await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, count).ConfigureAwait(false);
}
public string GenerateQrCode(string email, string unformattedKey)
{
var encoder = UrlEncoder.Default;
return string.Format(CultureInfo.InvariantCulture,
@"otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6",
encoder.Encode("Insight"),
encoder.Encode(email),
unformattedKey);
}
public static string HumanizeKey(string unformattedKey)
{
var result = new StringBuilder();
int currentPosition = 0;
while (currentPosition + 4 < unformattedKey.Length)
{
result.Append(unformattedKey.AsSpan(currentPosition, 4)).Append(' ');
currentPosition += 4;
}
if (currentPosition < unformattedKey.Length)
{
result.Append(unformattedKey.AsSpan(currentPosition));
}
return result.ToString().ToLowerInvariant();
}
return result.ToString().ToLowerInvariant();
}
}

View file

@ -4,33 +4,32 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using MongoDB.Driver;
namespace Insight.Infrastructure.Services
namespace Insight.Infrastructure.Services;
public class CustomerService
{
public class CustomerService
private readonly IMongoDatabase _database;
private readonly ILogger<CustomerService> _logger;
public CustomerService(IMongoDatabase database, ILogger<CustomerService> logger)
{
private readonly IMongoDatabase _database;
private readonly ILogger<CustomerService> _logger;
public CustomerService(IMongoDatabase database, ILogger<CustomerService> logger)
{
_database = database;
_logger = logger;
}
public Task<PagedList<CustomerEntity>> GetAsync(
FilterDefinition<CustomerEntity>? filter = null,
SortDefinition<CustomerEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Customer().GetPagedAsync(filter, sort, offset, limit, cancellationToken);
public Task<PagedList<CustomerEntity>> GetAsync(
HttpRequest request,
HttpResponse response,
FilterDefinition<CustomerEntity>? filter = null,
SortDefinition<CustomerEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Customer().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
_database = database;
_logger = logger;
}
public Task<PagedList<CustomerEntity>> GetAsync(
FilterDefinition<CustomerEntity>? filter = null,
SortDefinition<CustomerEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Customer().GetPagedAsync(filter, sort, offset, limit, cancellationToken);
public Task<PagedList<CustomerEntity>> GetAsync(
HttpRequest request,
HttpResponse response,
FilterDefinition<CustomerEntity>? filter = null,
SortDefinition<CustomerEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Customer().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
}

View file

@ -4,33 +4,32 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using MongoDB.Driver;
namespace Insight.Infrastructure.Services
namespace Insight.Infrastructure.Services;
public class HostService
{
public class HostService
private readonly IMongoDatabase _database;
private readonly ILogger<HostService> _logger;
public HostService(IMongoDatabase database, ILogger<HostService> logger)
{
private readonly IMongoDatabase _database;
private readonly ILogger<HostService> _logger;
public HostService(IMongoDatabase database, ILogger<HostService> logger)
{
_database = database;
_logger = logger;
}
public Task<PagedList<HostEntity>> GetAsync(
FilterDefinition<HostEntity>? filter = null,
SortDefinition<HostEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Host().GetPagedAsync(filter, sort, offset, limit, cancellationToken);
public Task<PagedList<HostEntity>> GetAsync(
HttpRequest request,
HttpResponse response,
FilterDefinition<HostEntity>? filter = null,
SortDefinition<HostEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Host().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
_database = database;
_logger = logger;
}
public Task<PagedList<HostEntity>> GetAsync(
FilterDefinition<HostEntity>? filter = null,
SortDefinition<HostEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Host().GetPagedAsync(filter, sort, offset, limit, cancellationToken);
public Task<PagedList<HostEntity>> GetAsync(
HttpRequest request,
HttpResponse response,
FilterDefinition<HostEntity>? filter = null,
SortDefinition<HostEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Host().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
}

View file

@ -3,136 +3,135 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using System.Security.Claims;
namespace Insight.Infrastructure.Services
namespace Insight.Infrastructure.Services;
public class IdentityService
{
public class IdentityService
private readonly UserManager<InsightUser> _userManager;
private readonly RoleManager<InsightRole> _roleManager;
private readonly ILogger<IdentityService> _logger;
public IdentityService(UserManager<InsightUser> userManager, RoleManager<InsightRole> roleManager, ILogger<IdentityService> logger)
{
private readonly UserManager<InsightUser> _userManager;
private readonly RoleManager<InsightRole> _roleManager;
private readonly ILogger<IdentityService> _logger;
_userManager = userManager;
_roleManager = roleManager;
_logger = logger;
}
public IdentityService(UserManager<InsightUser> userManager, RoleManager<InsightRole> roleManager, ILogger<IdentityService> logger)
public async Task SeedAsync()
{
// SEED ROLES
if (await _roleManager.FindByNameAsync("system") is not InsightRole systemRole)
{
_userManager = userManager;
_roleManager = roleManager;
_logger = logger;
var result = await CreateRoleAsync("system");
if (result.Succeeded is false) throw new InvalidProgramException("seeding: system role failed");
systemRole = await _roleManager.FindByNameAsync("system") ?? throw new InvalidProgramException("seeding: system role failed");
}
public async Task SeedAsync()
if (await _roleManager.FindByNameAsync("administrator") is not InsightRole administratorRole)
{
// SEED ROLES
if (await _roleManager.FindByNameAsync("system") is not InsightRole systemRole)
{
var result = await CreateRoleAsync("system");
if (result.Succeeded is false) throw new InvalidProgramException("seeding: system role failed");
var result = await CreateRoleAsync("administrator");
if (result.Succeeded is false) throw new InvalidProgramException("seeding: administrator role failed");
systemRole = await _roleManager.FindByNameAsync("system") ?? throw new InvalidProgramException("seeding: system role failed");
}
if (await _roleManager.FindByNameAsync("administrator") is not InsightRole administratorRole)
{
var result = await CreateRoleAsync("administrator");
if (result.Succeeded is false) throw new InvalidProgramException("seeding: administrator role failed");
administratorRole = await _roleManager.FindByNameAsync("administrator") ?? throw new InvalidProgramException("seeding: administrator role failed");
}
if (await _roleManager.FindByNameAsync("chat") is not InsightRole chatRole)
{
var result = await CreateRoleAsync("chat");
if (result.Succeeded is false) throw new InvalidProgramException("seeding: chat role failed");
chatRole = await _roleManager.FindByNameAsync("chat") ?? throw new InvalidProgramException("seeding: chat role failed");
}
// SEED USERS
if (await _userManager.FindByEmailAsync("system@insight.local") is not InsightUser systemUser)
{
var result = await CreateUserAsync("system@insight.local", "Replica3-Unroasted-Respect");
if (result.Succeeded is false) throw new InvalidProgramException("seeding: system user failed");
systemUser = await _userManager.FindByEmailAsync("system@insight.local") ?? throw new InvalidProgramException("seeding: system user failed");
}
if (systemUser.Roles.Any(p => p == systemRole.Id) is false)
{
var assign = await _userManager.AddToRoleAsync(systemUser, systemRole.Name);
if (assign.Succeeded is false) throw new InvalidProgramException("seeding: system user roles failed");
}
administratorRole = await _roleManager.FindByNameAsync("administrator") ?? throw new InvalidProgramException("seeding: administrator role failed");
}
public async Task<IdentityResult> CreateUserAsync(string email, string password)
if (await _roleManager.FindByNameAsync("chat") is not InsightRole chatRole)
{
var user = new InsightUser
{
UserName = email,
NormalizedUserName = email.ToUpperInvariant(),
Email = email,
NormalizedEmail = email.ToUpperInvariant(),
};
var result = await CreateRoleAsync("chat");
if (result.Succeeded is false) throw new InvalidProgramException("seeding: chat role failed");
return await _userManager.CreateAsync(user, password);
chatRole = await _roleManager.FindByNameAsync("chat") ?? throw new InvalidProgramException("seeding: chat role failed");
}
public async Task<IdentityResult> CreateRoleAsync(string name)
// SEED USERS
if (await _userManager.FindByEmailAsync("system@insight.local") is not InsightUser systemUser)
{
var role = new InsightRole
{
Name = name,
NormalizedName = name.ToUpperInvariant()
};
var result = await CreateUserAsync("system@insight.local", "Replica3-Unroasted-Respect");
if (result.Succeeded is false) throw new InvalidProgramException("seeding: system user failed");
return await _roleManager.CreateAsync(role);
systemUser = await _userManager.FindByEmailAsync("system@insight.local") ?? throw new InvalidProgramException("seeding: system user failed");
}
public async Task<InsightUser> LoginAsync(string email, string password, string? code = null)
if (systemUser.Roles.Any(p => p == systemRole.Id) is false)
{
if (await _userManager.FindByEmailAsync(email) is not InsightUser user) throw new InvalidDataException("Invalid Credentials");
if (await _userManager.CheckPasswordAsync(user, password) is false) throw new InvalidDataException("Invalid Credentials");
if (await _userManager.GetTwoFactorEnabledAsync(user))
{
if (string.IsNullOrWhiteSpace(code)) throw new InvalidOperationException("Requires 2FA Code");
var authCode = code.Replace(" ", string.Empty).Replace("-", string.Empty);
if (await _userManager.VerifyTwoFactorTokenAsync(user, _userManager.Options.Tokens.AuthenticatorTokenProvider, authCode) is false)
{
throw new InvalidDataException("Invalid 2FA Code");
}
}
return user;
}
public async Task<bool> ChangePasswordAsync(InsightUser user, string current, string @new)
{
var result = await _userManager.ChangePasswordAsync(user, current, @new).ConfigureAwait(false);
return result.Succeeded;
}
public async Task<InsightUser?> GetByEmailAsync(string key)
{
var result = await _userManager.FindByEmailAsync(key).ConfigureAwait(false);
if (result is not null) return result;
return null;
}
public async Task<IList<Claim>> GetClaimsAsync(InsightUser user, bool includeRoles = true)
{
var claims = await _userManager.GetClaimsAsync(user).ConfigureAwait(false);
if (includeRoles)
{
var roles = await _userManager.GetRolesAsync(user).ConfigureAwait(false);
foreach (var role in roles) claims.Add(new Claim(ClaimTypes.Role, role));
}
claims.Add(new Claim(ClaimTypes.Email, user.Email));
claims.Add(new Claim("user", user.UserName));
return claims;
var assign = await _userManager.AddToRoleAsync(systemUser, systemRole.Name);
if (assign.Succeeded is false) throw new InvalidProgramException("seeding: system user roles failed");
}
}
public async Task<IdentityResult> CreateUserAsync(string email, string password)
{
var user = new InsightUser
{
UserName = email,
NormalizedUserName = email.ToUpperInvariant(),
Email = email,
NormalizedEmail = email.ToUpperInvariant(),
};
return await _userManager.CreateAsync(user, password);
}
public async Task<IdentityResult> CreateRoleAsync(string name)
{
var role = new InsightRole
{
Name = name,
NormalizedName = name.ToUpperInvariant()
};
return await _roleManager.CreateAsync(role);
}
public async Task<InsightUser> LoginAsync(string email, string password, string? code = null)
{
if (await _userManager.FindByEmailAsync(email) is not InsightUser user) throw new InvalidDataException("Invalid Credentials");
if (await _userManager.CheckPasswordAsync(user, password) is false) throw new InvalidDataException("Invalid Credentials");
if (await _userManager.GetTwoFactorEnabledAsync(user))
{
if (string.IsNullOrWhiteSpace(code)) throw new InvalidOperationException("Requires 2FA Code");
var authCode = code.Replace(" ", string.Empty).Replace("-", string.Empty);
if (await _userManager.VerifyTwoFactorTokenAsync(user, _userManager.Options.Tokens.AuthenticatorTokenProvider, authCode) is false)
{
throw new InvalidDataException("Invalid 2FA Code");
}
}
return user;
}
public async Task<bool> ChangePasswordAsync(InsightUser user, string current, string @new)
{
var result = await _userManager.ChangePasswordAsync(user, current, @new).ConfigureAwait(false);
return result.Succeeded;
}
public async Task<InsightUser?> GetByEmailAsync(string key)
{
var result = await _userManager.FindByEmailAsync(key).ConfigureAwait(false);
if (result is not null) return result;
return null;
}
public async Task<IList<Claim>> GetClaimsAsync(InsightUser user, bool includeRoles = true)
{
var claims = await _userManager.GetClaimsAsync(user).ConfigureAwait(false);
if (includeRoles)
{
var roles = await _userManager.GetRolesAsync(user).ConfigureAwait(false);
foreach (var role in roles) claims.Add(new Claim(ClaimTypes.Role, role));
}
claims.Add(new Claim(ClaimTypes.Email, user.Email));
claims.Add(new Claim("user", user.UserName));
return claims;
}
}

View file

@ -4,33 +4,32 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using MongoDB.Driver;
namespace Insight.Infrastructure.Services
namespace Insight.Infrastructure.Services;
public class InventoryService
{
public class InventoryService
private readonly IMongoDatabase _database;
private readonly ILogger<InventoryService> _logger;
public InventoryService(IMongoDatabase database, ILogger<InventoryService> logger)
{
private readonly IMongoDatabase _database;
private readonly ILogger<InventoryService> _logger;
public InventoryService(IMongoDatabase database, ILogger<InventoryService> logger)
{
_database = database;
_logger = logger;
}
public Task<PagedList<HostApplicationEntity>> GetAsync(
FilterDefinition<HostApplicationEntity>? filter = null,
SortDefinition<HostApplicationEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.HostApplication().GetPagedAsync(filter, sort, offset, limit, cancellationToken);
public Task<PagedList<HostApplicationEntity>> GetAsync(
HttpRequest request,
HttpResponse response,
FilterDefinition<HostApplicationEntity>? filter = null,
SortDefinition<HostApplicationEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.HostApplication().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
_database = database;
_logger = logger;
}
public Task<PagedList<HostApplicationEntity>> GetAsync(
FilterDefinition<HostApplicationEntity>? filter = null,
SortDefinition<HostApplicationEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.HostApplication().GetPagedAsync(filter, sort, offset, limit, cancellationToken);
public Task<PagedList<HostApplicationEntity>> GetAsync(
HttpRequest request,
HttpResponse response,
FilterDefinition<HostApplicationEntity>? filter = null,
SortDefinition<HostApplicationEntity>? sort = null,
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.HostApplication().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
}

View file

@ -8,142 +8,141 @@ using System.Net;
using System.Security.Cryptography;
using System.Text;
namespace Insight.Infrastructure.Services
namespace Insight.Infrastructure.Services;
public class TokenService
{
public class TokenService
private readonly TokenOptions _options;
private readonly IdentityService _identityService;
private readonly IMongoDatabase _database;
public TokenService(TokenOptions options, IdentityService identityService, IMongoDatabase database)
{
private readonly TokenOptions _options;
private readonly IdentityService _identityService;
private readonly IMongoDatabase _database;
_options = options;
_identityService = identityService;
_database = database;
}
public TokenService(TokenOptions options, IdentityService identityService, IMongoDatabase database)
public async Task<TokenResponse> GetAsync(string email, string password, string? code = null, IPAddress? ipa = null)
{
var user = await _identityService.LoginAsync(email, password, code).ConfigureAwait(false);
var accessToken = await CreateAccessTokenAsync(user, ipa).ConfigureAwait(false);
var refreshToken = await CreateRefreshTokenAsync(user, ipa).ConfigureAwait(false);
return new TokenResponse
{
_options = options;
_identityService = identityService;
_database = database;
AccessToken = accessToken.Item1,
ExpireInSeconds = accessToken.Item2,
RefreshToken = refreshToken.Item1
};
}
public async Task<TokenResponse> RefreshAsync(string refreshToken, IPAddress? ipa = null)
{
if (string.IsNullOrWhiteSpace(refreshToken)) throw new ArgumentNullException(nameof(refreshToken));
var user = await _database.User().Find(p => p.RefreshTokens.Any(t => t.Token == refreshToken)).FirstOrDefaultAsync();
if (user is null || user.RefreshTokens is null) throw new InvalidDataException("Invalid Refresh Token");
var token = user.RefreshTokens.First(p => p.Token == refreshToken);
if (token.IsRevoked)
{
// todo: revoke all descendant tokens in case this token has been compromised
throw new InvalidDataException("Invalid Refresh Token");
}
public async Task<TokenResponse> GetAsync(string email, string password, string? code = null, IPAddress? ipa = null)
if (token.IsActive is false)
{
var user = await _identityService.LoginAsync(email, password, code).ConfigureAwait(false);
throw new InvalidDataException("Invalid Refresh Token");
}
var accessToken = await CreateAccessTokenAsync(user, ipa).ConfigureAwait(false);
var refreshToken = await CreateRefreshTokenAsync(user, ipa).ConfigureAwait(false);
// remove actual refresh token
user.RefreshTokens.Remove(token);
return new TokenResponse
// remove old refresh tokens from user
user.RefreshTokens.RemoveAll(p => p.IsExpired && p.IsRevoked is false);
// update users refreshTokens
await _database.User().UpdateOneAsync(Builders<InsightUser>
.Filter.Eq(p => p.UserName, user.UserName), Builders<InsightUser>
.Update.Set(p => p.RefreshTokens, user.RefreshTokens));
// create new refresh token
var newRefreshToken = await CreateRefreshTokenAsync(user, ipa).ConfigureAwait(false);
// create access token
var accessToken = await CreateAccessTokenAsync(user, ipa).ConfigureAwait(false);
return new TokenResponse
{
AccessToken = accessToken.Item1,
ExpireInSeconds = accessToken.Item2,
RefreshToken = newRefreshToken.Item1,
};
}
public async Task RevokeAsync(string refreshToken, string reason, IPAddress? ipa = null)
{
if (string.IsNullOrWhiteSpace(refreshToken)) throw new ArgumentNullException(nameof(refreshToken));
var user = await _database.User().Find(p => p.RefreshTokens.Any(t => t.Token == refreshToken)).FirstOrDefaultAsync();
if (user is null || user.RefreshTokens is null) throw new InvalidDataException("Invalid Refresh Token");
var token = user.RefreshTokens.First(p => p.Token == refreshToken);
if (token.IsActive is false)
{
throw new InvalidDataException("Invalid Refresh Token");
}
token.Revoked = DateTime.Now;
token.RevokedByIp = ipa?.ToString();
token.ReasonRevoked = reason;
}
private async Task<(string, int)> CreateAccessTokenAsync(InsightUser user, IPAddress? ipa = null)
{
var claims = await _identityService.GetClaimsAsync(user).ConfigureAwait(false);
var key = Encoding.UTF8.GetBytes(_options.Key);
var secret = new SymmetricSecurityKey(key);
var signing = new SigningCredentials(secret, SecurityAlgorithms.HmacSha256);
var securityToken = new JwtSecurityToken(
_options.Issuer?.ToString(),
_options.Audience?.ToString(),
claims,
DateTime.Now,
DateTime.Now.AddSeconds(Convert.ToDouble(_options.Expires)),
signing);
var token = new JwtSecurityTokenHandler().WriteToken(securityToken);
return (token, (int)TimeSpan.FromMinutes(Convert.ToDouble(_options.Expires)).TotalSeconds);
}
private async Task<(string, int)> CreateRefreshTokenAsync(InsightUser user, IPAddress? ipa = null)
{
var randomNumber = new byte[32];
using var rng = RandomNumberGenerator.Create();
rng.GetBytes(randomNumber);
var refreshToken = Convert.ToBase64String(randomNumber);
await _database.User()
.UpdateOneAsync(Builders<InsightUser>
.Filter.Eq(p => p.UserName, user.UserName), Builders<InsightUser>
.Update.AddToSet(p => p.RefreshTokens, new RefreshToken
{
AccessToken = accessToken.Item1,
ExpireInSeconds = accessToken.Item2,
RefreshToken = refreshToken.Item1
};
}
Token = refreshToken,
Created = DateTime.Now,
Expires = DateTime.Now.AddMinutes(30), // change offset to config based
CreatedByIp = ipa?.ToString()
}));
public async Task<TokenResponse> RefreshAsync(string refreshToken, IPAddress? ipa = null)
{
if (string.IsNullOrWhiteSpace(refreshToken)) throw new ArgumentNullException(nameof(refreshToken));
var user = await _database.User().Find(p => p.RefreshTokens.Any(t => t.Token == refreshToken)).FirstOrDefaultAsync();
if (user is null || user.RefreshTokens is null) throw new InvalidDataException("Invalid Refresh Token");
var token = user.RefreshTokens.First(p => p.Token == refreshToken);
if (token.IsRevoked)
{
// todo: revoke all descendant tokens in case this token has been compromised
throw new InvalidDataException("Invalid Refresh Token");
}
if (token.IsActive is false)
{
throw new InvalidDataException("Invalid Refresh Token");
}
// remove actual refresh token
user.RefreshTokens.Remove(token);
// remove old refresh tokens from user
user.RefreshTokens.RemoveAll(p => p.IsExpired && p.IsRevoked is false);
// update users refreshTokens
await _database.User().UpdateOneAsync(Builders<InsightUser>
.Filter.Eq(p => p.UserName, user.UserName), Builders<InsightUser>
.Update.Set(p => p.RefreshTokens, user.RefreshTokens));
// create new refresh token
var newRefreshToken = await CreateRefreshTokenAsync(user, ipa).ConfigureAwait(false);
// create access token
var accessToken = await CreateAccessTokenAsync(user, ipa).ConfigureAwait(false);
return new TokenResponse
{
AccessToken = accessToken.Item1,
ExpireInSeconds = accessToken.Item2,
RefreshToken = newRefreshToken.Item1,
};
}
public async Task RevokeAsync(string refreshToken, string reason, IPAddress? ipa = null)
{
if (string.IsNullOrWhiteSpace(refreshToken)) throw new ArgumentNullException(nameof(refreshToken));
var user = await _database.User().Find(p => p.RefreshTokens.Any(t => t.Token == refreshToken)).FirstOrDefaultAsync();
if (user is null || user.RefreshTokens is null) throw new InvalidDataException("Invalid Refresh Token");
var token = user.RefreshTokens.First(p => p.Token == refreshToken);
if (token.IsActive is false)
{
throw new InvalidDataException("Invalid Refresh Token");
}
token.Revoked = DateTime.Now;
token.RevokedByIp = ipa?.ToString();
token.ReasonRevoked = reason;
}
private async Task<(string, int)> CreateAccessTokenAsync(InsightUser user, IPAddress? ipa = null)
{
var claims = await _identityService.GetClaimsAsync(user).ConfigureAwait(false);
var key = Encoding.UTF8.GetBytes(_options.Key);
var secret = new SymmetricSecurityKey(key);
var signing = new SigningCredentials(secret, SecurityAlgorithms.HmacSha256);
var securityToken = new JwtSecurityToken(
_options.Issuer?.ToString(),
_options.Audience?.ToString(),
claims,
DateTime.Now,
DateTime.Now.AddSeconds(Convert.ToDouble(_options.Expires)),
signing);
var token = new JwtSecurityTokenHandler().WriteToken(securityToken);
return (token, (int)TimeSpan.FromMinutes(Convert.ToDouble(_options.Expires)).TotalSeconds);
}
private async Task<(string, int)> CreateRefreshTokenAsync(InsightUser user, IPAddress? ipa = null)
{
var randomNumber = new byte[32];
using var rng = RandomNumberGenerator.Create();
rng.GetBytes(randomNumber);
var refreshToken = Convert.ToBase64String(randomNumber);
await _database.User()
.UpdateOneAsync(Builders<InsightUser>
.Filter.Eq(p => p.UserName, user.UserName), Builders<InsightUser>
.Update.AddToSet(p => p.RefreshTokens, new RefreshToken
{
Token = refreshToken,
Created = DateTime.Now,
Expires = DateTime.Now.AddMinutes(30), // change offset to config based
CreatedByIp = ipa?.ToString()
}));
return (refreshToken, (int)TimeSpan.FromMinutes(30).TotalSeconds);
}
return (refreshToken, (int)TimeSpan.FromMinutes(30).TotalSeconds);
}
}