Implemented api key crud and started adding system page. Added 404 page
This commit is contained in:
@@ -1,11 +0,0 @@
|
|||||||
namespace Moonlight.ApiServer.Attributes;
|
|
||||||
|
|
||||||
public class RequirePermissionAttribute : Attribute
|
|
||||||
{
|
|
||||||
public string Permission { get; set; }
|
|
||||||
|
|
||||||
public RequirePermissionAttribute(string permission)
|
|
||||||
{
|
|
||||||
Permission = permission;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,4 +9,5 @@ public class CoreDataContext : DatabaseContext
|
|||||||
public override string Prefix { get; } = "Core";
|
public override string Prefix { get; } = "Core";
|
||||||
|
|
||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
|
public DbSet<ApiKey> ApiKeys { get; set; }
|
||||||
}
|
}
|
||||||
11
Moonlight.ApiServer/Database/Entities/ApiKey.cs
Normal file
11
Moonlight.ApiServer/Database/Entities/ApiKey.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace Moonlight.ApiServer.Database.Entities;
|
||||||
|
|
||||||
|
public class ApiKey
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Secret { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public string PermissionsJson { get; set; } = "[]";
|
||||||
|
public DateTime ExpiresAt { get; set; }
|
||||||
|
}
|
||||||
102
Moonlight.ApiServer/Database/Migrations/20241029134013_AddedApiKeys.Designer.cs
generated
Normal file
102
Moonlight.ApiServer/Database/Migrations/20241029134013_AddedApiKeys.Designer.cs
generated
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
// <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 Moonlight.ApiServer.Database;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Database.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(CoreDataContext))]
|
||||||
|
[Migration("20241029134013_AddedApiKeys")]
|
||||||
|
partial class AddedApiKeys
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasDefaultSchema("Core")
|
||||||
|
.HasAnnotation("ProductVersion", "8.0.8")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||||
|
|
||||||
|
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ExpiresAt")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<string>("PermissionsJson")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Secret")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys", "Core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("AccessToken")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("PermissionsJson")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<DateTime>("RefreshTimestamp")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<string>("RefreshToken")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<DateTime>("TokenValidTimestamp")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users", "Core");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddedApiKeys : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ApiKeys",
|
||||||
|
schema: "Core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||||
|
Secret = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
Description = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
PermissionsJson = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
ExpiresAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ApiKeys", x => x.Id);
|
||||||
|
})
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ApiKeys",
|
||||||
|
schema: "Core");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,34 @@ namespace Moonlight.ApiServer.Database.Migrations
|
|||||||
|
|
||||||
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
|
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ExpiresAt")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<string>("PermissionsJson")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Secret")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys", "Core");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.User", b =>
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MoonCore.Blazor.Tailwind.Attributes;
|
||||||
|
using MoonCore.Extended.Abstractions;
|
||||||
|
using MoonCore.Extended.Helpers;
|
||||||
|
using MoonCore.Helpers;
|
||||||
|
using MoonCore.Models;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.Shared.Http.Requests.Admin.ApiKeys;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin.ApiKeys;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.ApiKeys;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/apikeys")]
|
||||||
|
public class ApiKeysController : Controller
|
||||||
|
{
|
||||||
|
private readonly CrudHelper<ApiKey, ApiKeyDetailResponse> CrudHelper;
|
||||||
|
private readonly DatabaseRepository<ApiKey> ApiKeyRepository;
|
||||||
|
|
||||||
|
public ApiKeysController(CrudHelper<ApiKey, ApiKeyDetailResponse> crudHelper, DatabaseRepository<ApiKey> apiKeyRepository)
|
||||||
|
{
|
||||||
|
CrudHelper = crudHelper;
|
||||||
|
ApiKeyRepository = apiKeyRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[RequirePermission("admin.apikeys.read")]
|
||||||
|
public async Task<IPagedData<ApiKeyDetailResponse>> Get([FromQuery] int page, [FromQuery] int pageSize = 50)
|
||||||
|
=> await CrudHelper.Get(page, pageSize);
|
||||||
|
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[RequirePermission("admin.apikeys.read")]
|
||||||
|
public async Task<ApiKeyDetailResponse> GetSingle(int id)
|
||||||
|
=> await CrudHelper.GetSingle(id);
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[RequirePermission("admin.apikeys.create")]
|
||||||
|
public async Task<CreateApiKeyResponse> Create([FromBody] CreateApiKeyRequest request)
|
||||||
|
{
|
||||||
|
var secret = "api_" + Formatter.GenerateString(32);
|
||||||
|
|
||||||
|
var apiKey = new ApiKey()
|
||||||
|
{
|
||||||
|
Description = request.Description,
|
||||||
|
PermissionsJson = request.PermissionsJson,
|
||||||
|
ExpiresAt = request.ExpiresAt,
|
||||||
|
Secret = secret
|
||||||
|
};
|
||||||
|
|
||||||
|
var finalApiKey = ApiKeyRepository.Add(apiKey);
|
||||||
|
|
||||||
|
return Mapper.Map<CreateApiKeyResponse>(finalApiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch("{id}")]
|
||||||
|
[RequirePermission("admin.apikeys.update")]
|
||||||
|
public async Task<ApiKeyDetailResponse> Update([FromRoute] int id, [FromBody] UpdateApiKeyRequest request)
|
||||||
|
=> await CrudHelper.Update(id, request);
|
||||||
|
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[RequirePermission("admin.apikeys.delete")]
|
||||||
|
public async Task Delete([FromRoute] int id)
|
||||||
|
=> await CrudHelper.Delete(id);
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MoonCore.Blazor.Tailwind.Attributes;
|
||||||
using MoonCore.Exceptions;
|
using MoonCore.Exceptions;
|
||||||
using MoonCore.Extended.Abstractions;
|
using MoonCore.Extended.Abstractions;
|
||||||
using MoonCore.Extended.Helpers;
|
using MoonCore.Extended.Helpers;
|
||||||
using MoonCore.Models;
|
using MoonCore.Models;
|
||||||
using Moonlight.ApiServer.Attributes;
|
|
||||||
using Moonlight.ApiServer.Database.Entities;
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
using Moonlight.Shared.Http.Requests.Admin.Users;
|
using Moonlight.Shared.Http.Requests.Admin.Users;
|
||||||
using Moonlight.Shared.Http.Responses.Admin.Users;
|
using Moonlight.Shared.Http.Responses.Admin.Users;
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MoonCore.Blazor.Tailwind.Attributes;
|
||||||
using MoonCore.Exceptions;
|
using MoonCore.Exceptions;
|
||||||
using MoonCore.Extended.Abstractions;
|
using MoonCore.Extended.Abstractions;
|
||||||
using MoonCore.Extended.Helpers;
|
using MoonCore.Extended.Helpers;
|
||||||
using MoonCore.Extended.OAuth2.ApiServer;
|
using MoonCore.Extended.OAuth2.ApiServer;
|
||||||
using MoonCore.Helpers;
|
using MoonCore.Helpers;
|
||||||
using MoonCore.PluginFramework.Services;
|
|
||||||
using MoonCore.Services;
|
using MoonCore.Services;
|
||||||
using Moonlight.ApiServer.Attributes;
|
|
||||||
using Moonlight.ApiServer.Configuration;
|
using Moonlight.ApiServer.Configuration;
|
||||||
using Moonlight.ApiServer.Database.Entities;
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
using Moonlight.ApiServer.Helpers.Authentication;
|
using Moonlight.ApiServer.Helpers.Authentication;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
using Moonlight.ApiServer.Attributes;
|
using MoonCore.Blazor.Tailwind.Attributes;
|
||||||
using Moonlight.ApiServer.Exceptions;
|
using Moonlight.ApiServer.Exceptions;
|
||||||
using Moonlight.ApiServer.Helpers.Authentication;
|
using Moonlight.ApiServer.Helpers.Authentication;
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ public static class Startup
|
|||||||
var logLevels = new Dictionary<string, string>
|
var logLevels = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "Default", "Information" },
|
{ "Default", "Information" },
|
||||||
{ "Microsoft.AspNetCore", "Warning" }
|
{ "Microsoft.AspNetCore", "Warning" },
|
||||||
|
{ "System.Net.Http.HttpClient", "Warning" }
|
||||||
};
|
};
|
||||||
|
|
||||||
var logLevelsJson = JsonSerializer.Serialize(logLevels);
|
var logLevelsJson = JsonSerializer.Serialize(logLevels);
|
||||||
@@ -113,7 +114,7 @@ public static class Startup
|
|||||||
databaseHelper.AddDbContext(database);
|
databaseHelper.AddDbContext(database);
|
||||||
builder.Services.AddScoped(database);
|
builder.Services.AddScoped(database);
|
||||||
}
|
}
|
||||||
|
|
||||||
databaseHelper.GenerateMappings();
|
databaseHelper.GenerateMappings();
|
||||||
|
|
||||||
builder.Services.AddSingleton(databaseHelper);
|
builder.Services.AddSingleton(databaseHelper);
|
||||||
@@ -163,7 +164,7 @@ public static class Startup
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!config.Authentication.UseLocalOAuth2) return Task.CompletedTask;
|
if (!config.Authentication.UseLocalOAuth2) return Task.CompletedTask;
|
||||||
|
|
||||||
logger.LogInformation("Using local oauth2 provider");
|
logger.LogInformation("Using local oauth2 provider");
|
||||||
|
|
||||||
builder.Services.AddOAuth2Provider(configuration =>
|
builder.Services.AddOAuth2Provider(configuration =>
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Helpers\" />
|
<Folder Include="Helpers\" />
|
||||||
<Folder Include="UI\Components\" />
|
|
||||||
<Folder Include="wwwroot\css\" />
|
<Folder Include="wwwroot\css\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ using Moonlight.Client.Implementations;
|
|||||||
using Moonlight.Client.Interfaces;
|
using Moonlight.Client.Interfaces;
|
||||||
using Moonlight.Client.Services;
|
using Moonlight.Client.Services;
|
||||||
using Moonlight.Client.UI;
|
using Moonlight.Client.UI;
|
||||||
|
using Moonlight.Client.UI.Forms;
|
||||||
using Moonlight.Shared.Http.Requests.Auth;
|
using Moonlight.Shared.Http.Requests.Auth;
|
||||||
using Moonlight.Shared.Http.Responses.Auth;
|
using Moonlight.Shared.Http.Responses.Auth;
|
||||||
|
|
||||||
@@ -104,6 +105,7 @@ builder.Services.AutoAddServices<Program>();
|
|||||||
|
|
||||||
FormComponentRepository.Set<string, StringComponent>();
|
FormComponentRepository.Set<string, StringComponent>();
|
||||||
FormComponentRepository.Set<int, IntComponent>();
|
FormComponentRepository.Set<int, IntComponent>();
|
||||||
|
FormComponentRepository.Set<DateTime, DateComponent>();
|
||||||
|
|
||||||
// Interface service
|
// Interface service
|
||||||
builder.Services.AddPlugins(configuration =>
|
builder.Services.AddPlugins(configuration =>
|
||||||
|
|||||||
@@ -9,7 +9,14 @@
|
|||||||
<NotFound>
|
<NotFound>
|
||||||
<PageTitle>Not found</PageTitle>
|
<PageTitle>Not found</PageTitle>
|
||||||
<LayoutView Layout="@typeof(MainLayout)">
|
<LayoutView Layout="@typeof(MainLayout)">
|
||||||
<p role="alert">Sorry, there's nothing at this address.</p>
|
<div class="flex flex-col justify-center text-center">
|
||||||
|
<img class="h-48 mt-5 mb-3" src="/svg/notfound.svg" alt="Not found illustration"/>
|
||||||
|
|
||||||
|
<h3 class="mt-2 font-semibold text-white text-lg">Page not found</h3>
|
||||||
|
<p class="mt-1 text-gray-300">
|
||||||
|
The page you requested does not exist
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</LayoutView>
|
</LayoutView>
|
||||||
</NotFound>
|
</NotFound>
|
||||||
</Router>
|
</Router>
|
||||||
16
Moonlight.Client/UI/Components/StatCard.razor
Normal file
16
Moonlight.Client/UI/Components/StatCard.razor
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<div class="card card-body">
|
||||||
|
<div class="flex justify-between">
|
||||||
|
<p class="text-xl font-semibold text-slate-200">
|
||||||
|
@Text
|
||||||
|
</p>
|
||||||
|
<i class="@Icon text-4xl text-primary-500"></i>
|
||||||
|
</div>
|
||||||
|
<p class="text-base text-slate-300">@Title</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
[Parameter] public string Title { get; set; }
|
||||||
|
[Parameter] public string Text { get; set; }
|
||||||
|
[Parameter] public string Icon { get; set; }
|
||||||
|
}
|
||||||
3
Moonlight.Client/UI/Forms/DateComponent.razor
Normal file
3
Moonlight.Client/UI/Forms/DateComponent.razor
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
@inherits BaseFormComponent<DateTime>
|
||||||
|
|
||||||
|
<input @bind="Binder.Value" type="date" autocomplete="off" class="form-input w-full">
|
||||||
111
Moonlight.Client/UI/Views/Admin/Api/Index.razor
Normal file
111
Moonlight.Client/UI/Views/Admin/Api/Index.razor
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
@page "/admin/api"
|
||||||
|
|
||||||
|
@using MoonCore.Blazor.Tailwind.Attributes
|
||||||
|
@using MoonCore.Helpers
|
||||||
|
@using MoonCore.Models
|
||||||
|
@using Moonlight.Shared.Http.Requests.Admin.ApiKeys
|
||||||
|
@using Moonlight.Shared.Http.Responses.Admin.ApiKeys
|
||||||
|
|
||||||
|
@attribute [RequirePermission("admin.apikeys.read")]
|
||||||
|
|
||||||
|
@inject HttpApiClient HttpApiClient
|
||||||
|
@inject AlertService AlertService
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 sm:grid-cols-3 mb-8 gap-x-3">
|
||||||
|
<div class="col-span-1 card card-body border-l-4 border-primary-500">
|
||||||
|
<p class="font-medium tracking-wide text-slate-100">
|
||||||
|
API Documentation
|
||||||
|
</p>
|
||||||
|
<a href="/api/swagger" target="_blank" class="mt-2 flex items-center justify-between text-primary-500">
|
||||||
|
<div class="font-medium">Open</div>
|
||||||
|
<div>
|
||||||
|
<i class="bi bi-box-arrow-up-right text-lg text-primary-500"></i>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-span-1 card card-body border-l-4 border-tertiary-500">
|
||||||
|
<p class="font-medium tracking-wide text-slate-100">
|
||||||
|
Learn about the api usage
|
||||||
|
</p>
|
||||||
|
<a href="https://help.moonlightpanel.xyz" target="_blank" class="mt-2 flex items-center justify-between text-primary-500">
|
||||||
|
<div class="font-medium">Open</div>
|
||||||
|
<div>
|
||||||
|
<i class="bi bi-box-arrow-up-right text-lg text-tertiary-500"></i>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-span-1 card card-body border-l-4 border-success-500">
|
||||||
|
<p class="font-medium tracking-wide text-slate-100">
|
||||||
|
Open API Specification
|
||||||
|
</p>
|
||||||
|
<a href="/api/swagger/main" target="_blank" class="mt-2 flex items-center justify-between text-primary-500">
|
||||||
|
<div class="font-medium">Open</div>
|
||||||
|
<div>
|
||||||
|
<i class="bi bi-box-arrow-up-right text-lg text-success-500"></i>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Crud TItem="ApiKeyDetailResponse"
|
||||||
|
TCreateForm="CreateApiKeyRequest"
|
||||||
|
TUpdateForm="UpdateApiKeyRequest"
|
||||||
|
OnConfigure="OnConfigure">
|
||||||
|
<View>
|
||||||
|
<Column TItem="ApiKeyDetailResponse" Field="@(x => x.Id)" Title="Id"/>
|
||||||
|
<Column TItem="ApiKeyDetailResponse" Field="@(x => x.Description)" Title="Description"/>
|
||||||
|
<Column TItem="ApiKeyDetailResponse" Field="@(x => x.ExpiresAt)" Title="Expires at">
|
||||||
|
<Template>
|
||||||
|
@Formatter.FormatDate(context.ExpiresAt)
|
||||||
|
</Template>
|
||||||
|
</Column>
|
||||||
|
</View>
|
||||||
|
</Crud>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
private void OnConfigure(CrudOptions<ApiKeyDetailResponse, CreateApiKeyRequest, UpdateApiKeyRequest> crudOptions)
|
||||||
|
{
|
||||||
|
crudOptions.ItemName = "API Key";
|
||||||
|
|
||||||
|
crudOptions.ItemLoader = async (page, pageSize)
|
||||||
|
=> await HttpApiClient.GetJson<PagedData<ApiKeyDetailResponse>>($"api/admin/apikeys?page={page}&pageSize={pageSize}");
|
||||||
|
|
||||||
|
crudOptions.SingleItemLoader = async id
|
||||||
|
=> await HttpApiClient.GetJson<ApiKeyDetailResponse>($"api/admin/apikeys/{id}");
|
||||||
|
|
||||||
|
crudOptions.QueryIdentifier = response => response.Id.ToString();
|
||||||
|
|
||||||
|
crudOptions.OnCreate = async request =>
|
||||||
|
{
|
||||||
|
var response = await HttpApiClient.PostJson<CreateApiKeyResponse>("api/admin/apikeys", request);
|
||||||
|
|
||||||
|
await AlertService.Success(
|
||||||
|
"API Key successfully created",
|
||||||
|
$"Copy the following secret. It wont be shown again. '{response.Secret}'"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
crudOptions.OnUpdate = async (item, request)
|
||||||
|
=> await HttpApiClient.Patch($"api/admin/apikeys/{item.Id}", request);
|
||||||
|
|
||||||
|
crudOptions.OnDelete = async item
|
||||||
|
=> await HttpApiClient.Delete($"api/admin/apikeys/{item.Id}");
|
||||||
|
|
||||||
|
crudOptions.OnConfigureCreate = configuration =>
|
||||||
|
{
|
||||||
|
configuration.WithField(x => x.Description);
|
||||||
|
configuration.WithField(x => x.PermissionsJson);
|
||||||
|
configuration.WithField(x => x.ExpiresAt, fieldConfiguration => { fieldConfiguration.DefaultValue = DateTime.UtcNow.AddMonths(1); });
|
||||||
|
};
|
||||||
|
|
||||||
|
crudOptions.OnConfigureUpdate = (_, configuration) =>
|
||||||
|
{
|
||||||
|
configuration.WithField(x => x.Description);
|
||||||
|
configuration.WithField(x => x.PermissionsJson);
|
||||||
|
configuration.WithField(x => x.ExpiresAt);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
35
Moonlight.Client/UI/Views/Admin/Sys/Index.razor
Normal file
35
Moonlight.Client/UI/Views/Admin/Sys/Index.razor
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
@page "/admin/system"
|
||||||
|
|
||||||
|
@using MoonCore.Blazor.Tailwind.Attributes
|
||||||
|
@using Moonlight.Client.UI.Components
|
||||||
|
|
||||||
|
@attribute [RequirePermission("admin.system.read")]
|
||||||
|
|
||||||
|
<div class="gap-5 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4">
|
||||||
|
<StatCard Title="CPU Usage" Text="2%" Icon="bi bi-cpu"/>
|
||||||
|
<StatCard Title="Memory Usage" Text="71 MB" Icon="bi bi-memory"/>
|
||||||
|
<StatCard Title="Host OS" Text="Debian 12" Icon="bi bi-motherboard"/>
|
||||||
|
<StatCard Title="Uptime" Text="1d 5h 12h 3s" Icon="bi bi-clock-history"/>
|
||||||
|
|
||||||
|
<div class="card card-body relative">
|
||||||
|
<div>
|
||||||
|
<div class="absolute rounded-lg p-3 bg-danger-600">
|
||||||
|
<div class="h-6 w-6 flex justify-center items-center">
|
||||||
|
<i class="bi bi-arrow-repeat text-4xl text-white"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="ml-16 flex items-center mb-2">
|
||||||
|
<WButton OnClick="Restart" CssClasses="btn btn-danger w-full">Restart</WButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
private async Task Restart(WButton _)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
crudOptions.SingleItemLoader = async id
|
crudOptions.SingleItemLoader = async id
|
||||||
=> await HttpApiClient.GetJson<UserDetailResponse>($"api/admin/users/{id}");
|
=> await HttpApiClient.GetJson<UserDetailResponse>($"api/admin/users/{id}");
|
||||||
|
|
||||||
crudOptions.QueryIdentifier = item => item.Id.ToString(); //TODO: Make this default
|
crudOptions.QueryIdentifier = response => response.Id.ToString();
|
||||||
|
|
||||||
crudOptions.OnCreate = async request
|
crudOptions.OnCreate = async request
|
||||||
=> await HttpApiClient.Post("api/admin/users", request);
|
=> await HttpApiClient.Post("api/admin/users", request);
|
||||||
|
|||||||
1
Moonlight.Client/wwwroot/svg/notfound.svg
Normal file
1
Moonlight.Client/wwwroot/svg/notfound.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 11 KiB |
@@ -0,0 +1,15 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Moonlight.Shared.Http.Requests.Admin.ApiKeys;
|
||||||
|
|
||||||
|
public class CreateApiKeyRequest
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "You need to specify a description")]
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "You need to specify permissions for the api key")]
|
||||||
|
public string PermissionsJson { get; set; } = "[]";
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "You need to specify an expire date")]
|
||||||
|
public DateTime ExpiresAt { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Moonlight.Shared.Http.Requests.Admin.ApiKeys;
|
||||||
|
|
||||||
|
public class UpdateApiKeyRequest
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "You need to specify a description")]
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "You need to specify permissions for the api key")]
|
||||||
|
public string PermissionsJson { get; set; } = "[]";
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "You need to specify an expire date")]
|
||||||
|
public DateTime ExpiresAt { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Moonlight.Shared.Http.Responses.Admin.ApiKeys;
|
||||||
|
|
||||||
|
public class ApiKeyDetailResponse
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public string PermissionsJson { get; set; } = "[]";
|
||||||
|
public DateTime ExpiresAt { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Moonlight.Shared.Http.Responses.Admin.ApiKeys;
|
||||||
|
|
||||||
|
public class CreateApiKeyResponse
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Secret { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public string PermissionsJson { get; set; } = "[]";
|
||||||
|
public DateTime ExpiresAt { get; set; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user