-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: swap out leaky yggdrasil custom strategy for an internal abstr…
…action (#256)
- Loading branch information
Showing
6 changed files
with
79 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
using System.Threading.Tasks; | ||
using Yggdrasil; | ||
using Unleash.Strategies; | ||
|
||
namespace Unleash.ClientFactory | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using Yggdrasil; | ||
|
||
|
||
namespace Unleash.Strategies | ||
{ | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// Defines a strategy for enabling a feature. | ||
/// </summary> | ||
public interface IStrategy | ||
{ | ||
/// <summary> | ||
/// Gets the strategy name | ||
/// </summary> | ||
string Name { get; } | ||
|
||
/// <summary> | ||
/// Calculates if the strategy is enabled for a given context | ||
/// </summary> | ||
bool IsEnabled(Dictionary<string, string> parameters, UnleashContext context); | ||
} | ||
|
||
internal class CustomStrategyAdapter : Yggdrasil.IStrategy | ||
{ | ||
private IStrategy strategy { get; } | ||
|
||
public CustomStrategyAdapter(IStrategy strategy) | ||
{ | ||
this.strategy = strategy; | ||
} | ||
|
||
public string Name => strategy.Name; | ||
|
||
public bool IsEnabled(Dictionary<string, string> parameters, Context context) | ||
{ | ||
var currentTime = context.CurrentTime ?? DateTimeOffset.UtcNow; | ||
|
||
var unleashContext = new UnleashContext.Builder() | ||
.AppName(context.AppName) | ||
.CurrentTime(currentTime) | ||
.Environment(context.Environment) | ||
.UserId(context.UserId) | ||
.SessionId(context.SessionId) | ||
.RemoteAddress(context.RemoteAddress) | ||
.Build(); | ||
unleashContext.Properties = context.Properties; | ||
|
||
return strategy.IsEnabled(parameters, unleashContext); | ||
} | ||
} | ||
} |