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

Support client version prerelease flag in context and LD targeting #4994

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions src/Core/Context/CurrentContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
public virtual int? BotScore { get; set; }
public virtual string ClientId { get; set; }
public virtual Version ClientVersion { get; set; }
public virtual bool ClientVersionIsPrerelease { get; set; }

Check warning on line 42 in src/Core/Context/CurrentContext.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Context/CurrentContext.cs#L42

Added line #L42 was not covered by tests
public virtual IdentityClientType IdentityClientType { get; set; }
public virtual Guid? ServiceAccountOrganizationId { get; set; }

Expand Down Expand Up @@ -97,6 +98,11 @@
{
ClientVersion = cVersion;
}

if (httpContext.Request.Headers.TryGetValue("Is-Prerelease", out var clientVersionIsPrerelease))
{
ClientVersionIsPrerelease = clientVersionIsPrerelease == "true";
withinfocus marked this conversation as resolved.
Show resolved Hide resolved
}

Check warning on line 105 in src/Core/Context/CurrentContext.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Context/CurrentContext.cs#L103-L105

Added lines #L103 - L105 were not covered by tests
}

public async virtual Task BuildAsync(ClaimsPrincipal user, GlobalSettings globalSettings)
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Context/ICurrentContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ public interface ICurrentContext
int? BotScore { get; set; }
string ClientId { get; set; }
Version ClientVersion { get; set; }
bool ClientVersionIsPrerelease { get; set; }

Task BuildAsync(HttpContext httpContext, GlobalSettings globalSettings);
Task BuildAsync(ClaimsPrincipal user, GlobalSettings globalSettings);

Task SetContextAsync(ClaimsPrincipal user);


Task<bool> OrganizationUser(Guid orgId);
Task<bool> OrganizationAdmin(Guid orgId);
Task<bool> OrganizationOwner(Guid orgId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class LaunchDarklyFeatureService : IFeatureService
private const string _contextKindServiceAccount = "service-account";

private const string _contextAttributeClientVersion = "client-version";
private const string _contextAttributeClientVersionIsPrerelease = "client-version-is-prerelease";
private const string _contextAttributeDeviceType = "device-type";
private const string _contextAttributeClientType = "client-type";
private const string _contextAttributeOrganizations = "organizations";
Expand Down Expand Up @@ -145,6 +146,7 @@ void SetCommonContextAttributes(ContextBuilder builder)
if (_currentContext.ClientVersion != null)
{
builder.Set(_contextAttributeClientVersion, _currentContext.ClientVersion.ToString());
builder.Set(_contextAttributeClientVersionIsPrerelease, _currentContext.ClientVersionIsPrerelease);
}

if (_currentContext.DeviceType.HasValue)
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 @@ -24,6 +24,7 @@ private static SutProvider<LaunchDarklyFeatureService> GetSutProvider(IGlobalSet
var currentContext = Substitute.For<ICurrentContext>();
currentContext.UserId.Returns(Guid.NewGuid());
currentContext.ClientVersion.Returns(new Version(AssemblyHelpers.GetVersion()));
currentContext.ClientVersionIsPrerelease.Returns(true);
currentContext.DeviceType.Returns(Enums.DeviceType.ChromeBrowser);

var client = Substitute.For<ILdClient>();
Expand Down
Loading