Skip to content

Commit

Permalink
Licensing WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith committed Feb 10, 2024
1 parent b4e9fa7 commit ba7a5dc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/Imageflow.Server/ImageflowMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,14 @@ public ImageflowMiddleware(
globalInfoProvider = new GlobalInfoProvider(container);
container.Register(globalInfoProvider);

var licensingOptions = new LicenseOptions()
{ CandidateCacheFolders = new[] { env.ContentRootPath, Path.GetTempPath() } };


container.Register(licensingOptions);
container.Register(env);
container.Register(logger);



new MiddlewareOptionsServerBuilder(container, logger, retainedLogStore, options, env).PopulateServices();
new MiddlewareOptionsServerBuilder(container, logger, retainedLogStore, options,env).PopulateServices();


var startDiag = new StartupDiagnostics(container);
Expand Down
18 changes: 17 additions & 1 deletion src/Imageflow.Server/Internal/MiddlewareOptionsServerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ public void PopulateServices()
serverContainer.Register<IPerformanceTracker>(perfTracker);


var licensingOptions = new LicenseOptions
{
LicenseKey = options.LicenseKey,
MyOpenSourceProjectUrl = options.MyOpenSourceProjectUrl,
KeyPrefix = "imageflow_",
CandidateCacheFolders = new[]
{
env.ContentRootPath,
Path.GetTempPath()
},
EnforcementMethod = Imazen.Routing.Layers.EnforceLicenseWith.RedDotWatermark,

};
serverContainer.Register(licensingOptions);

var diagPageOptions = new DiagnosticsPageOptions(
options.DiagnosticsPassword,
(Imazen.Routing.Layers.DiagnosticsPageOptions.AccessDiagnosticsFrom)options.DiagnosticsAccess);
Expand Down Expand Up @@ -106,11 +121,12 @@ public void PopulateServices()
var routingEngine = router.Build(logger);

serverContainer.Register(routingEngine);


//TODO: Add a way to get the current ILicenseChecker
var imageServer = new ImageServer<RequestStreamAdapter,ResponseStreamAdapter, HttpContext>(
serverContainer,
null,
licensingOptions,
routingEngine, perfTracker, logger);

serverContainer.Register<IImageServer<RequestStreamAdapter,ResponseStreamAdapter, HttpContext>>(imageServer);
Expand Down
2 changes: 1 addition & 1 deletion src/Imazen.Routing/Layers/IRoutingEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Imazen.Routing.Layers;
public interface IRoutingEndpoint
{
bool IsBlobEndpoint { get; }
//ValueTask<CodeResult<ICacheableBlobPromise>> GetInstantPromise(IRequestSnapshot request, CancellationToken cancellationToken = default);

ValueTask<IInstantPromise> GetInstantPromise(IRequestSnapshot request, CancellationToken cancellationToken = default);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Imazen.Routing/Layers/Licensing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace Imageflow.Server
{
public class LicenseOptions{
internal string LicenseKey { get; set; } = "";
internal string? LicenseKey { get; set; } = "";
internal string MyOpenSourceProjectUrl { get; set; } = "";

internal string KeyPrifx { get; set; } = "imageflow_";
internal string KeyPrefix { get; set; } = "imageflow_";
public required string[] CandidateCacheFolders { get; set; }
internal EnforceLicenseWith EnforcementMethod { get; set; } = EnforceLicenseWith.RedDotWatermark;

Expand Down
2 changes: 1 addition & 1 deletion src/Imazen.Routing/Serving/ImageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ImageServer(IImageServerContainer container,

licenseChecker = container.GetService<ILicenseChecker>() ??
new Licensing(LicenseManagerSingleton.GetOrCreateSingleton(
licenseOptions.KeyPrifx, licenseOptions.CandidateCacheFolders), null);
licenseOptions.KeyPrefix, licenseOptions.CandidateCacheFolders), null);
licenseChecker.Initialize(licenseOptions);

licenseChecker.FireHeartbeat();
Expand Down

0 comments on commit ba7a5dc

Please sign in to comment.