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,8 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
</Project>

View file

@ -1,10 +1,9 @@
namespace Insight.Agent
namespace Insight.Agent;
public static class Appsettings
{
public static class Appsettings
{
public const string Api = "api";
public const string ServerHost = "server.host";
public const string ServerPort = "server.port";
public const string TrapPort = "trap.port";
}
}

View file

@ -1,7 +1,7 @@
namespace Insight.Agent.Constants
namespace Insight.Agent.Constants;
public static class Deploy
{
public static class Deploy
{
public static class Updater
{
public const string Name = "Updater";
@ -17,5 +17,4 @@
public static Uri GetUpdateHref(Uri api, string appName)
=> new($"{api.AbsoluteUri}/update/{appName.ToLower()}/windows");
}
}

View file

@ -1,14 +1,13 @@
using Microsoft.Extensions.Configuration;
namespace Insight.Agent.Extensions
namespace Insight.Agent.Extensions;
public static class ConfigurationExtensions
{
public static class ConfigurationExtensions
{
public static IConfigurationBuilder Defaults(this IConfigurationBuilder configuration)
{
configuration.Sources.Clear();
configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
return configuration.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: true, reloadOnChange: true);
}
}
}

View file

@ -1,10 +1,10 @@
using System.Diagnostics;
using System.Runtime.Versioning;
namespace Insight.Agent.Extensions
namespace Insight.Agent.Extensions;
public static class Linux
{
public static class Linux
{
[SupportedOSPlatform("linux")]
public static string Bash(this string cmd)
{
@ -28,5 +28,4 @@ namespace Insight.Agent.Extensions
return result;
}
}
}

View file

@ -1,10 +1,10 @@
using System.Management;
using System.Runtime.Versioning;
namespace Insight.Agent
namespace Insight.Agent;
public static class ManagmentExtensions
{
public static class ManagmentExtensions
{
[SupportedOSPlatform("windows")]
public static HashSet<string> GetPropertyHashes(this ManagementBaseObject @object)
{
@ -65,5 +65,4 @@ namespace Insight.Agent
value = obj;
return true;
}
}
}

View file

@ -2,10 +2,10 @@
using System.ServiceProcess;
using System.Text;
namespace Insight.Agent
namespace Insight.Agent;
internal class Helpers
{
internal class Helpers
{
internal static string? EscapeWql(string text)
{
if (text == null) return null;
@ -40,5 +40,4 @@ namespace Insight.Agent
if (winRm.Status != ServiceControllerStatus.Running) return false;
return true;
}
}
}

View file

@ -1,7 +1,6 @@
namespace Insight.Agent.Models
namespace Insight.Agent.Models;
public class Config
{
public class Config
{
public Guid? Serial { get; set; }
}
}

View file

@ -2,16 +2,15 @@
using Microsoft.Extensions.Logging.Abstractions;
using System.Runtime.Versioning;
namespace Insight.Agent.Services
namespace Insight.Agent.Services;
[SupportedOSPlatform("linux")]
public partial class CollectorService
{
[SupportedOSPlatform("linux")]
public partial class CollectorService
{
public ILogger<CollectorService> Logger { get; }
public CollectorService(ILogger<CollectorService>? logger = null)
{
Logger = logger ?? NullLogger<CollectorService>.Instance;
}
}
}

View file

@ -1,9 +1,9 @@
using System.Text.Json;
namespace Insight.Agent.Services
namespace Insight.Agent.Services;
public static class Configurator
{
public static class Configurator
{
public static async ValueTask<TConfig> ReadAsync<TConfig>(string file, CancellationToken cancellationToken = default)
where TConfig : class
{
@ -93,5 +93,4 @@ namespace Insight.Agent.Services
await File.WriteAllTextAsync(file, json, cancellationToken);
}
}
}

View file

@ -1,9 +1,8 @@
using Insight.Domain.Constants;
namespace Insight.Api
namespace Insight.Api;
public static class Locations
{
public static class Locations
{
public static DirectoryInfo UpdatesPath { get; } = new DirectoryInfo($"{Configuration.AppDirectory?.FullName}/files/updates");
}
}

View file

@ -4,11 +4,11 @@ using Insight.Infrastructure.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Insight.Api.Controllers
namespace Insight.Api.Controllers;
[ApiController, Route("api/accounts")]
public class AccountController : ControllerBase
{
[ApiController, Route("api/accounts")]
public class AccountController : ControllerBase
{
private readonly IdentityService _identityService;
private readonly AccountService _accountService;
private readonly ILogger<AccountController> _logger;
@ -72,5 +72,4 @@ namespace Insight.Api.Controllers
return Ok(model.Email);
}
}
}

