Recreated project with project template

This commit is contained in:
2024-12-05 15:35:23 +01:00
parent 7659403dc8
commit 3392407890
76 changed files with 2020 additions and 2922 deletions

View File

@@ -1,12 +0,0 @@
namespace MoonlightServers.ApiServer.Database.Entities;
public class Allocation
{
public int Id { get; set; }
public string IpAddress { get; set; } = "0.0.0.0";
public int Port { get; set; }
public Server? Server { get; set; }
public Node Node { get; set; }
}

View File

@@ -1,18 +0,0 @@
using MoonlightServers.Shared.Enums;
namespace MoonlightServers.ApiServer.Database.Entities;
public class Backup
{
public int Id { get; set; }
public string Name { get; set; }
public BackupState State { get; set; }
public long Size { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime FinishedAt { get; set; } = DateTime.UtcNow;
public Server Server { get; set; }
}

View File

@@ -1,11 +0,0 @@
namespace MoonlightServers.ApiServer.Database.Entities;
public class Network
{
public int Id { get; set; }
public string Name { get; set; }
public Node Node { get; set; }
public List<Server> Servers { get; set; } = new();
}

View File

@@ -1,16 +0,0 @@
namespace MoonlightServers.ApiServer.Database.Entities;
public class Node
{
public int Id { get; set; }
public string Name { get; set; }
public string Fqdn { get; set; }
public int ApiPort { get; set; }
public string Token { get; set; }
public bool SslEnabled { get; set; }
public List<Allocation> Allocations { get; set; } = new();
public List<Server> Servers { get; set; } = new();
}

View File

@@ -1,26 +0,0 @@
namespace MoonlightServers.ApiServer.Database.Entities;
public class Server
{
public int Id { get; set; }
public string Name { get; set; }
public int Cpu { get; set; }
public int Memory { get; set; }
public int Disk { get; set; }
public string? OverrideStartupCommand { get; set; } = null;
public string? OverrideDockerImage { get; set; } = null;
public bool VirtualDiskEnabled { get; set; } = false;
public Star Star { get; set; }
public int DockerImageIndex { get; set; } = 0;
public Node Node { get; set; }
public Network? Network { get; set; }
public List<Allocation> Allocations { get; set; } = new();
public List<ServerVariable> Variables { get; set; } = new();
public List<Backup> Backups { get; set; } = new();
}

View File

@@ -1,11 +0,0 @@
namespace MoonlightServers.ApiServer.Database.Entities;
public class ServerVariable
{
public int Id { get; set; }
public string Key { get; set; }
public string Value { get; set; }
public Server Server { get; set; }
}

View File

@@ -1,31 +0,0 @@
namespace MoonlightServers.ApiServer.Database.Entities;
public class Star
{
public int Id { get; set; }
public string Name { get; set; }
public string Author { get; set; }
public string? DonationUrl { get; set; }
public string? UpdateUrl { get; set; }
public string StartupCommand { get; set; }
public string StopCommand { get; set; }
public string OnlineDetection { get; set; }
public string InstallShell { get; set; }
public string InstallDockerImage { get; set; }
public string InstallScript { get; set; }
public int RequiredAllocations { get; set; }
public string ParseConfiguration { get; set; }
public int DefaultDockerImageIndex { get; set; }
public bool AllowDockerImageChanging { get; set; }
public List<StarVariable> Variables { get; set; } = new();
public List<StarDockerImage> DockerImages { get; set; } = new();
public StarFolder? Folder { get; set; }
}

View File

@@ -1,11 +0,0 @@
namespace MoonlightServers.ApiServer.Database.Entities;
public class StarDockerImage
{
public int Id { get; set; }
public string Identifier { get; set; }
public string DisplayName { get; set; }
public bool AutoPulling { get; set; } = true;
}

View File

@@ -1,10 +0,0 @@
namespace MoonlightServers.ApiServer.Database.Entities;
public class StarFolder
{
public int Id { get; set; }
public string Name { get; set; }
public List<Star> Stars { get; set; } = new();
}

View File

@@ -1,20 +0,0 @@
using MoonlightServers.Shared.Enums;
namespace MoonlightServers.ApiServer.Database.Entities;
public class StarVariable
{
public int Id { get; set; }
public string Key { get; set; }
public string DefaultValue { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
public bool AllowViewing { get; set; } = false;
public bool AllowEditing { get; set; } = false;
public string? Filter { get; set; }
public StarVariableType Type { get; set; } = StarVariableType.Text;
}

View File

@@ -1,519 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using MoonlightServers.ApiServer.Database;
#nullable disable
namespace MoonlightServers.ApiServer.Database.Migrations
{
[DbContext(typeof(ServersContext))]
[Migration("20240830074359_AddedServerEntities")]
partial class AddedServerEntities
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("Servers")
.HasAnnotation("ProductVersion", "8.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("NodeId")
.HasColumnType("int");
b.Property<int>("Port")
.HasColumnType("int");
b.Property<int?>("ServerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("NodeId");
b.HasIndex("ServerId");
b.ToTable("Allocations", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Backup", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<DateTime>("FinishedAt")
.HasColumnType("datetime(6)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("ServerId")
.HasColumnType("int");
b.Property<long>("Size")
.HasColumnType("bigint");
b.Property<int>("State")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ServerId");
b.ToTable("Backups", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Network", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("NodeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("NodeId");
b.ToTable("Networks", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ApiPort")
.HasColumnType("int");
b.Property<string>("Fqdn")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.Property<bool>("SslEnabled")
.HasColumnType("tinyint(1)");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("Nodes", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Cpu")
.HasColumnType("int");
b.Property<int>("Disk")
.HasColumnType("int");
b.Property<int>("DockerImageIndex")
.HasColumnType("int");
b.Property<int>("Memory")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.Property<int?>("NetworkId")
.HasColumnType("int");
b.Property<int>("NodeId")
.HasColumnType("int");
b.Property<string>("OverrideDockerImage")
.HasColumnType("longtext");
b.Property<string>("OverrideStartupCommand")
.HasColumnType("longtext");
b.Property<int>("StarId")
.HasColumnType("int");
b.Property<bool>("VirtualDiskEnabled")
.HasColumnType("tinyint(1)");
b.HasKey("Id");
b.HasIndex("NetworkId");
b.HasIndex("NodeId");
b.HasIndex("StarId");
b.ToTable("Servers", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Key")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("ServerId")
.HasColumnType("int");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("longtext");
b.HasKey("Id");
b.HasIndex("ServerId");
b.ToTable("ServerVariables", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("AllowDockerImageChanging")
.HasColumnType("tinyint(1)");
b.Property<string>("Author")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("DefaultDockerImageIndex")
.HasColumnType("int");
b.Property<string>("DonationUrl")
.HasColumnType("longtext");
b.Property<int?>("FolderId")
.HasColumnType("int");
b.Property<string>("InstallDockerImage")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("InstallScript")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("InstallShell")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("OnlineDetection")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("ParseConfiguration")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("RequiredAllocations")
.HasColumnType("int");
b.Property<string>("StartupCommand")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("StopCommand")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("UpdateUrl")
.HasColumnType("longtext");
b.HasKey("Id");
b.HasIndex("FolderId");
b.ToTable("Stars", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("AutoPulling")
.HasColumnType("tinyint(1)");
b.Property<string>("DisplayName")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Identifier")
.IsRequired()
.HasColumnType("longtext");
b.Property<int?>("StarId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("StarId");
b.ToTable("StarDockerImages", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarFolder", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("StarFolders", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("AllowEditing")
.HasColumnType("tinyint(1)");
b.Property<bool>("AllowViewing")
.HasColumnType("tinyint(1)");
b.Property<string>("DefaultValue")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("DisplayName")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Filter")
.HasColumnType("longtext");
b.Property<string>("Key")
.IsRequired()
.HasColumnType("longtext");
b.Property<int?>("StarId")
.HasColumnType("int");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("StarId");
b.ToTable("StarVariables", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node")
.WithMany("Allocations")
.HasForeignKey("NodeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server")
.WithMany("Allocations")
.HasForeignKey("ServerId");
b.Navigation("Node");
b.Navigation("Server");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Backup", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server")
.WithMany("Backups")
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Server");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Network", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node")
.WithMany()
.HasForeignKey("NodeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Node");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Network", "Network")
.WithMany("Servers")
.HasForeignKey("NetworkId");
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node")
.WithMany("Servers")
.HasForeignKey("NodeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star")
.WithMany()
.HasForeignKey("StarId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Network");
b.Navigation("Node");
b.Navigation("Star");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server")
.WithMany("Variables")
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Server");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.StarFolder", "Folder")
.WithMany("Stars")
.HasForeignKey("FolderId");
b.Navigation("Folder");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", null)
.WithMany("DockerImages")
.HasForeignKey("StarId");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", null)
.WithMany("Variables")
.HasForeignKey("StarId");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Network", b =>
{
b.Navigation("Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b =>
{
b.Navigation("Allocations");
b.Navigation("Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
{
b.Navigation("Allocations");
b.Navigation("Backups");
b.Navigation("Variables");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b =>
{
b.Navigation("DockerImages");
b.Navigation("Variables");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarFolder", b =>
{
b.Navigation("Stars");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,434 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace MoonlightServers.ApiServer.Database.Migrations
{
/// <inheritdoc />
public partial class AddedServerEntities : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "Servers");
migrationBuilder.AlterDatabase()
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Nodes",
schema: "Servers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Fqdn = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
ApiPort = table.Column<int>(type: "int", nullable: false),
Token = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
SslEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Nodes", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "StarFolders",
schema: "Servers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_StarFolders", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Networks",
schema: "Servers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
NodeId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Networks", x => x.Id);
table.ForeignKey(
name: "FK_Networks_Nodes_NodeId",
column: x => x.NodeId,
principalSchema: "Servers",
principalTable: "Nodes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Stars",
schema: "Servers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Author = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
DonationUrl = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
UpdateUrl = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
StartupCommand = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
StopCommand = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
OnlineDetection = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
InstallShell = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
InstallDockerImage = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
InstallScript = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
RequiredAllocations = table.Column<int>(type: "int", nullable: false),
ParseConfiguration = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
DefaultDockerImageIndex = table.Column<int>(type: "int", nullable: false),
AllowDockerImageChanging = table.Column<bool>(type: "tinyint(1)", nullable: false),
FolderId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Stars", x => x.Id);
table.ForeignKey(
name: "FK_Stars_StarFolders_FolderId",
column: x => x.FolderId,
principalSchema: "Servers",
principalTable: "StarFolders",
principalColumn: "Id");
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Servers",
schema: "Servers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Cpu = table.Column<int>(type: "int", nullable: false),
Memory = table.Column<int>(type: "int", nullable: false),
Disk = table.Column<int>(type: "int", nullable: false),
OverrideStartupCommand = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
OverrideDockerImage = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
VirtualDiskEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false),
StarId = table.Column<int>(type: "int", nullable: false),
DockerImageIndex = table.Column<int>(type: "int", nullable: false),
NodeId = table.Column<int>(type: "int", nullable: false),
NetworkId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Servers", x => x.Id);
table.ForeignKey(
name: "FK_Servers_Networks_NetworkId",
column: x => x.NetworkId,
principalSchema: "Servers",
principalTable: "Networks",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Servers_Nodes_NodeId",
column: x => x.NodeId,
principalSchema: "Servers",
principalTable: "Nodes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Servers_Stars_StarId",
column: x => x.StarId,
principalSchema: "Servers",
principalTable: "Stars",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "StarDockerImages",
schema: "Servers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Identifier = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
DisplayName = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
AutoPulling = table.Column<bool>(type: "tinyint(1)", nullable: false),
StarId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_StarDockerImages", x => x.Id);
table.ForeignKey(
name: "FK_StarDockerImages_Stars_StarId",
column: x => x.StarId,
principalSchema: "Servers",
principalTable: "Stars",
principalColumn: "Id");
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "StarVariables",
schema: "Servers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Key = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
DefaultValue = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
DisplayName = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Description = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
AllowViewing = table.Column<bool>(type: "tinyint(1)", nullable: false),
AllowEditing = table.Column<bool>(type: "tinyint(1)", nullable: false),
Filter = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Type = table.Column<int>(type: "int", nullable: false),
StarId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_StarVariables", x => x.Id);
table.ForeignKey(
name: "FK_StarVariables_Stars_StarId",
column: x => x.StarId,
principalSchema: "Servers",
principalTable: "Stars",
principalColumn: "Id");
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Allocations",
schema: "Servers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
IpAddress = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Port = table.Column<int>(type: "int", nullable: false),
ServerId = table.Column<int>(type: "int", nullable: true),
NodeId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Allocations", x => x.Id);
table.ForeignKey(
name: "FK_Allocations_Nodes_NodeId",
column: x => x.NodeId,
principalSchema: "Servers",
principalTable: "Nodes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Allocations_Servers_ServerId",
column: x => x.ServerId,
principalSchema: "Servers",
principalTable: "Servers",
principalColumn: "Id");
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "Backups",
schema: "Servers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
State = table.Column<int>(type: "int", nullable: false),
Size = table.Column<long>(type: "bigint", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
FinishedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
ServerId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Backups", x => x.Id);
table.ForeignKey(
name: "FK_Backups_Servers_ServerId",
column: x => x.ServerId,
principalSchema: "Servers",
principalTable: "Servers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "ServerVariables",
schema: "Servers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Key = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Value = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
ServerId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ServerVariables", x => x.Id);
table.ForeignKey(
name: "FK_ServerVariables_Servers_ServerId",
column: x => x.ServerId,
principalSchema: "Servers",
principalTable: "Servers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_Allocations_NodeId",
schema: "Servers",
table: "Allocations",
column: "NodeId");
migrationBuilder.CreateIndex(
name: "IX_Allocations_ServerId",
schema: "Servers",
table: "Allocations",
column: "ServerId");
migrationBuilder.CreateIndex(
name: "IX_Backups_ServerId",
schema: "Servers",
table: "Backups",
column: "ServerId");
migrationBuilder.CreateIndex(
name: "IX_Networks_NodeId",
schema: "Servers",
table: "Networks",
column: "NodeId");
migrationBuilder.CreateIndex(
name: "IX_Servers_NetworkId",
schema: "Servers",
table: "Servers",
column: "NetworkId");
migrationBuilder.CreateIndex(
name: "IX_Servers_NodeId",
schema: "Servers",
table: "Servers",
column: "NodeId");
migrationBuilder.CreateIndex(
name: "IX_Servers_StarId",
schema: "Servers",
table: "Servers",
column: "StarId");
migrationBuilder.CreateIndex(
name: "IX_ServerVariables_ServerId",
schema: "Servers",
table: "ServerVariables",
column: "ServerId");
migrationBuilder.CreateIndex(
name: "IX_StarDockerImages_StarId",
schema: "Servers",
table: "StarDockerImages",
column: "StarId");
migrationBuilder.CreateIndex(
name: "IX_Stars_FolderId",
schema: "Servers",
table: "Stars",
column: "FolderId");
migrationBuilder.CreateIndex(
name: "IX_StarVariables_StarId",
schema: "Servers",
table: "StarVariables",
column: "StarId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Allocations",
schema: "Servers");
migrationBuilder.DropTable(
name: "Backups",
schema: "Servers");
migrationBuilder.DropTable(
name: "ServerVariables",
schema: "Servers");
migrationBuilder.DropTable(
name: "StarDockerImages",
schema: "Servers");
migrationBuilder.DropTable(
name: "StarVariables",
schema: "Servers");
migrationBuilder.DropTable(
name: "Servers",
schema: "Servers");
migrationBuilder.DropTable(
name: "Networks",
schema: "Servers");
migrationBuilder.DropTable(
name: "Stars",
schema: "Servers");
migrationBuilder.DropTable(
name: "Nodes",
schema: "Servers");
migrationBuilder.DropTable(
name: "StarFolders",
schema: "Servers");
}
}
}

View File

@@ -1,516 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using MoonlightServers.ApiServer.Database;
#nullable disable
namespace MoonlightServers.ApiServer.Database.Migrations
{
[DbContext(typeof(ServersContext))]
partial class ServersContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("Servers")
.HasAnnotation("ProductVersion", "8.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("NodeId")
.HasColumnType("int");
b.Property<int>("Port")
.HasColumnType("int");
b.Property<int?>("ServerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("NodeId");
b.HasIndex("ServerId");
b.ToTable("Allocations", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Backup", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<DateTime>("FinishedAt")
.HasColumnType("datetime(6)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("ServerId")
.HasColumnType("int");
b.Property<long>("Size")
.HasColumnType("bigint");
b.Property<int>("State")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ServerId");
b.ToTable("Backups", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Network", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("NodeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("NodeId");
b.ToTable("Networks", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ApiPort")
.HasColumnType("int");
b.Property<string>("Fqdn")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.Property<bool>("SslEnabled")
.HasColumnType("tinyint(1)");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("Nodes", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Cpu")
.HasColumnType("int");
b.Property<int>("Disk")
.HasColumnType("int");
b.Property<int>("DockerImageIndex")
.HasColumnType("int");
b.Property<int>("Memory")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.Property<int?>("NetworkId")
.HasColumnType("int");
b.Property<int>("NodeId")
.HasColumnType("int");
b.Property<string>("OverrideDockerImage")
.HasColumnType("longtext");
b.Property<string>("OverrideStartupCommand")
.HasColumnType("longtext");
b.Property<int>("StarId")
.HasColumnType("int");
b.Property<bool>("VirtualDiskEnabled")
.HasColumnType("tinyint(1)");
b.HasKey("Id");
b.HasIndex("NetworkId");
b.HasIndex("NodeId");
b.HasIndex("StarId");
b.ToTable("Servers", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Key")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("ServerId")
.HasColumnType("int");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("longtext");
b.HasKey("Id");
b.HasIndex("ServerId");
b.ToTable("ServerVariables", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("AllowDockerImageChanging")
.HasColumnType("tinyint(1)");
b.Property<string>("Author")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("DefaultDockerImageIndex")
.HasColumnType("int");
b.Property<string>("DonationUrl")
.HasColumnType("longtext");
b.Property<int?>("FolderId")
.HasColumnType("int");
b.Property<string>("InstallDockerImage")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("InstallScript")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("InstallShell")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("OnlineDetection")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("ParseConfiguration")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("RequiredAllocations")
.HasColumnType("int");
b.Property<string>("StartupCommand")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("StopCommand")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("UpdateUrl")
.HasColumnType("longtext");
b.HasKey("Id");
b.HasIndex("FolderId");
b.ToTable("Stars", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("AutoPulling")
.HasColumnType("tinyint(1)");
b.Property<string>("DisplayName")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Identifier")
.IsRequired()
.HasColumnType("longtext");
b.Property<int?>("StarId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("StarId");
b.ToTable("StarDockerImages", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarFolder", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("StarFolders", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("AllowEditing")
.HasColumnType("tinyint(1)");
b.Property<bool>("AllowViewing")
.HasColumnType("tinyint(1)");
b.Property<string>("DefaultValue")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("DisplayName")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Filter")
.HasColumnType("longtext");
b.Property<string>("Key")
.IsRequired()
.HasColumnType("longtext");
b.Property<int?>("StarId")
.HasColumnType("int");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("StarId");
b.ToTable("StarVariables", "Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Allocation", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node")
.WithMany("Allocations")
.HasForeignKey("NodeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server")
.WithMany("Allocations")
.HasForeignKey("ServerId");
b.Navigation("Node");
b.Navigation("Server");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Backup", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server")
.WithMany("Backups")
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Server");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Network", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node")
.WithMany()
.HasForeignKey("NodeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Node");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Network", "Network")
.WithMany("Servers")
.HasForeignKey("NetworkId");
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Node", "Node")
.WithMany("Servers")
.HasForeignKey("NodeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", "Star")
.WithMany()
.HasForeignKey("StarId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Network");
b.Navigation("Node");
b.Navigation("Star");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.ServerVariable", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Server", "Server")
.WithMany("Variables")
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Server");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.StarFolder", "Folder")
.WithMany("Stars")
.HasForeignKey("FolderId");
b.Navigation("Folder");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarDockerImage", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", null)
.WithMany("DockerImages")
.HasForeignKey("StarId");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarVariable", b =>
{
b.HasOne("MoonlightServers.ApiServer.Database.Entities.Star", null)
.WithMany("Variables")
.HasForeignKey("StarId");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Network", b =>
{
b.Navigation("Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Node", b =>
{
b.Navigation("Allocations");
b.Navigation("Servers");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Server", b =>
{
b.Navigation("Allocations");
b.Navigation("Backups");
b.Navigation("Variables");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.Star", b =>
{
b.Navigation("DockerImages");
b.Navigation("Variables");
});
modelBuilder.Entity("MoonlightServers.ApiServer.Database.Entities.StarFolder", b =>
{
b.Navigation("Stars");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,13 @@
using Moonlight.ApiServer.Configuration;
using Moonlight.ApiServer.Helpers;
namespace MoonlightServers.ApiServer.Database;
public class MoonlightServersDataContext : DatabaseContext
{
public override string Prefix { get; } = "MoonlightServers";
public MoonlightServersDataContext(AppConfiguration configuration) : base(configuration)
{
}
}

View File

@@ -1,21 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Moonlight.ApiServer.App.Helpers.Database;
using MoonlightServers.ApiServer.Database.Entities;
namespace MoonlightServers.ApiServer.Database;
public class ServersContext : DatabaseContext
{
public override string Prefix => "Servers";
public DbSet<Allocation> Allocations { get; set; }
public DbSet<Backup> Backups { get; set; }
public DbSet<Network> Networks { get; set; }
public DbSet<Node> Nodes { get; set; }
public DbSet<Server> Servers { get; set; }
public DbSet<ServerVariable> ServerVariables { get; set; }
public DbSet<Star> Stars { get; set; }
public DbSet<StarDockerImage> StarDockerImages { get; set; }
public DbSet<StarFolder> StarFolders { get; set; }
public DbSet<StarVariable> StarVariables { get; set; }
}

View File

@@ -1,22 +0,0 @@
using MoonCore.Helpers;
using MoonlightServers.ApiServer.Database.Entities;
namespace MoonlightServers.ApiServer.Extensions;
public static class NodeExtensions
{
public static HttpApiClient CreateClient(this Node node)
{
var httpClient = new HttpClient(new HttpClientHandler() // TODO: Make global http config for proxy etc
{
UseProxy = false
});
var url = $"{(node.SslEnabled ? "https" : "http")}://{node.Fqdn}:{node.ApiPort}/";
httpClient.BaseAddress = new Uri(url);
httpClient.DefaultRequestHeaders.Add("Authorization", node.Token);
return new HttpApiClient(httpClient);
}
}

View File

@@ -1,63 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MoonCore.Extended.Abstractions;
using MoonCore.Helpers;
using Moonlight.ApiServer.App.Attributes;
using Moonlight.ApiServer.App.Exceptions;
using Moonlight.ApiServer.App.Helpers;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.Shared.Http.Requests.Admin.Allocations;
using MoonlightServers.Shared.Http.Responses.Admin.Allocations;
namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Nodes;
[ApiController]
[Route("admin/servers/nodes/{rootItem:int}/allocations")]
public class NodeAllocationsController : BaseSubCrudController<Node, Allocation, DetailAllocationResponse, CreateAllocationRequest, DetailAllocationResponse, UpdateAllocationRequest, DetailAllocationResponse>
{
public override Func<Node, List<Allocation>> Property => node => node.Allocations;
public NodeAllocationsController(DatabaseRepository<Allocation> itemRepository, DatabaseRepository<Node> rootItemRepository, IHttpContextAccessor contextAccessor) : base(itemRepository, rootItemRepository, contextAccessor)
{
PermissionPrefix = "admin.servers.nodes.allocations";
}
[HttpPost]
[RequirePermission("admin.servers.nodes.allocations.create")]
public override async Task<ActionResult<DetailAllocationResponse>> Create(CreateAllocationRequest request)
{
if (ItemRepository.Get().Any(x => x.IpAddress == request.IpAddress && x.Port == request.Port))
throw new ApiException("An allocation with this ip and port already exists", statusCode: 400);
var item = Mapper.Map<Allocation>(request!);
Property.Invoke(RootItem).Add(item);
RootItemRepository.Update(RootItem);
var response = Mapper.Map<DetailAllocationResponse>(item);
return Ok(response);
}
[HttpPatch("{id}")]
[RequirePermission("admin.servers.nodes.allocations.create")]
public override async Task<ActionResult<DetailAllocationResponse>> Update(int id, UpdateAllocationRequest request)
{
var item = LoadItemById(id);
if (ItemRepository.Get().Any(x => x.IpAddress == request.IpAddress && x.Port == request.Port && x.Id != item.Id))
throw new ApiException("An allocation with this ip and port already exists", statusCode: 400);
var mappedItem = Mapper.Map(item, request!, ignoreNullValues: true);
ItemRepository.Update(mappedItem);
var response = Mapper.Map<DetailAllocationResponse>(mappedItem);
return Ok(response);
}
protected override IEnumerable<Node> IncludeRelations(IQueryable<Node> items)
=> items.Include(x => x.Allocations);
}

View File

@@ -1,105 +0,0 @@
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Mvc;
using MoonCore.Extended.Abstractions;
using MoonCore.Helpers;
using Moonlight.ApiServer.App.Attributes;
using Moonlight.ApiServer.App.Exceptions;
using Moonlight.ApiServer.App.Helpers;
using MoonlightServers.DaemonShared.Http.Resources.Sys;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.ApiServer.Extensions;
using MoonlightServers.Shared.Http.Requests.Admin.Nodes;
using MoonlightServers.Shared.Http.Responses.Admin.Nodes;
namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Nodes;
[ApiController]
[Route("admin/servers/nodes")]
public class NodesController : BaseCrudController<Node, DetailNodeResponse, CreateNodeRequest, DetailNodeResponse, UpdateNodeRequest, DetailNodeResponse>
{
public NodesController(DatabaseRepository<Node> itemRepository) : base(itemRepository)
{
PermissionPrefix = "admin.servers.nodes";
}
[HttpPost]
[RequirePermission("admin.servers.nodes.create")]
public override async Task<ActionResult<DetailNodeResponse>> Create(CreateNodeRequest request)
{
ValidateFqdn(request.Fqdn, request.SslEnabled);
var node = Mapper.Map<Node>(request);
node.Token = Formatter.GenerateString(32);
var finalNode = ItemRepository.Add(node);
return Ok(Mapper.Map<DetailNodeResponse>(finalNode));
}
[HttpPatch("{id}")]
[RequirePermission("admin.servers.nodes.update")]
public override async Task<ActionResult<DetailNodeResponse>> Update(int id, UpdateNodeRequest request)
{
ValidateFqdn(request.Fqdn, request.SslEnabled);
var item = LoadItemById(id);
item = Mapper.Map(item, request);
ItemRepository.Update(item);
return Ok(Mapper.Map<DetailNodeResponse>(item));
}
[HttpGet("{id}/status")]
[RequirePermission("admin.servers.nodes.status")]
public async Task<ActionResult<StatusNodeResponse>> Status(int id)
{
var node = LoadItemById(id);
using var httpClient = node.CreateClient();
SystemInfoResponse response;
try
{
response = await httpClient.GetJson<SystemInfoResponse>("system/info");
}
catch (HttpRequestException e)
{
throw new ApiException(
"The requested node's api server was not reachable",
e.Message,
statusCode: 502
);
}
var result = Mapper.Map<StatusNodeResponse>(response);
return Ok(result);
}
private void ValidateFqdn(string fqdn, bool ssl)
{
if (ssl)
{
// Is it a valid domain?
if (Regex.IsMatch(fqdn, "^(?!-)(?:[a-zA-Z\\d-]{0,62}[a-zA-Z\\d]\\.)+(?:[a-zA-Z]{2,})$"))
return;
throw new ApiException("The fqdn needs to be a valid domain. If you want to use an ip address as the fqdn, disable ssl for this node", statusCode: 400);
}
else
{
// Is it a valid domain?
if (Regex.IsMatch(fqdn, "^(?!-)(?:[a-zA-Z\\d-]{0,62}[a-zA-Z\\d]\\.)+(?:[a-zA-Z]{2,})$"))
return;
// Is it a valid ip?
if (Regex.IsMatch(fqdn, "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"))
return;
throw new ApiException("The fqdn needs to be either a domain or an ip", statusCode: 400);
}
}
}

View File

@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Mvc;
using MoonlightServers.ApiServer.Services;
using MoonlightServers.Shared.Http.Responses;
namespace MoonlightServers.ApiServer.Http.Controllers;
[ApiController]
[Route("api/example")]
public class ExampleController : Controller
{
private readonly ExampleService ExampleService;
public ExampleController(ExampleService exampleService)
{
ExampleService = exampleService;
}
[HttpGet]
public async Task<ExampleResponse> Get()
{
var val = await ExampleService.GetValue();
return new ExampleResponse()
{
Number = val
};
}
}

View File

@@ -1,50 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup Label="Moonlight Dependencies">
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MoonCore" Version="1.5.4" />
<PackageReference Include="MoonCore.Extended" Version="1.0.2" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.6.2" />
</ItemGroup>
<ItemGroup Label="Shared references">
<ProjectReference Include="..\MoonlightServers.DaemonShared\MoonlightServers.DaemonShared.csproj" />
<ProjectReference Include="..\MoonlightServers.Shared\MoonlightServers.Shared.csproj" />
</ItemGroup>
<ItemGroup Label="Reference moonlight builds">
<Reference Include="Moonlight.ApiServer">
<HintPath>..\..\Moonlight\Moonlight\ApiServer\bin\Debug\net8.0\Moonlight.ApiServer.dll</HintPath>
</Reference>
<Reference Include="Moonlight.Shared">
<HintPath>..\..\Moonlight\Moonlight\Shared\bin\Debug\net8.0\Moonlight.Shared.dll</HintPath>
</Reference>
<PackageReference Include="Moonlight.ApiServer" Version="2.1.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.11"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Database\Enums\" />
<Folder Include="Database\Migrations\" />
<Folder Include="Helpers\" />
<Folder Include="Http\Hubs\" />
<Folder Include="Http\Middleware\" />
<Folder Include="Implementations\" />
<Folder Include="Models\" />
<Folder Include="Services\" />
<ProjectReference Include="..\MoonlightServers.Frontend\MoonlightServers.Frontend.csproj"/>
<ProjectReference Include="..\MoonlightServers.Shared\MoonlightServers.Shared.csproj"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Database\Entities\"/>
<Folder Include="Database\Migrations\"/>
<Folder Include="Helpers\"/>
<Folder Include="Http\Middleware\"/>
<Folder Include="Implementations\"/>
<Folder Include="Interfaces\"/>
<Folder Include="Models\"/>
</ItemGroup>
</Project>

View File

@@ -1,34 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MoonCore.Extended.Helpers;
using Moonlight.ApiServer.App.PluginApi;
using MoonlightServers.ApiServer.Database;
namespace MoonlightServers.ApiServer;
public class MoonlightServersPlugin : MoonlightPlugin
{
public MoonlightServersPlugin(ILogger logger, PluginService pluginService) : base(logger, pluginService)
{
}
public override Task OnLoaded()
{
return Task.CompletedTask;
}
public override Task OnAppBuilding(WebApplicationBuilder builder, DatabaseHelper databaseHelper)
{
// Register database
builder.Services.AddDbContext<ServersContext>();
databaseHelper.AddDbContext<ServersContext>();
return Task.CompletedTask;
}
public override Task OnAppConfiguring(WebApplication app)
{
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,7 @@
using Moonlight.ApiServer;
var startup = new Startup();
await startup.Run(args, [
typeof(Program).Assembly
]);

View File

@@ -0,0 +1,17 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Dev Server": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5269",
"commandLineArgs": "--frontend-asset /css/MoonlightServers.min.css",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"MOONLIGHT_APP_PUBLICURL": "http://localhost:5269"
}
}
}
}

View File

@@ -0,0 +1,22 @@
using MoonCore.Attributes;
namespace MoonlightServers.ApiServer.Services;
[Singleton]
public class ExampleService
{
private readonly Random Random;
private readonly ILogger<ExampleService> Logger;
public ExampleService(ILogger<ExampleService> logger)
{
Logger = logger;
Random = new();
}
public async Task<int> GetValue()
{
Logger.LogInformation("Generating value");
return Random.Next(0, 10324);
}
}

View File

@@ -0,0 +1,15 @@
using Moonlight.ApiServer.Helpers;
using Moonlight.ApiServer.Interfaces.Startup;
using MoonlightServers.ApiServer.Database;
namespace MoonlightServers.ApiServer.Startup;
public class DatabaseStartup : IDatabaseStartup
{
public Task ConfigureDatabase(DatabaseContextCollection collection)
{
collection.Add<MoonlightServersDataContext>();
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,29 @@
using MoonCore.Extensions;
using Moonlight.ApiServer.Interfaces.Startup;
namespace MoonlightServers.ApiServer.Startup;
public class PluginStartup : IAppStartup
{
private readonly ILogger<PluginStartup> Logger;
public PluginStartup(ILogger<PluginStartup> logger)
{
Logger = logger;
}
public Task BuildApp(IHostApplicationBuilder builder)
{
Logger.LogInformation("Elo World from MoonlightServers");
// Scan the current plugin assembly for di services
builder.Services.AutoAddServices<PluginStartup>();
return Task.CompletedTask;
}
public Task ConfigureApp(IApplicationBuilder app)
{
return Task.CompletedTask;
}
}