Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide new feature flag context for devices #5226

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Core/Services/Implementations/LaunchDarklyFeatureService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class LaunchDarklyFeatureService : IFeatureService
private readonly ICurrentContext _currentContext;
private const string _anonymousUser = "25a15cac-58cf-4ac0-ad0f-b17c4bd92294";

private const string _contextKindDevice = "device";
private const string _contextKindOrganization = "organization";
private const string _contextKindServiceAccount = "service-account";
Comment on lines +19 to 21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At what point would we want to make this an enum/class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I think I am done adding them and we can't invent any more, then another comes up. This is (probably) the last one! ๐Ÿ˜œ


Expand Down Expand Up @@ -158,6 +159,16 @@ void SetCommonContextAttributes(ContextBuilder builder)

var builder = LaunchDarkly.Sdk.Context.MultiBuilder();

if (!string.IsNullOrWhiteSpace(_currentContext.DeviceIdentifier))
{
var ldDevice = LaunchDarkly.Sdk.Context.Builder(_currentContext.DeviceIdentifier);

ldDevice.Kind(_contextKindDevice);
SetCommonContextAttributes(ldDevice);

builder.Add(ldDevice.Build());
}

switch (_currentContext.IdentityClientType)
{
case IdentityClientType.User:
Expand Down
1 change: 1 addition & 0 deletions test/Core.Test/Services/LaunchDarklyFeatureServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private static SutProvider<LaunchDarklyFeatureService> GetSutProvider(IGlobalSet
globalSettings.ProjectName = "LaunchDarkly Tests";

var currentContext = Substitute.For<ICurrentContext>();
currentContext.DeviceIdentifier.Returns(Guid.NewGuid().ToString());
currentContext.UserId.Returns(Guid.NewGuid());
currentContext.ClientVersion.Returns(new Version(AssemblyHelpers.GetVersion()));
currentContext.ClientVersionIsPrerelease.Returns(true);
Expand Down
Loading