View file

@ -3,11 +3,11 @@ using Insight.Infrastructure.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Insight.Api.Controllers
namespace Insight.Api.Controllers;
[ApiController, Route("api/agents")]
public class AgentController : ControllerBase
{
[ApiController, Route("api/agents")]
public class AgentController : ControllerBase
{
private readonly AgentService _agentService;
private readonly ILogger<AgentController> _logger;
@ -40,5 +40,4 @@ namespace Insight.Api.Controllers
return BadRequest(ex.Message);
}
}
}
}

View file

@ -3,11 +3,11 @@ using Insight.Infrastructure.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Insight.Api.Controllers
namespace Insight.Api.Controllers;
[ApiController, Route("api/customers")]
public class CustomerController : ControllerBase
{
[ApiController, Route("api/customers")]
public class CustomerController : ControllerBase
{
private readonly CustomerService _customerService;
private readonly ILogger<CustomerController> _logger;
@ -40,5 +40,4 @@ namespace Insight.Api.Controllers
return BadRequest(ex.Message);
}
}
}
}

View file

@ -3,11 +3,11 @@ using Insight.Infrastructure.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Insight.Api.Controllers
namespace Insight.Api.Controllers;
[ApiController, Route("api/hosts")]
public class HostController : ControllerBase
{
[ApiController, Route("api/hosts")]
public class HostController : ControllerBase
{
private readonly HostService _hostService;
private readonly ILogger<HostController> _logger;
@ -40,5 +40,4 @@ namespace Insight.Api.Controllers
return BadRequest(ex.Message);
}
}
}
}

View file

@ -8,11 +8,11 @@ using MongoDB.Driver;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
namespace Insight.Api.Controllers
namespace Insight.Api.Controllers;
[ApiController, Route("api/inventory")]
public class InventoryController : ControllerBase
{
[ApiController, Route("api/inventory")]
public class InventoryController : ControllerBase
{
private readonly InventoryService _inventoryService;
private readonly ILogger<InventoryController> _logger;
@ -69,5 +69,4 @@ namespace Insight.Api.Controllers
[JsonPropertyName("name")]
public string? Name { get; set; }
}
}
}

View file

@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Mvc;
namespace Insight.Server.Controllers
namespace Insight.Server.Controllers;
[ApiController, Route("api/setup")]
public class SetupController : ControllerBase
{
[ApiController, Route("api/setup")]
public class SetupController : ControllerBase
{
private readonly ILogger<SetupController> _logger;
public SetupController(ILogger<SetupController> logger)
@ -26,5 +26,4 @@ namespace Insight.Server.Controllers
return File(await System.IO.File.ReadAllBytesAsync(files.OrderBy(p => p.LastWriteTime).First().FullName, cancellationToken), "application/zip", "setup-win64.zip");
}
}
}

View file

@ -3,11 +3,11 @@ using Insight.Infrastructure.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Insight.Api.Controllers
namespace Insight.Api.Controllers;
[ApiController, Route("api/token", Order = 0)]
public class TokenController : ControllerBase
{
[ApiController, Route("api/token", Order = 0)]
public class TokenController : ControllerBase
{
private readonly TokenService _tokenService;
public TokenController(TokenService tokenService)
@ -81,5 +81,4 @@ namespace Insight.Api.Controllers
return BadRequest(ex.Message);
}
}
}
}

View file

@ -2,11 +2,11 @@
using Insight.Domain.Models;
using Microsoft.AspNetCore.Mvc;
namespace Insight.Server.Controllers
namespace Insight.Server.Controllers;
[ApiController, Route("api/update")]
public class UpdateController : ControllerBase
{
[ApiController, Route("api/update")]
public class UpdateController : ControllerBase
{
private readonly ILogger<UpdateController> _logger;
public UpdateController(ILogger<UpdateController> logger)
@ -89,5 +89,4 @@ namespace Insight.Server.Controllers
Uri = new Uri($"{Request.Scheme}://{Request.Host}/api/{relPath}")
});
}
}
}

View file

@ -2,10 +2,10 @@
using Microsoft.OpenApi.Models;
using System.Reflection;
namespace Insight.Api.Hosting
namespace Insight.Api.Hosting;
public static class ServiceExtensions
{
public static class ServiceExtensions
{
internal static IServiceCollection AddSwaggerServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddEndpointsApiExplorer();
@ -55,5 +55,4 @@ namespace Insight.Api.Hosting
return services;
}
}
}

