Skip to content

Commit

Permalink
(#2) add configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintAngeLs committed Sep 26, 2024
1 parent 11cb8e7 commit 5435591
Show file tree
Hide file tree
Showing 51 changed files with 4,209 additions and 14 deletions.
6 changes: 0 additions & 6 deletions src/Nuar/Nuar/Class1.cs

This file was deleted.

14 changes: 14 additions & 0 deletions src/Nuar/Nuar/Configuration/Auth.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Nuar.Configuration
{
public class Auth
{
public bool Enabled { get; set; }
public bool Global { get; set; }
public IDictionary<string, Policy> Policies { get; set; }
}
}
14 changes: 14 additions & 0 deletions src/Nuar/Nuar/Configuration/Http.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Nuar.Configuration
{
public class Http
{
public int Retries { get; set; }
public bool Exponential { get; set; }
public double Interval { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/Nuar/Nuar/Configuration/LoadBalancer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Nuar.Configuration
{
public class LoadBalancer
{
public bool Enabled { get; set; }
public string Url { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/Nuar/Nuar/Configuration/Module.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Nuar.Configuration
{
public class Module
{
public string Name { get; set; }
public string Description { get; set; }
public string Version { get; set; }
public bool? Enabled { get; set; }
public IEnumerable<Route> Routes { get; set; }
public IDictionary<string, Service> Services { get; set; }

}
}
8 changes: 8 additions & 0 deletions src/Nuar/Nuar/Configuration/OnError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Nuar.Configuration
{
public class OnError
{
public int Code { get; set; } = 200;
public object Data { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/Nuar/Nuar/Configuration/OnSuccess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Nuar.Configuration
{
public class OnSuccess
{
public int Code { get; set; } = 200;
public object Data { get; set; }
}
}
7 changes: 7 additions & 0 deletions src/Nuar/Nuar/Configuration/Policy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Nuar.Configuration
{
public class Policy
{
public IDictionary<string, string> Claims { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/Nuar/Nuar/Configuration/ResourceId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Nuar.Configuration
{
public class ResourceId
{
public bool Generate { get; set; }
public string Property { get; set; }
}
}
33 changes: 33 additions & 0 deletions src/Nuar/Nuar/Configuration/Route.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Nuar.Configuration
{
public class Route
{
public ResourceId ResourceId { get; set; }
public string Upstream { get; set; }
public string Method { get; set; }
public IEnumerable<string> Methods { get; set; }
public bool MatchAll { get; set; }
public string Use { get; set; }
public string Downstream { get; set; }
public string DownstreamMethod { get; set; }
public bool? PassQueryString { get; set; }
public string ReturnValue { get; set; }
public string Payload { get; set; }
public string Schema { get; set; }
public bool? Auth { get; set; }
public IDictionary<string, string> RequestHeaders { get; set; }
public IDictionary<string, string> ResponseHeaders { get; set; }
public bool? ForwardRequestHeaders { get; set; }
public bool? ForwardResponseHeaders { get; set; }
public bool? ForwardStatusCode { get; set; }
public bool? GenerateRequestId { get; set; }
public bool? GenerateTraceId { get; set; }
public OnError OnError { get; set; }
public OnSuccess OnSuccess { get; set; }
public IDictionary<string, string> Claims { get; set; }
public IEnumerable<string> Policies { get; set; }
public IEnumerable<string> Bind { get; set; }
public IEnumerable<string> Transform { get; set; }
public IDictionary<string, string> Config { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/Nuar/Nuar/Configuration/Service.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Nuar.Configuration
{
public class Service
{
public string LocalUrl { get; set; }
public string Url { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/Nuar/Nuar/Error.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Nuar
{
public class Error
{
public string Code { get; set; }
public string Property { get; set; }
public string Message { get; set; }
}
}
27 changes: 27 additions & 0 deletions src/Nuar/Nuar/ExecutionData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Route = Nuar.Configuration.Route;

namespace Nuar
{
public class ExecutionData
{
public string RequestId { get; set; }
public string ResourceId { get; set; }
public string TraceId { get; set; }
public string UserId { get; set; }
public string ContentType { get; set; }
public string Downstream { get; set; }
public bool HasPayload { get; set; }
public IDictionary<string, string> Claims { get; set; }
public Route Route { get; set; }
public HttpContext Context { get; set; }
public RouteData Data { get; set; }
public ExpandoObject Payload { get; set; }
public IEnumerable<Error> ValidationErrors { get; set; } = Enumerable.Empty<Error>();
public bool IsPayloadValid => ValidationErrors is null || !ValidationErrors.Any();
}
}
9 changes: 9 additions & 0 deletions src/Nuar/Nuar/IAuthenticationManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Http;

namespace Nuar
{
public interface IAuthenticationManager
{
Task<bool> TryAuthenticateAsync(HttpRequest request, RouteConfig routeConfig);
}
}
9 changes: 9 additions & 0 deletions src/Nuar/Nuar/IAuthorizationManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Security.Claims;

namespace Nuar
{
public interface IAuthorizationManager
{
bool IsAuthorized(ClaimsPrincipal user, RouteConfig routeConfig);
}
}
10 changes: 10 additions & 0 deletions src/Nuar/Nuar/IDownstreamBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;

namespace Nuar
{
internal interface IDownstreamBuilder
{
string GetDownstream(RouteConfig routeConfig, HttpRequest request, RouteData data);
}
}
8 changes: 8 additions & 0 deletions src/Nuar/Nuar/IEnabledExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Nuar
{
public interface IEnabledExtension
{
IExtension Extension { get; }
IExtensionOptions Options { get; }
}
}
18 changes: 18 additions & 0 deletions src/Nuar/Nuar/IExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace Nuar
{
public interface IExtension
{
string Name { get; }
string Description { get; }
string Version { get; }
void Add(IServiceCollection services, IOptionsProvider optionsProvider);
void Use(IApplicationBuilder app, IOptionsProvider optionsProvider);
}
}
13 changes: 13 additions & 0 deletions src/Nuar/Nuar/IExtensionOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Nuar
{
public interface IExtensionOptions
{
int? Order { get; set; }
bool? Enabled { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/Nuar/Nuar/IExtensionProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace Nuar
{
internal interface IExtensionProvider
{
IEnumerable<IEnabledExtension> GetAll();
}
}
12 changes: 12 additions & 0 deletions src/Nuar/Nuar/IHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using NuarRoute = Nuar.Configuration.Route;

namespace Nuar
{
public interface IHandler
{
string GetInfo(NuarRoute route);
Task HandleAsync(HttpContext context, RouteConfig config);
}
}
7 changes: 7 additions & 0 deletions src/Nuar/Nuar/IOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Nuar
{
public interface IOptions
{

}
}
8 changes: 8 additions & 0 deletions src/Nuar/Nuar/IOptionsProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Nuar
{
public interface IOptionsProvider
{
T Get<T>(string name = null) where T : class, IOptions, new();
T GetForExtension<T>(string name) where T : class, IOptions, new();
}
}
10 changes: 10 additions & 0 deletions src/Nuar/Nuar/IPayloadBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Http;

namespace Nuar
{
public interface IPayloadBuilder
{
Task<string> BuildRawAsync(HttpRequest request);
Task<T> BuildJsonAsync<T>(HttpRequest request) where T : class, new();
}
}
13 changes: 13 additions & 0 deletions src/Nuar/Nuar/IPayloadManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Nuar
{
internal interface IPayloadManager
{
string GetKey(string method, string upstream);
IDictionary<string, PayloadSchema> Payloads { get; }
}
}
12 changes: 12 additions & 0 deletions src/Nuar/Nuar/IPayloadTransformer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using NuarRoute = Nuar.Configuration.Route;

namespace Nuar
{
internal interface IPayloadTransformer
{
bool HasTransformations(string resourceId, NuarRoute route);
PayloadSchema Transform(string payload, string resourceId, NuarRoute route, HttpRequest request, RouteData data);
}
}
12 changes: 12 additions & 0 deletions src/Nuar/Nuar/IPayloadValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


using Microsoft.AspNetCore.Http;

namespace Nuar
{
public interface IPayloadValidator
{
Task<bool> TryValidate(ExecutionData executionData, HttpResponse httpResponce);
Task<IEnumerable<Error>> GetValidationErrorsAsync(PayloadSchema payloadSchema);
}
}
12 changes: 12 additions & 0 deletions src/Nuar/Nuar/IPolicyManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Nuar
{
internal interface IPolicyManager
{
IDictionary<string, string> GetClaims(string policy);
}
}
9 changes: 9 additions & 0 deletions src/Nuar/Nuar/IRequestExecutionValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Http;

namespace Nuar
{
internal interface IRequestExecutionValidator
{
Task<bool> TryExecuteAsync(HttpContext httpContext, RouteConfig routeConfig);
}
}
Loading

0 comments on commit 5435591

Please sign in to comment.