mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Starting a config apio
This commit is contained in:
parent
8fcbcd125f
commit
9ae846f88a
@ -7,12 +7,17 @@ namespace Kyoo.Models.Permissions
|
||||
/// <summary>
|
||||
/// The kind of permission needed.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The admin kind is used for configuration or security sensitive permissions to allow one
|
||||
/// to use an overall permission without compromising security.
|
||||
/// </remarks>
|
||||
public enum Kind
|
||||
{
|
||||
Read,
|
||||
Write,
|
||||
Create,
|
||||
Delete
|
||||
Delete,
|
||||
Admin
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Kyoo.Controllers;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Kyoo
|
||||
@ -62,5 +63,12 @@ namespace Kyoo
|
||||
services.Add(ServiceDescriptor.Describe(typeof(T), typeof(T2), lifetime));
|
||||
return services.AddRepository<T2>(lifetime);
|
||||
}
|
||||
|
||||
public static IServiceCollection AddConfiguration<T>(this IServiceCollection services, IConfiguration config, string path)
|
||||
{
|
||||
services.Configure<T>(config.GetSection(path));
|
||||
services.AddSingleton<ConfigReference>(new ConfigReference(path, typeof(T)));
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
@ -18,6 +19,7 @@ namespace Kyoo
|
||||
/// Main function of the program
|
||||
/// </summary>
|
||||
/// <param name="args">Command line arguments</param>
|
||||
[SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalse")]
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
if (!File.Exists("./settings.json"))
|
||||
|
41
Kyoo/Views/ConfigurationApi.cs
Normal file
41
Kyoo/Views/ConfigurationApi.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Kyoo.Models.Permissions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Kyoo.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// An API to retrieve or edit configuration settings
|
||||
/// </summary>
|
||||
[Route("api/config")]
|
||||
[Route("api/configuration")]
|
||||
[ApiController]
|
||||
public class ConfigurationApi : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// The configuration to retrieve and edit.
|
||||
/// </summary>
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="ConfigurationApi"/> using the given configuration.
|
||||
/// </summary>
|
||||
/// <param name="config">The configuration to use.</param>
|
||||
public ConfigurationApi(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a permission from it's slug.
|
||||
/// </summary>
|
||||
/// <param name="slug">The permission to retrieve. You can use __ to get a child value.</param>
|
||||
/// <returns>The associate value or list of values.</returns>
|
||||
[HttpGet("{slug}")]
|
||||
[Permission(nameof(ConfigurationApi), Kind.Admin)]
|
||||
public ActionResult<object> GetConfiguration(string slug)
|
||||
{
|
||||
return _config[slug];
|
||||
}
|
||||
}
|
||||
}
|
@ -32,8 +32,8 @@
|
||||
"password": "passphrase"
|
||||
},
|
||||
"permissions": {
|
||||
"default": ["overall.read", "overall.write", "overall.create", "overall.delete"],
|
||||
"newUser": ["overall.read", "overall.write", "overall.create", "overall.delete"]
|
||||
"default": ["overall.read", "overall.write", "overall.create", "overall.delete", "overall.admin"],
|
||||
"newUser": ["overall.read", "overall.write", "overall.create", "overall.delete", "overall.admin"]
|
||||
},
|
||||
"profilePicturePath": "users/",
|
||||
"clients": []
|
||||
|
Loading…
x
Reference in New Issue
Block a user