View file

@ -1,9 +1,9 @@
using System.ComponentModel.DataAnnotations;
namespace Insight.Api.Models
namespace Insight.Api.Models;
public class RegistrationModel
{
public class RegistrationModel
{
public string? FirstName { get; set; }
public string? LastName { get; set; }
@ -19,5 +19,4 @@ namespace Insight.Api.Models
[DataType(DataType.Password)]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string? ConfirmPassword { get; set; }
}
}

View file

@ -3,10 +3,10 @@ using Insight.Domain.Constants;
using Insight.Infrastructure;
using Microsoft.Extensions.FileProviders;
namespace Insight.Api
namespace Insight.Api;
internal class Program
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
@ -95,5 +95,4 @@ namespace Insight.Api
await app.RunAsync();
}
}
}

View file

@ -1,7 +1,7 @@
namespace Insight.Infrastructure
namespace Insight.Infrastructure;
public class Appsettings
{
public class Appsettings
{
public const string Database = "database";
public const string JwtKey = "jwt.key";
public const string JwtAudience = "jwt.audience";
@ -10,5 +10,4 @@
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");
}
}

View file

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

View file

@ -3,11 +3,11 @@ 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; }
@ -58,5 +58,4 @@ namespace Insight.Infrastructure.Entities
if (Activity is null) return false;
return Activity.Value.ToLocalTime().Add(TimeSpan.FromSeconds(60)).Subtract(DateTime.Now).Seconds > 0;
}
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -33,5 +33,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("timestamp")]
public DateTime? Timestamp { get; set; }
}
}

View file

@ -3,11 +3,11 @@ 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; }
@ -25,5 +25,4 @@ namespace Insight.Infrastructure.Entities
[BsonIgnoreIfNull, JsonIgnore]
public List<HostEntity>? Hosts { get; set; }
}
}

View file

@ -3,11 +3,11 @@ 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; }
@ -34,5 +34,4 @@ namespace Insight.Infrastructure.Entities
[BsonIgnoreIfNull, JsonIgnore]
public List<AgentEntity>? Agents { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -36,5 +36,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("installdate")]
public DateTime? InstallDate { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -48,5 +48,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("pnp")]
public string? Pnp { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -90,11 +90,11 @@ namespace Insight.Infrastructure.Entities
[BsonIgnoreIfNull, JsonIgnore]
public List<HostHypervisorVirtualMaschineConfigEntity>? Configs { get; set; }
}
}
[BsonIgnoreExtraElements]
public class HostHypervisorVirtualMaschineConfigEntity
{
[BsonIgnoreExtraElements]
public class HostHypervisorVirtualMaschineConfigEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
@ -184,5 +184,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("swap_data_root")]
public string? SwapFileDataRoot { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -78,11 +78,11 @@ namespace Insight.Infrastructure.Entities
[BsonElement("packets_outgoing_errors")]
public long? OutgoingPacketsWithErrors { get; set; }
}
}
[BsonIgnoreExtraElements]
public class HostInterfaceAddressEntity
{
[BsonIgnoreExtraElements]
public class HostInterfaceAddressEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
@ -115,11 +115,11 @@ namespace Insight.Infrastructure.Entities
[BsonIgnoreIfNull, JsonIgnore]
public List<HostInterfaceEntity>? Interfaces { get; set; }
}
}
[BsonIgnoreExtraElements]
public class HostInterfaceGatewayEntity
{
[BsonIgnoreExtraElements]
public class HostInterfaceGatewayEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
@ -146,11 +146,11 @@ namespace Insight.Infrastructure.Entities
[BsonIgnoreIfNull, JsonIgnore]
public List<HostInterfaceEntity>? Interfaces { get; set; }
}
}
[BsonIgnoreExtraElements]
public class HostInterfaceNameserverEntity
{
[BsonIgnoreExtraElements]
public class HostInterfaceNameserverEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
@ -177,11 +177,11 @@ namespace Insight.Infrastructure.Entities
[BsonIgnoreIfNull, JsonIgnore]
public List<HostInterfaceEntity>? Interfaces { get; set; }
}
}
[BsonIgnoreExtraElements]
public class HostInterfaceRouteEntity
{
[BsonIgnoreExtraElements]
public class HostInterfaceRouteEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
@ -214,5 +214,4 @@ namespace Insight.Infrastructure.Entities
[BsonIgnoreIfNull, JsonIgnore]
public List<HostInterfaceEntity>? Interfaces { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -33,5 +33,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("timestamp")]
public DateTime? Timestamp { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -39,5 +39,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("timestamp")]
public DateTime? Timestamp { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -36,5 +36,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("Date")]
public DateTime? Date { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -54,5 +54,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("voltage_current")]
public uint? CurrentVoltage { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -36,5 +36,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("installed")]
public DateTime? Installed { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -36,5 +36,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("comment")]
public string? Comment { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -66,5 +66,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("pnp")]
public string? PNP { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -51,5 +51,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("account")]
public string? Account { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -36,5 +36,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("state")]
public string? State { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -60,11 +60,11 @@ namespace Insight.Infrastructure.Entities
[BsonIgnoreIfNull, JsonIgnore]
public List<HostStoragePoolVirtualDiskEntity>? VirtualDisks { get; set; }
}
}
[BsonIgnoreExtraElements]
public class HostStoragePoolVirtualDiskEntity
{
[BsonIgnoreExtraElements]
public class HostStoragePoolVirtualDiskEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
@ -127,11 +127,11 @@ namespace Insight.Infrastructure.Entities
[BsonElement("states")]
public List<string>? States { get; set; }
}
}
[BsonIgnoreExtraElements]
public class HostStoragePoolPhysicalDiskEntity
{
[BsonIgnoreExtraElements]
public class HostStoragePoolPhysicalDiskEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
@ -203,5 +203,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("states")]
public List<string>? States { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -30,5 +30,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("license")]
public string? License { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -57,5 +57,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("reboot"), BsonIgnoreIfNull] // pending only
public string? RebootBehavior { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -57,11 +57,11 @@ namespace Insight.Infrastructure.Entities
[BsonElement("password_required")]
public bool? PasswordRequired { get; set; }
}
}
[BsonIgnoreExtraElements]
public class HostGroupEntity
{
[BsonIgnoreExtraElements]
public class HostGroupEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
@ -91,11 +91,11 @@ namespace Insight.Infrastructure.Entities
[BsonElement("localaccount")]
public bool? LocalAccount { get; set; }
}
}
[BsonIgnoreExtraElements]
public class HostUserGroupEntity
{
[BsonIgnoreExtraElements]
public class HostUserGroupEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
@ -116,5 +116,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("update")]
public DateTime? Update { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -36,5 +36,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("date")]
public DateTime? Date { get; set; }
}
}

View file

@ -2,11 +2,11 @@
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; }
@ -72,5 +72,4 @@ namespace Insight.Infrastructure.Entities
[BsonElement("provider")]
public string? Provider { get; set; }
}
}

View file

@ -4,22 +4,22 @@ 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(string userName, string email) : base(userName, email) { }
[JsonPropertyName("refresh_tokens")]
public List<RefreshToken>? RefreshTokens { get; set; }
}
}
[BsonIgnoreExtraElements]
public class InsightUserLogEntity
{
[BsonIgnoreExtraElements]
public class InsightUserLogEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
@ -34,11 +34,11 @@ namespace Insight.Infrastructure.Entities
[BsonElement("message")]
public string? Message { get; set; }
}
}
[CollectionName("user_pref"), BsonIgnoreExtraElements]
public class InsightUserPreferences
{
[CollectionName("user_pref"), BsonIgnoreExtraElements]
public class InsightUserPreferences
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
@ -50,22 +50,19 @@ namespace Insight.Infrastructure.Entities
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("darkmode")]
public bool DarkMode { get; set; }
}
}
[CollectionName("role")]
public class InsightRole : MongoIdentityRole<ObjectId>
{
public InsightRole() : base() { }
[CollectionName("role")]
public class InsightRole : MongoIdentityRole<ObjectId>
{
public InsightRole(string roleName) : base(roleName) { }
}
}
[BsonIgnoreExtraElements]
public class RefreshToken
{
[BsonIgnoreExtraElements]
public class RefreshToken
{
[BsonElement("token")]
public string? Token { get; set; }
@ -95,5 +92,4 @@ namespace Insight.Infrastructure.Entities
[BsonIgnore, JsonIgnore]
public bool IsActive => !IsRevoked && !IsExpired;
}
}

View file

@ -2,10 +2,10 @@
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)
{
var builder = new QueryBuilder();
@ -43,5 +43,4 @@ namespace Insight.Infrastructure
pagelist.Meta.Next = $"{request.Scheme}://{request.Host}{request.PathBase}{request.Path}{qb}";
}
}
}
}

View file

@ -2,10 +2,10 @@
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)
{
response.Headers.Add("X-Pagination", JsonSerializer.Serialize(pagelist.Meta as PagedHeaderData, new JsonSerializerOptions
@ -13,5 +13,4 @@ namespace Insight.Infrastructure
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
}));
}
}
}

View file

@ -4,10 +4,10 @@ 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>(
@ -79,5 +79,4 @@ namespace Insight.Infrastructure
return result;
}
}
}

View file

@ -1,10 +1,10 @@
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");
@ -53,5 +53,4 @@ namespace Insight.Infrastructure
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,10 +16,10 @@ 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)
{
var connectionString = configuration.GetValue<string?>(Appsettings.Database) ?? throw new Exception($"{Appsettings.Database} value not set (appsettings)");
@ -259,5 +259,4 @@ namespace Insight.Infrastructure
return services;
}
}
}

View file

@ -1,9 +1,9 @@
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; }
@ -18,32 +18,31 @@ namespace Insight.Infrastructure.Models
Total = total,
};
}
}
}
public class PagedDataRequest
{
public class PagedDataRequest
{
[JsonPropertyName("offset")]
public int Offset { get; set; } = 0;
[JsonPropertyName("limit")]
public int Limit { get; set; } = 10;
}
}
public class PagedHeaderData : PagedDataRequest
{
public class PagedHeaderData : PagedDataRequest
{
[JsonPropertyName("count")]
public int Count { get; set; } = 0;
[JsonPropertyName("total")]
public long Total { get; set; } = 0;
}
}
public class PagedMetaData : PagedHeaderData
{
public class PagedMetaData : PagedHeaderData
{
[JsonPropertyName("next")]
public string? Next { get; set; }
[JsonPropertyName("previous")]
public string? Previous { get; set; }
}
}

View file

@ -1,7 +1,7 @@
namespace Insight.Infrastructure.Models
namespace Insight.Infrastructure.Models;
public class TokenOptions
{
public class TokenOptions
{
public string Key { get; set; }
public int Expires { get; set; }
public Uri? Audience { get; set; }
@ -14,5 +14,4 @@
Audience = audience;
Issuer = issuer;
}
}
}

View file

@ -4,10 +4,10 @@ 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;
@ -32,5 +32,4 @@ namespace Insight.Infrastructure.Services
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.User().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
}
}

View file

@ -4,10 +4,10 @@ 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;
@ -32,5 +32,4 @@ namespace Insight.Infrastructure.Services
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Agent().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
}
}

View file

@ -5,10 +5,10 @@ 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;
@ -108,5 +108,4 @@ namespace Insight.Infrastructure.Services
return result.ToString().ToLowerInvariant();
}
}
}

View file

@ -4,10 +4,10 @@ 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;
@ -32,5 +32,4 @@ namespace Insight.Infrastructure.Services
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Customer().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
}
}

View file

@ -4,10 +4,10 @@ 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;
@ -32,5 +32,4 @@ namespace Insight.Infrastructure.Services
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.Host().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
}
}

View file

@ -3,10 +3,10 @@ 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;
@ -134,5 +134,4 @@ namespace Insight.Infrastructure.Services
return claims;
}
}
}

View file

@ -4,10 +4,10 @@ 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;
@ -32,5 +32,4 @@ namespace Insight.Infrastructure.Services
int offset = 0,
int limit = 10,
CancellationToken cancellationToken = default) => _database.HostApplication().GetPagedAsync(request, response, filter, sort, offset, limit, cancellationToken);
}
}

View file

@ -8,10 +8,10 @@ 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;
@ -145,5 +145,4 @@ namespace Insight.Infrastructure.Services
return (refreshToken, (int)TimeSpan.FromMinutes(30).TotalSeconds);
}
}
}

View file

@ -1,7 +1,7 @@
namespace Insight.Server
namespace Insight.Server;
internal static class Appsettings
{
internal static class Appsettings
{
internal const string AgentServerPort = "agent.server.port";
internal const string AgentServerCertificate = "agent.server.certificate";
internal const string AgentServerCertificatePassword = "agent.server.certificate.password";
@ -10,5 +10,4 @@
internal const string WebServerPort = "web.server.port";
internal const string WebServerCertificate = "web.server.certificate";
internal const string WebServerCertificatePassword = "web.server.certificate.password";
}
}

View file

@ -1,9 +1,9 @@
using System.Threading.Tasks.Dataflow;
namespace Insight.Server.Extensions
namespace Insight.Server.Extensions;
public static class Async
{
public static class Async
{
public static async Task ParallelForEach<T>(
this IAsyncEnumerable<T> source,
Func<T, Task> body,
@ -49,5 +49,4 @@ namespace Insight.Server.Extensions
block.Complete();
await block.Completion;
}
}
}

View file

@ -1,14 +1,13 @@
using Microsoft.Extensions.Configuration;
namespace Insight.Server.Extensions
namespace Insight.Server.Extensions;
public static class ConfigurationExtensions
{
public static class ConfigurationExtensions
{
public static IConfigurationBuilder Defaults(this IConfigurationBuilder configuration)
{
configuration.Sources.Clear();
configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
return configuration.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: true, reloadOnChange: true);
}
}
}

View file

@ -1,7 +1,7 @@
namespace Insight.Setup.Constants
namespace Insight.Setup.Constants;
public static class Deploy
{
public static class Deploy
{
public static class Runtime
{
public static class Core
@ -45,5 +45,4 @@
public static Uri GetUpdateHref(Uri api, string appName)
=> new($"{api.AbsoluteUri}/update/{appName.ToLower()}/windows");
}
}

View file

@ -5,11 +5,11 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Runtime.Versioning;
namespace Insight.Setup.Windows
namespace Insight.Setup.Windows;
[SupportedOSPlatform("windows")]
internal class Program
{
[SupportedOSPlatform("windows")]
public class Program
{
public static async Task Main(string[] args)
{
await Host.CreateDefaultBuilder(args)
@ -54,5 +54,4 @@ namespace Insight.Setup.Windows
.Build()
.RunAsync();
}
}
}

View file

@ -6,10 +6,10 @@ using System.Runtime.Versioning;
using System.ServiceProcess;
using System.Text.Json;
namespace Insight.Setup.Services
namespace Insight.Setup.Services;
public static class Deployment
{
public static class Deployment
{
[SupportedOSPlatform("windows")]
public static class Windows
{
@ -473,5 +473,4 @@ namespace Insight.Setup.Services
public bool Success { get; set; } = false;
public List<string> Errors { get; } = new();
}
}
}

View file

@ -5,11 +5,11 @@ using Microsoft.Extensions.Logging;
using System.Diagnostics;
using System.Runtime.Versioning;
namespace Insight.Setup.Services
namespace Insight.Setup.Services;
[SupportedOSPlatform("windows")]
internal class SetupService : BackgroundService
{
[SupportedOSPlatform("windows")]
internal class SetupService : BackgroundService
{
private readonly Uri _uri;
private readonly HttpClient _httpClient;
@ -243,5 +243,4 @@ namespace Insight.Setup.Services
if (runtimeFile.Exists) runtimeFile.Delete();
}
}
}

View file

@ -1,7 +1,7 @@
namespace Insight.Updater.Constants
namespace Insight.Updater.Constants;
public static class Deploy
{
public static class Deploy
{
public static class Agent
{
public const string Name = "Agent";
@ -17,5 +17,4 @@
public static Uri GetUpdateHref(Uri api, string appName)
=> new($"{api.AbsoluteUri}/update/{appName.ToLower()}/windows");
}
}

View file

@ -5,10 +5,10 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Insight.Updater.Windows
namespace Insight.Updater.Windows;
internal class Program
{
internal class Program
{
public static async Task Main(string[] args)
{
var builder = Host.CreateDefaultBuilder(args);
@ -53,5 +53,4 @@ namespace Insight.Updater.Windows
var host = builder.Build();
await host.RunAsync().ConfigureAwait(false);
}
}
}

View file

@ -10,10 +10,10 @@ using System.Runtime.Versioning;
using System.ServiceProcess;
using System.Text.Json;
namespace Insight.Updater.Services
namespace Insight.Updater.Services;
public class UpdateService : BackgroundService
{
public class UpdateService : BackgroundService
{
private readonly Uri _uri;
private readonly HttpClient _httpClient;
@ -356,5 +356,4 @@ namespace Insight.Updater.Services
public List<string> ApiErrors { get; } = new();
public List<string> UpdateErrors { get; } = new();
}
}
}

View file

@ -12,7 +12,7 @@ using Vaitr.Network.Hosting;
namespace Insight.Web;
public class Program
internal class Program
{
public static async Task Main(string[] args)
{